From 83ca712cfef3e4954e22f4402ee9ac6d8c388b9b Mon Sep 17 00:00:00 2001 From: paulojamorim Date: Thu, 4 Feb 2010 10:45:51 +0000 Subject: [PATCH] ENH: Display save dialog in the close project not saved --- invesalius/control.py | 61 ++++++++++++++++++++++++++++++++++++++----------------------- invesalius/gui/dialogs.py | 15 ++++++--------- invesalius/gui/frame.py | 34 +++++++++++++++++++--------------- invesalius/gui/widgets/platebtn.py | 26 +++++++++++++------------- 4 files changed, 76 insertions(+), 60 deletions(-) diff --git a/invesalius/control.py b/invesalius/control.py index 464acbf..f0184fc 100755 --- a/invesalius/control.py +++ b/invesalius/control.py @@ -154,27 +154,42 @@ class Controller(): st = session.project_status if st == const.PROJ_CLOSE: return -1 - filename = session.project_path[1] - if (st == const.PROJ_NEW) or (st == const.PROJ_CHANGE): - answer = dialog.SaveChangesDialog(filename) - if not answer: - debug("Close without changes") - self.CloseProject() - ps.Publisher().sendMessage("Enable state project", False) - ps.Publisher().sendMessage('Set project name') - elif answer == 1: - self.ShowDialogSaveProject() - debug("Save changes and close") + try: + filename = session.project_path[1] + except(AttributeError): + print "Not exist project" + filename = None + + if (filename): + if (st == const.PROJ_NEW) or (st == const.PROJ_CHANGE): + answer = dialog.SaveChangesDialog(filename, self.frame) + + if not answer: + debug("Close without changes") + self.CloseProject() + ps.Publisher().sendMessage("Enable state project", False) + ps.Publisher().sendMessage('Set project name') + ps.Publisher().sendMessage('Close Window') + elif answer == 1: + self.ShowDialogSaveProject() + debug("Save changes and close") + self.CloseProject() + ps.Publisher().sendMessage("Enable state project", False) + ps.Publisher().sendMessage('Set project name') + ps.Publisher().sendMessage('Close Window') + elif answer == -1: + debug("Cancel") + else: self.CloseProject() ps.Publisher().sendMessage("Enable state project", False) ps.Publisher().sendMessage('Set project name') - elif answer == -1: - debug("Cancel") + ps.Publisher().sendMessage('Close Window') + else: - self.CloseProject() - ps.Publisher().sendMessage("Enable state project", False) - ps.Publisher().sendMessage('Set project name') - + ps.Publisher().sendMessage('Stop Config Recording') + ps.Publisher().sendMessage('Close Window') + + ########################### def OnOpenProject(self, pubsub_evt): path = pubsub_evt.data @@ -212,7 +227,7 @@ class Controller(): surface = srf.Surface() surface._set_class_index(proj.last_surface_index) - + self.LoadProject() session = ses.Session() @@ -233,7 +248,7 @@ class Controller(): session.SaveProject() ps.Publisher().sendMessage('End busy cursor') - + def CloseProject(self): proj = prj.Project() proj.Close() @@ -320,7 +335,7 @@ class Controller(): const.THRESHOLD_OUTVALUE = proj.threshold_range[0] const.THRESHOLD_INVALUE = proj.threshold_range[1] - + const.WINDOW_LEVEL[_('Default')] = (proj.window, proj.level) const.WINDOW_LEVEL[_('Manual')] = (proj.window, proj.level) @@ -404,9 +419,9 @@ class Controller(): if not filelist: debug("Not used the IPPSorter") filelist = [i.image.file for i in dicom_group.GetHandSortedList()[::interval]] - - - + + + zspacing = dicom_group.zspacing * interval size = dicom.image.size bits = dicom.image.bits_allocad diff --git a/invesalius/gui/dialogs.py b/invesalius/gui/dialogs.py index 4bc90c4..4f07bcf 100644 --- a/invesalius/gui/dialogs.py +++ b/invesalius/gui/dialogs.py @@ -30,7 +30,6 @@ import project as proj import session as ses import utils - class NumberDialog(wx.Dialog): def __init__(self, message, value=0): pre = wx.PreDialog() @@ -341,7 +340,7 @@ def NewMask(): import data.mask as mask dlg = wx.TextEntryDialog(None, _('Name of new mask:'), _('InVesalius 3 - New mask')) - + dlg.CenterOnScreen() default_mask_name = const.MASK_NAME_PATTERN %(mask.Mask.general_index+2) dlg.SetValue(default_mask_name) @@ -367,20 +366,19 @@ def InexistentPath(path): dlg.ShowModal() dlg.Destroy() -def SaveChangesDialog(filename): +def SaveChangesDialog(filename, parent): current_dir = os.path.abspath(".") msg = _("The project %s has been modified.\nSave changes?")%filename if sys.platform == 'darwin': dlg = wx.MessageDialog(None, "", msg, wx.ICON_QUESTION | wx.YES_NO | wx.CANCEL) else: - dlg = wx.MessageDialog(None, msg, - "InVesalius 3", - wx.ICON_QUESTION | wx.YES_NO | wx.CANCEL) + dlg = wx.MessageDialog(None, "TESTETSTE", "InVesalius 3", + wx.ICON_QUESTION | wx.YES_NO | wx.CANCEL) try: answer = dlg.ShowModal() - except(wx._core.PyAssertionError): - answer = dlg.GetReturnCode() + except(wx._core.PyAssertionError): #TODO: FIX win64 + answer = wx.ID_YES dlg.Destroy() os.chdir(current_dir) @@ -621,4 +619,3 @@ def ExportPicture(type_=""): return () - diff --git a/invesalius/gui/frame.py b/invesalius/gui/frame.py index ec8d0a7..123daee 100755 --- a/invesalius/gui/frame.py +++ b/invesalius/gui/frame.py @@ -91,9 +91,10 @@ class Frame(wx.Frame): ps.Publisher().subscribe(self.BeginBusyCursor, 'Begin busy cursor') ps.Publisher().subscribe(self.EndBusyCursor, 'End busy cursor') ps.Publisher().subscribe(self.HideContentPanel, 'Hide content panel') + ps.Publisher().subscribe(self.CloseProgram, 'Close Window') def EndBusyCursor(self, pubsub_evt=None): - try: + try: wx.EndBusyCursor() except wx._core.PyAssertionError: #xEndBusyCursor(): no matching wxBeginBusyCursor() for wxEndBusyCursor() @@ -104,7 +105,7 @@ class Frame(wx.Frame): def SetProjectName(self, pubsub_evt): proj_name = pubsub_evt.data - + if not(proj_name): self.SetTitle("InVesalius 3") else: @@ -123,6 +124,7 @@ class Frame(wx.Frame): #self.Bind(wx.EVT_CLOSE, self.OnExit) def CloseWindow(self, evt): + ps.Publisher().sendMessage('Close Project') ps.Publisher().sendMessage("Stop Config Recording") self.Destroy() @@ -248,8 +250,8 @@ class Frame(wx.Frame): self.SaveAsProject() elif id == const.ID_PROJECT_CLOSE: self.CloseProject() - #elif id == const.ID_EXIT: - # self.OnExit(evt) + elif id == const.ID_EXIT: + self.OnExit() elif id == const.ID_ABOUT: self.ShowAbout() elif id == const.ID_START: @@ -286,9 +288,11 @@ class Frame(wx.Frame): utils.debug("CloseProject") ps.Publisher().sendMessage('Close Project') - def OnExit(self, event): - self.Exit() - event.Skip() + def OnExit(self): + ps.Publisher().sendMessage('Close Project') + + def CloseProgram(self, pubsub_evt): + self.Destroy() def Exit(self): utils.debug("Exit") @@ -303,8 +307,8 @@ class Frame(wx.Frame): self.aui_manager.Update() #def OnClose(self): - # # TODO: implement this, based on wx.Demo - # pass + # TODO: implement this, based on wx.Demo + #pass # ------------------------------------------------------------------------------ # TODO: what will appear on ivMenuBar? # Menu items ID's, necessary to bind events on them @@ -417,7 +421,7 @@ class MenuBar(wx.MenuBar): def SetStateProjectClose(self): for item in self.enable_items: - self.Enable(item, False) + self.Enable(item, False) def __bind_events(self): # TODO: in future, possibly when wxPython 2.9 is available, @@ -594,7 +598,7 @@ class ProjectToolBar(wx.ToolBar): def SetStateProjectClose(self): for tool in self.enable_items: - self.EnableTool(tool, False) + self.EnableTool(tool, False) def OnEnableState(self, pubsub_evt): state = pubsub_evt.data @@ -730,7 +734,7 @@ class ObjectToolBar(wx.ToolBar): def SetStateProjectClose(self): for tool in self.enable_items: self.EnableTool(tool, False) - self.UntoggleAllItems() + self.UntoggleAllItems() def __bind_events_wx(self): @@ -809,8 +813,8 @@ class SliceToolBar(wx.ToolBar): def SetStateProjectClose(self): for tool in self.enable_items: - self.EnableTool(tool, False) - + self.EnableTool(tool, False) + def __bind_events_wx(self): self.Bind(wx.EVT_TOOL, self.OnClick) @@ -916,7 +920,7 @@ shortHelp= _("Hide task panel")) self.ontool_text = True self.OnText() for tool in self.enable_items: - self.EnableTool(tool, False) + self.EnableTool(tool, False) def __bind_events(self): ps.Publisher().subscribe(self.SetLayoutButtonOnlyData, diff --git a/invesalius/gui/widgets/platebtn.py b/invesalius/gui/widgets/platebtn.py index 0da962f..92c23f1 100644 --- a/invesalius/gui/widgets/platebtn.py +++ b/invesalius/gui/widgets/platebtn.py @@ -11,9 +11,9 @@ Editra Control Library: PlateButton The PlateButton is a custom owner drawn flat button, that in many ways emulates -the buttons found the bookmark bar of the Safari browser. It can be used as a -drop in replacement for wx.Button/wx.BitmapButton under most circumstances. It -also offers a wide range of options for customizing its appearance, a +the buttons found the bookmark bar of the Safari browser. It can be used as a +drop in replacement for wx.Button/wx.BitmapButton under most circumstances. It +also offers a wide range of options for customizing its appearance, a description of each of the main style settings is listed below. Main Button Styles: @@ -77,7 +77,7 @@ __svnid__ = "$Id: platebtn.py 57713 2009-01-01 23:36:15Z CJP $" __revision__ = "$Revision: 57713 $" __all__ = ["PlateButton", "AdjustAlpha", "AdjustColor", "GetHighlightColor", - "PLATE_NORMAL", "PLATE_PRESSED", "PLATE_HIGHLIGHT", + "PLATE_NORMAL", "PLATE_PRESSED", "PLATE_HIGHLIGHT", "PB_STYLE_DEFAULT", "PB_STYLE_GRADIENT", "PB_STYLE_SQUARE", "PB_STYLE_NOBG", "PB_STYLE_DROPARROW", "EVT_PLATEBTN_DROPARROW_PRESSED"] @@ -120,7 +120,7 @@ class PlateButton(wx.PyControl): displaying bitmaps and having an attached dropdown menu. """ - def __init__(self, parent, id_=wx.ID_ANY, label='', bmp=None, + def __init__(self, parent, id_=wx.ID_ANY, label='', bmp=None, pos=wx.DefaultPosition, size=wx.DefaultSize, style=PB_STYLE_DEFAULT, name=wx.ButtonNameStr): """Create a PlateButton @@ -314,14 +314,14 @@ class PlateButton(wx.PyControl): color = GetHighlightColour() pcolor = AdjustColour(color, -12) colors = dict(default=True, - hlight=color, + hlight=color, press=pcolor, htxt=BestLabelColour(self.GetForegroundColour())) return colors def __LeaveWindow(self): if (self._style & PB_STYLE_TOGGLE) and self._pressed: - self.SetState(PLATE_PRESSED) + self.SetState(PLATE_PRESSED) else: self.SetState(PLATE_NORMAL) @@ -363,7 +363,7 @@ class PlateButton(wx.PyControl): lsize = self.GetTextExtent(self.GetLabel()) width += lsize[0] height += lsize[1] - + if self._bmp['enable'] is not None: bsize = self._bmp['enable'].GetSize() width += (bsize[0] + 10) @@ -423,7 +423,7 @@ class PlateButton(wx.PyControl): # GetBitmap Aliases for BitmapButton api GetBitmapFocus = GetBitmapLabel GetBitmapHover = GetBitmapLabel - + # Alias for GetLabel GetLabelText = wx.PyControl.GetLabel @@ -504,9 +504,9 @@ class PlateButton(wx.PyControl): if (self._style & PB_STYLE_TOGGLE): self._pressed = not self._pressed - + self.SetFocus() - + def OnLeftUp(self, evt): """Post a button event if the control was previously in a pressed state. @@ -586,7 +586,7 @@ class PlateButton(wx.PyControl): """Set the color of the label. The optimal label color is usually automatically selected depending on the button color. In some cases the colors that are choosen may not be optimal. - + The normal state must be specified, if the other two params are left Null they will be automatically guessed based on the normal color. To prevent this automatic color choices from happening either specify @@ -686,7 +686,7 @@ class PlateButton(wx.PyControl): self.PopupMenu(self._menu, (xpos, size[1] + adj)) - def Toggle(self): + def Toggle(self): self._pressed = not self._pressed if self._pressed: self.SetState(PLATE_PRESSED) -- libgit2 0.21.2