From 8d1711c03c3139ed3ed5efc74793a4de2636d5bd Mon Sep 17 00:00:00 2001 From: tatiana Date: Tue, 24 Nov 2009 18:15:00 +0000 Subject: [PATCH] ENH: Close project working (still testing) --- invesalius/control.py | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------------- invesalius/data/slice_.py | 6 ++++-- invesalius/data/surface.py | 2 +- invesalius/data/viewer_slice.py | 20 ++++++++++++++++++++ invesalius/gui/data_notebook.py | 4 ++-- invesalius/gui/task_slice.py | 2 +- invesalius/gui/task_surface.py | 2 +- 7 files changed, 93 insertions(+), 60 deletions(-) diff --git a/invesalius/control.py b/invesalius/control.py index 847b315..108af89 100755 --- a/invesalius/control.py +++ b/invesalius/control.py @@ -68,12 +68,16 @@ class Controller(): ps.Publisher().subscribe(self.Progress, "Update dicom load") ps.Publisher().subscribe(self.OnLoadImportPanel, "End dicom load") ps.Publisher().subscribe(self.OnCancelImport, 'Cancel DICOM load') - ps.Publisher().subscribe(self.OnCloseProject, 'Close Project') + ps.Publisher().subscribe(self.OnShowDialogCloseProject, 'Close Project') def OnCancelImport(self, pubsub_evt): #self.cancel_import = True ps.Publisher().sendMessage('Hide import panel') + + +########################### +########################### def OnShowDialogImportDirectory(self, pubsub_evt): self.ShowDialogImportDirectory() @@ -85,19 +89,71 @@ class Controller(): saveas = pubsub_evt.data self.ShowDialogSaveProject(saveas) + def OnShowDialogCloseProject(self, pubsub_evt): + self.ShowDialogCloseProject() + ########################### def ShowDialogImportDirectory(self): dirpath = dialog.ShowImportDirDialog() if dirpath: + # Close project if necessary + session = ses.Session() + st = session.project_status + if st != const.PROJ_CLOSE: + self.ShowDialogCloseProject() + # Import project self.StartImportPanel(dirpath) ps.Publisher().sendMessage("Load data to import panel", dirpath) def ShowDialogOpenProject(self): filepath = dialog.ShowOpenProjectDialog() if filepath: + # Close project if necessary + session = ses.Session() + st = session.project_status + if st != const.PROJ_CLOSE: + self.ShowDialogCloseProject() + # Open project self.OpenProject(filepath) + def ShowDialogSaveProject(self, saveas=False): + session = ses.Session() + if saveas: + proj = prj.Project() + filepath = dialog.ShowSaveAsProjectDialog(proj.name) + if filepath: + session.RemoveTemp() + session.OpenProject(filepath) + else: + return + else: + dirpath, filename = session.project_path + filepath = os.path.join(dirpath, filename) + + self.SaveProject(filepath) + + + def ShowDialogCloseProject(self): + session = ses.Session() + st = session.project_status + filename = session.project_path[1] + if (st == const.PROJ_NEW) or (st == const.PROJ_CHANGE): + answer = dialog.SaveChangesDialog(filename) + if not answer: + print "Close without changes" + self.CloseProject() + elif answer == 1: + self.ShowDialogSaveProject() + print "Save changes and close" + self.CloseProject() + #elif answer == -1: + # print "Cancel" + else: + self.CloseProject() + +########################### + def OpenProject(self, filepath): path = os.path.abspath(filepath) @@ -105,9 +161,6 @@ class Controller(): proj.OpenPlistProject(path) proj.SetAcquisitionModality(proj.modality) - session = ses.Session() - session.OpenProject(path) - mask = msk.Mask() mask._set_class_index(proj.last_mask_index) @@ -116,21 +169,8 @@ class Controller(): self.LoadProject() - def ShowDialogSaveProject(self, saveas=False): session = ses.Session() - if saveas: - proj = prj.Project() - filepath = dialog.ShowSaveAsProjectDialog(proj.name) - if filepath: - session.RemoveTemp() - session.OpenProject(filepath) - else: - return - else: - dirpath, filename = session.project_path - filepath = os.path.join(dirpath, filename) - - self.SaveProject(filepath) + session.OpenProject(filepath) def SaveProject(self, path=None): session = ses.Session() @@ -143,28 +183,19 @@ class Controller(): proj = prj.Project() prj.Project().SavePlistProject(dirpath, filename) + session.SaveProject() + def CloseProject(self): - print "Close Project" - session = ses.Session() - session.CloseProject() - proj = prj.Project() proj.Close() - # TODO: - # Remove items from combo of masks - # Remove items from combo of surfaces - # Remove items from dictionaries - # Slice - # Surface - # -------------- - # - ps.Publisher().sendMessage('Hide content panel') + ps.Publisher().sendMessage('Close project data') + session = ses.Session() + session.CloseProject() -################################## - +########################### def StartImportPanel(self, path): @@ -363,24 +394,4 @@ class Controller(): - def OnCloseProject(self, pubsub_evt): - print "OnCloseProject" - session = ses.Session() - st = session.project_status - filename = session.project_path[1] - if (st == const.PROJ_NEW) or (st == const.PROJ_CHANGE): - answer = dialog.SaveChangesDialog(filename) - if not answer: - print "Close without changes" - self.CloseProject() - elif answer == 1: - self.ShowDialogSaveProject() - print "Save changes and close" - self.CloseProject() - #else: - # print "Cancel" - else: - print ":) Close without changes" - self.CloseProject() - diff --git a/invesalius/data/slice_.py b/invesalius/data/slice_.py index 3bf850f..778179e 100644 --- a/invesalius/data/slice_.py +++ b/invesalius/data/slice_.py @@ -40,10 +40,12 @@ class Slice(object): self.imagedata = None self.current_mask = None self.blend_filter = None - self.__bind_events() + self.num_gradient = 0 self.mode = md.SliceMode() + self.__bind_events() + def __bind_events(self): # Slice properties ps.Publisher().subscribe(self.UpdateCursorPosition, @@ -85,7 +87,7 @@ class Slice(object): ps.Publisher().subscribe(self.InputImageWidget, 'Input Image in the widget') ps.Publisher().subscribe(self.OnExportMask,'Export mask to file') - ps.Publisher().subscribe(self.OnCloseProject, 'Close Project') + ps.Publisher().subscribe(self.OnCloseProject, 'Close project data') def OnCloseProject(self, pubsub_evt): self.CloseProject() diff --git a/invesalius/data/surface.py b/invesalius/data/surface.py index 0d6a5e2..9cda161 100644 --- a/invesalius/data/surface.py +++ b/invesalius/data/surface.py @@ -103,7 +103,7 @@ class SurfaceManager(): ps.Publisher().subscribe(self.OnShowSurface, 'Show surface') ps.Publisher().subscribe(self.OnExportSurface,'Export surface to file') ps.Publisher().subscribe(self.OnLoadSurfaceDict, 'Load surface dict') - ps.Publisher().subscribe(self.OnCloseProject, 'Close Project') + ps.Publisher().subscribe(self.OnCloseProject, 'Close project data') def OnCloseProject(self, pubsub_evt): self.CloseProject() diff --git a/invesalius/data/viewer_slice.py b/invesalius/data/viewer_slice.py index 50c2317..953209d 100755 --- a/invesalius/data/viewer_slice.py +++ b/invesalius/data/viewer_slice.py @@ -765,6 +765,26 @@ class Viewer(wx.Panel): ps.Publisher().subscribe(self.OnSetMode, 'Set slice mode') + ps.Publisher().subscribe(self.OnCloseProject, 'Close project data') + + def OnCloseProject(self, pubsub_evt): + self.CloseProject() + + def CloseProject(self): + for slice_data in self.slice_data_list: + self.interactor.GetRenderWindow().RemoveRenderer(slice_data.renderer) + del slice_data + + self.modes = []#['DEFAULT'] + self.mouse_pressed = 0 + self.slice_data_list = [] + self.layout = (1, 1) + self.orientation_texts = [] + self.slice_number = 0 + self.cursor = None + self.wl_text = None + self.pick = vtk.vtkPropPicker() + def OnSetMode(self, pubsub_evt): state = pubsub_evt.data diff --git a/invesalius/gui/data_notebook.py b/invesalius/gui/data_notebook.py index c7a699b..5a50548 100644 --- a/invesalius/gui/data_notebook.py +++ b/invesalius/gui/data_notebook.py @@ -84,7 +84,7 @@ class MasksListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): 'Change mask colour in notebook') ps.Publisher().subscribe(self.OnChangeCurrentMask, 'Change mask selected') - ps.Publisher().subscribe(self.OnCloseProject, 'Close Project') + ps.Publisher().subscribe(self.OnCloseProject, 'Close project data') def OnCloseProject(self, pubsub_evt): self.DeleteAllItems() @@ -217,7 +217,7 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): 'Set surface transparency') ps.Publisher().subscribe(self.EditSurfaceColour, 'Set surface colour') - ps.Publisher().subscribe(self.OnCloseProject, 'Close Project') + ps.Publisher().subscribe(self.OnCloseProject, 'Close project data') def OnCloseProject(self, pubsub_evt): self.DeleteAllItems() diff --git a/invesalius/gui/task_slice.py b/invesalius/gui/task_slice.py index da799b4..4a9dfb7 100644 --- a/invesalius/gui/task_slice.py +++ b/invesalius/gui/task_slice.py @@ -291,7 +291,7 @@ class MaskProperties(wx.Panel): 'Set threshold values in gradient') ps.Publisher().subscribe(self.SelectMaskName, 'Select mask name in combo') ps.Publisher().subscribe(self.ChangeMaskName, 'Change mask name') - ps.Publisher().subscribe(self.OnCloseProject, 'Close Project') + ps.Publisher().subscribe(self.OnCloseProject, 'Close project data') def OnCloseProject(self, pubsub_evt): self.CloseProject() diff --git a/invesalius/gui/task_surface.py b/invesalius/gui/task_surface.py index bbe472f..f484250 100644 --- a/invesalius/gui/task_surface.py +++ b/invesalius/gui/task_surface.py @@ -341,7 +341,7 @@ class SurfaceProperties(wx.Panel): 'Update surface info in GUI') ps.Publisher().subscribe(self.ChangeSurfaceName, 'Change surface name') - ps.Publisher().subscribe(self.OnCloseProject, 'Close Project') + ps.Publisher().subscribe(self.OnCloseProject, 'Close project data') def OnCloseProject(self, pubsub_evt): self.CloseProject() -- libgit2 0.21.2