Skip to content

Commit 6659f18

Browse files
Fixed #37, #38, & #40: Restoring maximize now shrinks to 2/3 H & W
1 parent 928da9b commit 6659f18

1 file changed

Lines changed: 87 additions & 48 deletions

File tree

main.py

Lines changed: 87 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -526,30 +526,37 @@ def OnAbout(event):
526526
# function to open the data files
527527
def OnOpen(event):
528528
frame.EnableCloseButton(False)
529-
# # create the open file dialog, if a file exists the user is able to open it will probably change it so
530-
# # only the MountainsMap data file format can be opened
531-
openFileDialog = wx.FileDialog(frame, "Open", # wildcard="CSV UTF-8 (Comma delimited) (*.csv)|*.csv" ,# \ "
532-
# "TXT (*.txt)|*.txt",
533-
style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST | wx.FD_MULTIPLE)
534-
openFileDialog.CenterOnScreen()
535-
# shows the dialog on screen
536-
result = openFileDialog.ShowModal()
537-
# only opens the file if 'open' in dialog is pressed otherwise if 'cancel' in dialog is pressed closes dialog
538-
if result == wx.ID_OK:
539-
# gets the file path
540-
filepath = openFileDialog.GetPaths()
541-
data = tree_menu.GetItemData(getPlotDataID())
542-
543-
# opens the file and reads it
544-
if filepath[0][len(filepath[0]) - 3:len(filepath[0])] == 'csv':
545-
data.open_file(filepath)
546-
if filepath[0][len(filepath[0]) - 3:len(filepath[0])] == 'txt':
547-
data.open_file2(filepath)
548-
frame.EnableCloseButton(True)
549-
return True
550-
elif result == wx.ID_CANCEL:
529+
output = False
530+
try:
531+
# # create the open file dialog, if a file exists the user is able to open it will probably change it so
532+
# # only the MountainsMap data file format can be opened
533+
openFileDialog = wx.FileDialog(frame, "Open", # wildcard="CSV UTF-8 (Comma delimited) (*.csv)|*.csv" ,# \ "
534+
# "TXT (*.txt)|*.txt",
535+
style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST | wx.FD_MULTIPLE)
536+
openFileDialog.CenterOnScreen()
537+
# shows the dialog on screen
538+
result = openFileDialog.ShowModal()
539+
# only opens the file if 'open' in dialog is pressed otherwise if 'cancel' in dialog is pressed closes dialog
540+
if result == wx.ID_OK:
541+
# gets the file path
542+
filepath = openFileDialog.GetPaths()
543+
data = tree_menu.GetItemData(getPlotDataID())
544+
545+
# opens the file and reads it
546+
if filepath[0][len(filepath[0]) - 3:len(filepath[0])] == 'csv':
547+
data.open_file(filepath)
548+
if filepath[0][len(filepath[0]) - 3:len(filepath[0])] == 'txt':
549+
data.open_file2(filepath)
550+
frame.EnableCloseButton(True)
551+
output = True
552+
elif result == wx.ID_CANCEL:
553+
frame.EnableCloseButton(True)
554+
output = False
555+
except (Exception) as e:
556+
raise e
557+
finally:
551558
frame.EnableCloseButton(True)
552-
return False
559+
return output
553560

554561
def OnNewWB(event):
555562

@@ -582,32 +589,60 @@ def getPlotDataID() :
582589
return selectedID
583590

584591
def OnSave(event):
585-
selectedID = getPlotDataID()
586-
selectedWorkbook = tree_menu.GetItemData(selectedID).get_wb()
587-
588-
saveFileDialog = wx.FileDialog(frame, "Save", selectedWorkbook.name, "xlsx (*.xlsx)|*.xlsx", wx.FD_SAVE)
589-
saveFileDialog.CenterOnScreen()
590-
# shows the dialog on screen when pushes button
591-
result = saveFileDialog.ShowModal()
592-
# only saves the file if 'save' in dialog is pressed otherwise if 'cancel' in dialog is pressed closes dialog
593-
if result == wx.ID_OK:
594-
# gets the file path
595-
filepath = saveFileDialog.GetPath()
596-
597-
cells = selectedWorkbook.get_data().keys()
598-
values = selectedWorkbook.get_data().values()
599-
600-
file = openpyxl.Workbook()
601-
sheet = file.worksheets[0]
602-
603-
for item in zip(cells, values):
592+
frame.EnableCloseButton(False)
593+
output = False
594+
try:
595+
selectedID = getPlotDataID()
596+
selectedWorkbook = tree_menu.GetItemData(selectedID).get_wb()
597+
598+
saveFileDialog = wx.FileDialog(frame, "Save", selectedWorkbook.name, "xlsx (*.xlsx)|*.xlsx", style=wx.FD_SAVE)
599+
saveFileDialog.CenterOnScreen()
600+
# shows the dialog on screen when pushes button
601+
result = saveFileDialog.ShowModal()
602+
# only saves the file if 'save' in dialog is pressed otherwise if 'cancel' in dialog is pressed closes dialog
603+
if result == wx.ID_OK:
604+
# gets the file path
605+
filepath = saveFileDialog.GetPath()
606+
607+
cells = selectedWorkbook.get_data().keys()
608+
values = selectedWorkbook.get_data().values()
609+
610+
file = openpyxl.Workbook()
611+
sheet = file.worksheets[0]
612+
613+
for item in zip(cells, values):
614+
615+
sheet.cell(row=item[0][0] + 1, column=item[0][1] + 1).value = str(item[1])
616+
617+
file.save(filepath)
618+
output = True
619+
elif result == wx.ID_CANCEL:
620+
output = False
621+
except e:
622+
raise e
623+
finally:
624+
frame.EnableCloseButton(True)
625+
return output
604626

605-
sheet.cell(row=item[0][0] + 1, column=item[0][1] + 1).value = str(item[1])
627+
# function to handle window maximization
628+
def onMaxmizeRestore(event):
629+
global resized
630+
global frame
631+
global width, height
606632

607-
file.save(filepath)
608-
return True
609-
elif result == wx.ID_CANCEL:
610-
return False
633+
# Shrinks the window at initial resizing
634+
if frame.IsMaximized() :
635+
pass
636+
else:
637+
if not resized:
638+
screen = wx.DisplaySize()
639+
width = screen[0]
640+
height = screen[1]
641+
frame.SetSize(0.0, 0.0, width/1.5, height/1.5, sizeFlags=wx.SIZE_AUTO)
642+
frame.CenterOnScreen()
643+
resized = True
644+
else:
645+
pass
611646

612647
# function to exit the software
613648
def OnExit(event):
@@ -628,16 +663,20 @@ def OnExit(event):
628663
return False
629664

630665
app = wx.App(redirect=False)
666+
resized = False
631667

632668
# sets the size of the window to be the size of the users computer screen can be set to integers instead
633669
screen = wx.DisplaySize()
634670
width = screen[0]
635671
height = screen[1]
636672

637673
frame = wx.Frame(None, title='Multiscale Analysis')
638-
frame.SetSize(0.0, 0.0, width, height)
674+
frame.SetSize(0.0, 0.0, width, height, sizeFlags=wx.SIZE_AUTO)
639675
frame.SetBackgroundColour('#ffffff')
640676
frame.EnableCloseButton(enable=True)
677+
frame.Bind(wx.EVT_CLOSE, OnExit)
678+
frame.Bind(wx.EVT_SIZE, onMaxmizeRestore)
679+
641680
# this is a bunch of GUI stuff
642681
# general curve fit object which has all of the regression curve functions
643682
cvf = CurveFit()

0 commit comments

Comments
 (0)