Commit 157fb2f741fa071e77eedb1d8a553e47a0708dc2

Authored by tatiana
1 parent b1d4e29d

ENH: Open project while a modified project is open

Showing 2 changed files with 40 additions and 14 deletions   Show diff stats
invesalius/control.py
... ... @@ -95,26 +95,35 @@ class Controller():
95 95 ###########################
96 96  
97 97 def ShowDialogImportDirectory(self):
  98 + # Offer to save current project if necessary
  99 + session = ses.Session()
  100 + st = session.project_status
  101 + if (st == const.PROJ_NEW) or (st == const.PROJ_CHANGE):
  102 + filename = session.project_path[1]
  103 + answer = dialog.SaveChangesDialog2(filename)
  104 + if answer:
  105 + self.ShowDialogSaveProject()
  106 +
  107 + # Import project
98 108 dirpath = dialog.ShowImportDirDialog()
99 109 if dirpath:
100   - # Close project if necessary
101   - session = ses.Session()
102   - st = session.project_status
103   - if st != const.PROJ_CLOSE:
104   - self.ShowDialogCloseProject()
105   - # Import project
106 110 self.StartImportPanel(dirpath)
107 111 ps.Publisher().sendMessage("Load data to import panel", dirpath)
108 112  
109 113 def ShowDialogOpenProject(self):
  114 + # Offer to save current project if necessary
  115 + session = ses.Session()
  116 + st = session.project_status
  117 + if (st == const.PROJ_NEW) or (st == const.PROJ_CHANGE):
  118 + filename = session.project_path[1]
  119 + answer = dialog.SaveChangesDialog2(filename)
  120 + if answer:
  121 + self.ShowDialogSaveProject()
  122 +
  123 + # Open project
110 124 filepath = dialog.ShowOpenProjectDialog()
111 125 if filepath:
112   - # Close project if necessary
113   - session = ses.Session()
114   - st = session.project_status
115   - if st != const.PROJ_CLOSE:
116   - self.ShowDialogCloseProject()
117   - # Open project
  126 + self.CloseProject()
118 127 self.OpenProject(filepath)
119 128  
120 129 def ShowDialogSaveProject(self, saveas=False):
... ... @@ -147,8 +156,8 @@ class Controller():
147 156 self.ShowDialogSaveProject()
148 157 print "Save changes and close"
149 158 self.CloseProject()
150   - #elif answer == -1:
151   - # print "Cancel"
  159 + elif answer == -1:
  160 + print "Cancel"
152 161 else:
153 162 self.CloseProject()
154 163  
... ...
invesalius/gui/dialogs.py
... ... @@ -270,4 +270,21 @@ def SaveChangesDialog(filename):
270 270 else:
271 271 return -1
272 272  
  273 +def SaveChangesDialog2(filename):
273 274  
  275 + if sys.platform == 'darwin':
  276 + dlg = wx.MessageDialog(None, "",
  277 + "Save changes to "+filename+"?",
  278 + wx.ICON_QUESTION | wx.YES_NO)
  279 + else:
  280 + dlg = wx.MessageDialog(None, "Save changes to "+filename+"?",
  281 + "InVesalius 3",
  282 + wx.ICON_QUESTION | wx.YES_NO)
  283 +
  284 + answer = dlg.ShowModal()
  285 + dlg.Destroy()
  286 +
  287 + if answer == wx.ID_YES:
  288 + return 1
  289 + else:# answer == wx.ID_NO:
  290 + return 0
... ...