Commit 8d1711c03c3139ed3ed5efc74793a4de2636d5bd
1 parent
a1b9aeaa
Exists in
master
and in
68 other branches
ENH: Close project working (still testing)
Showing
7 changed files
with
93 additions
and
60 deletions
Show diff stats
invesalius/control.py
| ... | ... | @@ -68,12 +68,16 @@ class Controller(): |
| 68 | 68 | ps.Publisher().subscribe(self.Progress, "Update dicom load") |
| 69 | 69 | ps.Publisher().subscribe(self.OnLoadImportPanel, "End dicom load") |
| 70 | 70 | ps.Publisher().subscribe(self.OnCancelImport, 'Cancel DICOM load') |
| 71 | - ps.Publisher().subscribe(self.OnCloseProject, 'Close Project') | |
| 71 | + ps.Publisher().subscribe(self.OnShowDialogCloseProject, 'Close Project') | |
| 72 | 72 | |
| 73 | 73 | |
| 74 | 74 | def OnCancelImport(self, pubsub_evt): |
| 75 | 75 | #self.cancel_import = True |
| 76 | 76 | ps.Publisher().sendMessage('Hide import panel') |
| 77 | + | |
| 78 | + | |
| 79 | +########################### | |
| 80 | +########################### | |
| 77 | 81 | |
| 78 | 82 | def OnShowDialogImportDirectory(self, pubsub_evt): |
| 79 | 83 | self.ShowDialogImportDirectory() |
| ... | ... | @@ -85,19 +89,71 @@ class Controller(): |
| 85 | 89 | saveas = pubsub_evt.data |
| 86 | 90 | self.ShowDialogSaveProject(saveas) |
| 87 | 91 | |
| 92 | + def OnShowDialogCloseProject(self, pubsub_evt): | |
| 93 | + self.ShowDialogCloseProject() | |
| 94 | + | |
| 88 | 95 | ########################### |
| 89 | 96 | |
| 90 | 97 | def ShowDialogImportDirectory(self): |
| 91 | 98 | dirpath = dialog.ShowImportDirDialog() |
| 92 | 99 | 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 | |
| 93 | 106 | self.StartImportPanel(dirpath) |
| 94 | 107 | ps.Publisher().sendMessage("Load data to import panel", dirpath) |
| 95 | 108 | |
| 96 | 109 | def ShowDialogOpenProject(self): |
| 97 | 110 | filepath = dialog.ShowOpenProjectDialog() |
| 98 | 111 | 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 | |
| 99 | 118 | self.OpenProject(filepath) |
| 100 | 119 | |
| 120 | + def ShowDialogSaveProject(self, saveas=False): | |
| 121 | + session = ses.Session() | |
| 122 | + if saveas: | |
| 123 | + proj = prj.Project() | |
| 124 | + filepath = dialog.ShowSaveAsProjectDialog(proj.name) | |
| 125 | + if filepath: | |
| 126 | + session.RemoveTemp() | |
| 127 | + session.OpenProject(filepath) | |
| 128 | + else: | |
| 129 | + return | |
| 130 | + else: | |
| 131 | + dirpath, filename = session.project_path | |
| 132 | + filepath = os.path.join(dirpath, filename) | |
| 133 | + | |
| 134 | + self.SaveProject(filepath) | |
| 135 | + | |
| 136 | + | |
| 137 | + def ShowDialogCloseProject(self): | |
| 138 | + session = ses.Session() | |
| 139 | + st = session.project_status | |
| 140 | + filename = session.project_path[1] | |
| 141 | + if (st == const.PROJ_NEW) or (st == const.PROJ_CHANGE): | |
| 142 | + answer = dialog.SaveChangesDialog(filename) | |
| 143 | + if not answer: | |
| 144 | + print "Close without changes" | |
| 145 | + self.CloseProject() | |
| 146 | + elif answer == 1: | |
| 147 | + self.ShowDialogSaveProject() | |
| 148 | + print "Save changes and close" | |
| 149 | + self.CloseProject() | |
| 150 | + #elif answer == -1: | |
| 151 | + # print "Cancel" | |
| 152 | + else: | |
| 153 | + self.CloseProject() | |
| 154 | + | |
| 155 | +########################### | |
| 156 | + | |
| 101 | 157 | def OpenProject(self, filepath): |
| 102 | 158 | path = os.path.abspath(filepath) |
| 103 | 159 | |
| ... | ... | @@ -105,9 +161,6 @@ class Controller(): |
| 105 | 161 | proj.OpenPlistProject(path) |
| 106 | 162 | proj.SetAcquisitionModality(proj.modality) |
| 107 | 163 | |
| 108 | - session = ses.Session() | |
| 109 | - session.OpenProject(path) | |
| 110 | - | |
| 111 | 164 | mask = msk.Mask() |
| 112 | 165 | mask._set_class_index(proj.last_mask_index) |
| 113 | 166 | |
| ... | ... | @@ -116,21 +169,8 @@ class Controller(): |
| 116 | 169 | |
| 117 | 170 | self.LoadProject() |
| 118 | 171 | |
| 119 | - def ShowDialogSaveProject(self, saveas=False): | |
| 120 | 172 | session = ses.Session() |
| 121 | - if saveas: | |
| 122 | - proj = prj.Project() | |
| 123 | - filepath = dialog.ShowSaveAsProjectDialog(proj.name) | |
| 124 | - if filepath: | |
| 125 | - session.RemoveTemp() | |
| 126 | - session.OpenProject(filepath) | |
| 127 | - else: | |
| 128 | - return | |
| 129 | - else: | |
| 130 | - dirpath, filename = session.project_path | |
| 131 | - filepath = os.path.join(dirpath, filename) | |
| 132 | - | |
| 133 | - self.SaveProject(filepath) | |
| 173 | + session.OpenProject(filepath) | |
| 134 | 174 | |
| 135 | 175 | def SaveProject(self, path=None): |
| 136 | 176 | session = ses.Session() |
| ... | ... | @@ -143,28 +183,19 @@ class Controller(): |
| 143 | 183 | proj = prj.Project() |
| 144 | 184 | prj.Project().SavePlistProject(dirpath, filename) |
| 145 | 185 | |
| 186 | + session.SaveProject() | |
| 187 | + | |
| 146 | 188 | def CloseProject(self): |
| 147 | - print "Close Project" | |
| 148 | - session = ses.Session() | |
| 149 | - session.CloseProject() | |
| 150 | - | |
| 151 | 189 | proj = prj.Project() |
| 152 | 190 | proj.Close() |
| 153 | 191 | |
| 154 | - # TODO: | |
| 155 | - # Remove items from combo of masks | |
| 156 | - # Remove items from combo of surfaces | |
| 157 | - # Remove items from dictionaries | |
| 158 | - # Slice | |
| 159 | - # Surface | |
| 160 | - # -------------- | |
| 161 | - # | |
| 162 | - | |
| 163 | 192 | ps.Publisher().sendMessage('Hide content panel') |
| 193 | + ps.Publisher().sendMessage('Close project data') | |
| 164 | 194 | |
| 195 | + session = ses.Session() | |
| 196 | + session.CloseProject() | |
| 165 | 197 | |
| 166 | -################################## | |
| 167 | - | |
| 198 | +########################### | |
| 168 | 199 | |
| 169 | 200 | |
| 170 | 201 | def StartImportPanel(self, path): |
| ... | ... | @@ -363,24 +394,4 @@ class Controller(): |
| 363 | 394 | |
| 364 | 395 | |
| 365 | 396 | |
| 366 | - def OnCloseProject(self, pubsub_evt): | |
| 367 | - print "OnCloseProject" | |
| 368 | - session = ses.Session() | |
| 369 | - st = session.project_status | |
| 370 | - filename = session.project_path[1] | |
| 371 | - if (st == const.PROJ_NEW) or (st == const.PROJ_CHANGE): | |
| 372 | - answer = dialog.SaveChangesDialog(filename) | |
| 373 | - if not answer: | |
| 374 | - print "Close without changes" | |
| 375 | - self.CloseProject() | |
| 376 | - elif answer == 1: | |
| 377 | - self.ShowDialogSaveProject() | |
| 378 | - print "Save changes and close" | |
| 379 | - self.CloseProject() | |
| 380 | - #else: | |
| 381 | - # print "Cancel" | |
| 382 | - else: | |
| 383 | - print ":) Close without changes" | |
| 384 | - self.CloseProject() | |
| 385 | - | |
| 386 | 397 | ... | ... |
invesalius/data/slice_.py
| ... | ... | @@ -40,10 +40,12 @@ class Slice(object): |
| 40 | 40 | self.imagedata = None |
| 41 | 41 | self.current_mask = None |
| 42 | 42 | self.blend_filter = None |
| 43 | - self.__bind_events() | |
| 43 | + | |
| 44 | 44 | self.num_gradient = 0 |
| 45 | 45 | self.mode = md.SliceMode() |
| 46 | 46 | |
| 47 | + self.__bind_events() | |
| 48 | + | |
| 47 | 49 | def __bind_events(self): |
| 48 | 50 | # Slice properties |
| 49 | 51 | ps.Publisher().subscribe(self.UpdateCursorPosition, |
| ... | ... | @@ -85,7 +87,7 @@ class Slice(object): |
| 85 | 87 | ps.Publisher().subscribe(self.InputImageWidget, 'Input Image in the widget') |
| 86 | 88 | ps.Publisher().subscribe(self.OnExportMask,'Export mask to file') |
| 87 | 89 | |
| 88 | - ps.Publisher().subscribe(self.OnCloseProject, 'Close Project') | |
| 90 | + ps.Publisher().subscribe(self.OnCloseProject, 'Close project data') | |
| 89 | 91 | |
| 90 | 92 | def OnCloseProject(self, pubsub_evt): |
| 91 | 93 | self.CloseProject() | ... | ... |
invesalius/data/surface.py
| ... | ... | @@ -103,7 +103,7 @@ class SurfaceManager(): |
| 103 | 103 | ps.Publisher().subscribe(self.OnShowSurface, 'Show surface') |
| 104 | 104 | ps.Publisher().subscribe(self.OnExportSurface,'Export surface to file') |
| 105 | 105 | ps.Publisher().subscribe(self.OnLoadSurfaceDict, 'Load surface dict') |
| 106 | - ps.Publisher().subscribe(self.OnCloseProject, 'Close Project') | |
| 106 | + ps.Publisher().subscribe(self.OnCloseProject, 'Close project data') | |
| 107 | 107 | |
| 108 | 108 | def OnCloseProject(self, pubsub_evt): |
| 109 | 109 | self.CloseProject() | ... | ... |
invesalius/data/viewer_slice.py
| ... | ... | @@ -765,6 +765,26 @@ class Viewer(wx.Panel): |
| 765 | 765 | |
| 766 | 766 | ps.Publisher().subscribe(self.OnSetMode, |
| 767 | 767 | 'Set slice mode') |
| 768 | + ps.Publisher().subscribe(self.OnCloseProject, 'Close project data') | |
| 769 | + | |
| 770 | + def OnCloseProject(self, pubsub_evt): | |
| 771 | + self.CloseProject() | |
| 772 | + | |
| 773 | + def CloseProject(self): | |
| 774 | + for slice_data in self.slice_data_list: | |
| 775 | + self.interactor.GetRenderWindow().RemoveRenderer(slice_data.renderer) | |
| 776 | + del slice_data | |
| 777 | + | |
| 778 | + self.modes = []#['DEFAULT'] | |
| 779 | + self.mouse_pressed = 0 | |
| 780 | + self.slice_data_list = [] | |
| 781 | + self.layout = (1, 1) | |
| 782 | + self.orientation_texts = [] | |
| 783 | + self.slice_number = 0 | |
| 784 | + self.cursor = None | |
| 785 | + self.wl_text = None | |
| 786 | + self.pick = vtk.vtkPropPicker() | |
| 787 | + | |
| 768 | 788 | |
| 769 | 789 | def OnSetMode(self, pubsub_evt): |
| 770 | 790 | state = pubsub_evt.data | ... | ... |
invesalius/gui/data_notebook.py
| ... | ... | @@ -84,7 +84,7 @@ class MasksListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): |
| 84 | 84 | 'Change mask colour in notebook') |
| 85 | 85 | |
| 86 | 86 | ps.Publisher().subscribe(self.OnChangeCurrentMask, 'Change mask selected') |
| 87 | - ps.Publisher().subscribe(self.OnCloseProject, 'Close Project') | |
| 87 | + ps.Publisher().subscribe(self.OnCloseProject, 'Close project data') | |
| 88 | 88 | |
| 89 | 89 | def OnCloseProject(self, pubsub_evt): |
| 90 | 90 | self.DeleteAllItems() |
| ... | ... | @@ -217,7 +217,7 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): |
| 217 | 217 | 'Set surface transparency') |
| 218 | 218 | ps.Publisher().subscribe(self.EditSurfaceColour, |
| 219 | 219 | 'Set surface colour') |
| 220 | - ps.Publisher().subscribe(self.OnCloseProject, 'Close Project') | |
| 220 | + ps.Publisher().subscribe(self.OnCloseProject, 'Close project data') | |
| 221 | 221 | |
| 222 | 222 | def OnCloseProject(self, pubsub_evt): |
| 223 | 223 | self.DeleteAllItems() | ... | ... |
invesalius/gui/task_slice.py
| ... | ... | @@ -291,7 +291,7 @@ class MaskProperties(wx.Panel): |
| 291 | 291 | 'Set threshold values in gradient') |
| 292 | 292 | ps.Publisher().subscribe(self.SelectMaskName, 'Select mask name in combo') |
| 293 | 293 | ps.Publisher().subscribe(self.ChangeMaskName, 'Change mask name') |
| 294 | - ps.Publisher().subscribe(self.OnCloseProject, 'Close Project') | |
| 294 | + ps.Publisher().subscribe(self.OnCloseProject, 'Close project data') | |
| 295 | 295 | |
| 296 | 296 | def OnCloseProject(self, pubsub_evt): |
| 297 | 297 | self.CloseProject() | ... | ... |
invesalius/gui/task_surface.py
| ... | ... | @@ -341,7 +341,7 @@ class SurfaceProperties(wx.Panel): |
| 341 | 341 | 'Update surface info in GUI') |
| 342 | 342 | ps.Publisher().subscribe(self.ChangeSurfaceName, |
| 343 | 343 | 'Change surface name') |
| 344 | - ps.Publisher().subscribe(self.OnCloseProject, 'Close Project') | |
| 344 | + ps.Publisher().subscribe(self.OnCloseProject, 'Close project data') | |
| 345 | 345 | |
| 346 | 346 | def OnCloseProject(self, pubsub_evt): |
| 347 | 347 | self.CloseProject() | ... | ... |