diff --git a/invesalius/constants.py b/invesalius/constants.py index 05a7b09..3930130 100644 --- a/invesalius/constants.py +++ b/invesalius/constants.py @@ -276,7 +276,7 @@ VTK_WARNING = 0 #---------------------------------------------------------- [ID_FILE_IMPORT, ID_FILE_LOAD_INTERNET, ID_FILE_SAVE, ID_FILE_PHOTO, -ID_FILE_PRINT] = [wx.NewId() for number in range(5)] +ID_FILE_PRINT, ID_FILE_OPEN] = [wx.NewId() for number in range(6)] diff --git a/invesalius/gui/dialogs.py b/invesalius/gui/dialogs.py index 41468e5..0c4bcf2 100644 --- a/invesalius/gui/dialogs.py +++ b/invesalius/gui/dialogs.py @@ -16,10 +16,15 @@ # PARTICULAR. Consulte a Licenca Publica Geral GNU para obter mais # detalhes. #-------------------------------------------------------------------------- +import os +import sys + import wx from wx.lib import masked import wx.lib.pubsub as ps +import project + class NumberDialog(wx.Dialog): def __init__(self, message, value=0): pre = wx.PreDialog() @@ -115,4 +120,74 @@ class ProgressDialog(object): def Close(self): self.dlg.Destroy() + + + + + + +#--------- +WILDCARD_OPEN = "InVesalius 3 project (*.inv3)|*.inv3|"\ + "All files (*.*)|*.*" + +def ShowOpenProjectDialog(): + # Default system path + if sys.platform == 'win32': + default_path = "" + else: + default_path = os.getcwd() + + dlg = wx.FileDialog(None, message="Open InVesalius 3 project...", + defaultDir=default_path, + defaultFile="", wildcard=WILDCARD_OPEN, + style=wx.OPEN|wx.CHANGE_DIR) + + # In OSX this filter is not working - wxPython 2.8.10 problem + if sys.platform != 'darwin': + dlg.SetFilterIndex(0) + else: + dlg.SetFilterIndex(1) + + # Show the dialog and retrieve the user response. If it is the OK response, + # process the data. + filepath = None + if dlg.ShowModal() == wx.ID_OK: + # This returns a Python list of files that were selected. + filepath = dlg.GetPath() + + # Destroy the dialog. Don't do this until you are done with it! + # BAD things can happen otherwise! + dlg.Destroy() + return filepath + +def ShowImportDirDialog(): + dlg = wx.DirDialog(None, "Choose a DICOM folder:", "", + style=wx.DD_DEFAULT_STYLE + | wx.DD_DIR_MUST_EXIST + | wx.DD_CHANGE_DIR) + + path = None + if dlg.ShowModal() == wx.ID_OK: + path = dlg.GetPath() + # Only destroy a dialog after you're done with it. + dlg.Destroy() + return path + +def ShowSaveAsProjectDialog(default_filename=None): + dlg = wx.FileDialog(None, + "Save project as...", # title + "", # last used directory + default_filename, + "InVesalius project (*.inv3)|*.inv3", + wx.SAVE|wx.OVERWRITE_PROMPT) + #dlg.SetFilterIndex(0) # default is VTI + + filename = None + if dlg.ShowModal() == wx.ID_OK: + filename = dlg.GetPath() + extension = "inv3" + if sys.platform != 'win32': + if filename.split(".")[-1] != extension: + filename = filename + "." + extension + return filename diff --git a/invesalius/gui/frame.py b/invesalius/gui/frame.py index 44550d4..10b301b 100755 --- a/invesalius/gui/frame.py +++ b/invesalius/gui/frame.py @@ -28,6 +28,7 @@ import wx.lib.pubsub as ps import constants as const import default_tasks as tasks import default_viewers as viewers +import gui.dialogs as dlg import import_panel as imp from project import Project @@ -82,6 +83,15 @@ class Frame(wx.Frame): ps.Publisher().subscribe(self.SetProjectName, 'Set project name') ps.Publisher().subscribe(self.ShowContentPanel, 'Cancel DICOM load') ps.Publisher().subscribe(self.HideImportPanel, 'Hide import panel') + ps.Publisher().subscribe(self.BeginBusyCursor, 'Begin busy cursor') + ps.Publisher().subscribe(self.EndBusyCursor, 'End busy cursor') + + + def EndBusyCursor(self, pubsub_evt=None): + wx.EndBusyCursor() + + def BeginBusyCursor(self, pubsub_evt=None): + wx.BeginBusyCursor() def SetProjectName(self, pubsub_evt): proj_name = pubsub_evt.data @@ -377,26 +387,15 @@ class ProjectToolBar(wx.ToolBar): def __init_items(self): - - BMP_IMPORT = wx.Bitmap(os.path.join(const.ICON_DIR, "file_import.png"), - wx.BITMAP_TYPE_PNG) - BMP_NET = wx.Bitmap(os.path.join(const.ICON_DIR, - "file_from_internet.png"), - wx.BITMAP_TYPE_PNG) - BMP_SAVE = wx.Bitmap(os.path.join(const.ICON_DIR, "file_save.png"), - wx.BITMAP_TYPE_PNG) - BMP_PRINT = wx.Bitmap(os.path.join(const.ICON_DIR, "print.png"), - wx.BITMAP_TYPE_PNG) - BMP_PHOTO = wx.Bitmap(os.path.join(const.ICON_DIR, "tool_photo.png"), - wx.BITMAP_TYPE_PNG) - if sys.platform == 'darwin': - BMP_IMPORT = wx.Bitmap(os.path.join(const.ICON_DIR, - "file_import_original.png"), - wx.BITMAP_TYPE_PNG) BMP_NET = wx.Bitmap(os.path.join(const.ICON_DIR, "file_from_internet_original.png"), wx.BITMAP_TYPE_PNG) + BMP_IMPORT = wx.Bitmap(os.path.join(const.ICON_DIR, + "file_import_original.png"), + wx.BITMAP_TYPE_PNG) + BMP_OPEN = wx.Bitmap(os.path.join(const.ICON_DIR,"file_open_original.png"), + wx.BITMAP_TYPE_PNG) BMP_SAVE = wx.Bitmap(os.path.join(const.ICON_DIR, "file_save_original.png"), wx.BITMAP_TYPE_PNG) @@ -407,25 +406,28 @@ class ProjectToolBar(wx.ToolBar): "tool_photo_original.png"), wx.BITMAP_TYPE_PNG) else: - BMP_IMPORT = wx.Bitmap(os.path.join(const.ICON_DIR, - "file_import.png"), - wx.BITMAP_TYPE_PNG) - BMP_NET = wx.Bitmap(os.path.join(const.ICON_DIR, - "file_from_internet.png"), + BMP_NET = wx.Bitmap(os.path.join(const.ICON_DIR,"file_from_internet.png"), wx.BITMAP_TYPE_PNG) + BMP_IMPORT = wx.Bitmap(os.path.join(const.ICON_DIR, "file_import.png"), + wx.BITMAP_TYPE_PNG) + BMP_OPEN = wx.Bitmap(os.path.join(const.ICON_DIR,"file_open.png"), + wx.BITMAP_TYPE_PNG) BMP_SAVE = wx.Bitmap(os.path.join(const.ICON_DIR, "file_save.png"), - wx.BITMAP_TYPE_PNG) + wx.BITMAP_TYPE_PNG) BMP_PRINT = wx.Bitmap(os.path.join(const.ICON_DIR, "print.png"), wx.BITMAP_TYPE_PNG) BMP_PHOTO = wx.Bitmap(os.path.join(const.ICON_DIR, "tool_photo.png"), - wx.BITMAP_TYPE_PNG) + wx.BITMAP_TYPE_PNG) - self.AddLabelTool(const.ID_FILE_IMPORT, - "Import medical image...", - BMP_IMPORT) self.AddLabelTool(const.ID_FILE_LOAD_INTERNET, "Load medical image...", BMP_NET) + self.AddLabelTool(const.ID_FILE_IMPORT, + "Import medical image...", + BMP_IMPORT) + self.AddLabelTool(const.ID_FILE_OPEN, + "Open InVesalius 3 project...", + BMP_OPEN) self.AddLabelTool(const.ID_FILE_SAVE, "Save InVesalius project", BMP_SAVE) @@ -440,32 +442,36 @@ class ProjectToolBar(wx.ToolBar): def __bind_events(self): self.Bind(wx.EVT_TOOL, self.OnToolSave, id=const.ID_FILE_SAVE) + self.Bind(wx.EVT_TOOL, self.OnToolOpen, id=const.ID_FILE_OPEN) + self.Bind(wx.EVT_TOOL, self.OnToolImport, id=const.ID_FILE_IMPORT) - def OnToolSave(self, evt): - filename = None - project_name = (Project().name).replace(' ','_') - + def OnToolImport(self, event): + dirpath = dlg.ShowImportDirDialog() + if dirpath: + ps.Publisher().sendMessage("Load data to import panel", path) + event.Skip() + + def OnToolOpen(self, event): + filepath = dlg.ShowOpenProjectDialog() + if filepath: + ps.Publisher().sendMessage('Open Project', filepath) + event.Skip() + + def OnToolSave(self, event): + filename = (Project().name).replace(' ','_') if Project().save_as: - dlg = wx.FileDialog(None, - "Save InVesalius project as...", # title - "", # last used directory - project_name, # filename - "InVesalius project (*.inv3)|*.inv3", - wx.SAVE|wx.OVERWRITE_PROMPT) - dlg.SetFilterIndex(0) # default is VTI - - if dlg.ShowModal() == wx.ID_OK: - filename = dlg.GetPath() - print "filename", filename - extension = "inv3" - if sys.platform != 'win32': - if filename.split(".")[-1] != extension: - filename = filename + "."+ extension - - Project().save_as = False - + filename = dlg.ShowSaveAsProjectDialog(filename) + if filename: + Project().save_as = False + else: + return ps.Publisher().sendMessage('Save Project',filename) -# ------------------------------------------------------------------ + event.Skip() + + + + + # ------------------------------------------------------------------ class ObjectToolBar(wx.ToolBar): def __init__(self, parent): @@ -593,11 +599,14 @@ class SliceToolBar(wx.ToolBar): BMP_SLICE = wx.Bitmap(os.path.join(const.ICON_DIR, "slice_original.png"), wx.BITMAP_TYPE_PNG) + + BMP_CROSS = wx.Bitmap(os.path.join(const.ICON_DIR,"cross_original.png"), + wx.BITMAP_TYPE_PNG) else: BMP_SLICE = wx.Bitmap(os.path.join(const.ICON_DIR, "slice.png"), wx.BITMAP_TYPE_PNG) - BMP_CROSS = wx.Bitmap(os.path.join(const.ICON_DIR, "cross.png"), + BMP_CROSS = wx.Bitmap(os.path.join(const.ICON_DIR, "cross.png"), wx.BITMAP_TYPE_PNG) self.AddLabelTool(ID_SLICE_SCROLL, "Scroll slice", diff --git a/invesalius/gui/task_importer.py b/invesalius/gui/task_importer.py index 3a9b45a..1ca9026 100644 --- a/invesalius/gui/task_importer.py +++ b/invesalius/gui/task_importer.py @@ -25,15 +25,13 @@ import wx.lib.platebtn as pbtn import wx.lib.pubsub as ps import constants as const +import gui.dialogs as dlg BTN_IMPORT_LOCAL = wx.NewId() BTN_IMPORT_PACS = wx.NewId() BTN_OPEN_PROJECT = wx.NewId() -WILDCARD_OPEN = "InVesalius 1 project (*.promed)|*.promed|"\ - "InVesalius 2 project (*.inv)|*.inv|"\ - "InVesalius 3 project (*.inv3)|*.inv3|"\ - "All files (*.*)|*.*" + class TaskPanel(wx.Panel): def __init__(self, parent): @@ -93,9 +91,9 @@ class InnerTaskPanel(wx.Panel): # Image(s) for buttons BMP_IMPORT = wx.Bitmap("../icons/file_import.png", wx.BITMAP_TYPE_PNG) BMP_NET = wx.Bitmap("../icons/file_from_internet.png", wx.BITMAP_TYPE_PNG) - BMP_NULL = wx.Bitmap("../icons/object_invisible.jpg", wx.BITMAP_TYPE_JPEG) + BMP_OPEN_PROJECT = wx.Bitmap("../icons/file_open.png", wx.BITMAP_TYPE_PNG) - bmp_list = [BMP_IMPORT, BMP_NET, BMP_NULL] + bmp_list = [BMP_IMPORT, BMP_NET, BMP_OPEN_PROJECT] for bmp in bmp_list: bmp.SetWidth(25) bmp.SetHeight(25) @@ -103,12 +101,12 @@ class InnerTaskPanel(wx.Panel): # Buttons related to hyperlinks button_style = pbtn.PB_STYLE_SQUARE | pbtn.PB_STYLE_DEFAULT - button_import_local = pbtn.PlateButton(self, BTN_IMPORT_LOCAL, "", - BMP_IMPORT, style=button_style) button_import_pacs = pbtn.PlateButton(self, BTN_IMPORT_PACS, "", BMP_NET, style=button_style) + button_import_local = pbtn.PlateButton(self, BTN_IMPORT_LOCAL, "", + BMP_IMPORT, style=button_style) button_open_proj = pbtn.PlateButton(self, BTN_OPEN_PROJECT, "", - BMP_NULL, style=button_style) + BMP_OPEN_PROJECT, style=button_style) # When using PlaneButton, it is necessary to bind events from parent win self.Bind(wx.EVT_BUTTON, self.OnButton) @@ -119,10 +117,10 @@ class InnerTaskPanel(wx.Panel): fixed_sizer = wx.FlexGridSizer(rows=3, cols=2, hgap=2, vgap=0) fixed_sizer.AddGrowableCol(0, 1) - fixed_sizer.AddMany([ (link_import_local, 1, flag_link, 3), - (button_import_local, 0, flag_button), - (link_import_pacs, 1, flag_link, 3), + fixed_sizer.AddMany([ (link_import_pacs, 1, flag_link, 3), (button_import_pacs, 0, flag_button), + (link_import_local, 1, flag_link, 3), + (button_import_local, 0, flag_button), (link_open_proj, 1, flag_link, 3), (button_open_proj, 0, flag_button) ]) @@ -137,76 +135,44 @@ class InnerTaskPanel(wx.Panel): # Test load and unload specific projects' links self.TestLoadProjects() - #self.UnloadProjects() - ps.Publisher().subscribe(self.OnLinkImport,("Run menu item", - str(const.ID_FILE_IMPORT))) - - def OnLinkImport(self, evt=None): - dlg = wx.DirDialog(self, "Choose a directory:", "", - style=wx.DD_DEFAULT_STYLE - | wx.DD_DIR_MUST_EXIST - | wx.DD_CHANGE_DIR) - - if dlg.ShowModal() == wx.ID_OK: - path = dlg.GetPath() - ps.Publisher().sendMessage("Load data to import panel", path) - - # Only destroy a dialog after you're done with it. - dlg.Destroy() - - try: - if evt: - evt.Skip() - except(AttributeError): - pass - - def OnLinkImportPACS(self, evt=None): + + def OnLinkImport(self, event): + self.LinkImport() + event.Skip() + + def OnLinkImportPACS(self, event): + self.LinkImportPACS() + event.Skip() + + def OnLinkOpenProject(self, event): + self.LinkOpenProject() + event.Skip() + + def LinkImport(self): + dirpath = dlg.ShowImportDirDialog() + if dirpath: + ps.Publisher().sendMessage("Load data to import panel", dirpath) + + def LinkImportPACS(self): print "TODO: Send Signal - Import DICOM files from PACS" - if evt: - evt.Skip() - def OnLinkOpenProject(self, evt=None, proj_name=""): - if proj_name: - print "TODO: Send Signal - Open project "+ proj_name + def LinkOpenProject(self, filename=None): + if filename: + print "TODO: Send Signal - Open inv3 last project" else: - if sys.platform == 'win32': - path = "" - else: - path = os.getcwd() - dlg = wx.FileDialog(self, message="Open project...", - defaultDir=path, - defaultFile="", wildcard=WILDCARD_OPEN, - style=wx.OPEN|wx.CHANGE_DIR) - if sys.platform != 'darwin': - dlg.SetFilterIndex(2) - else: - dlg.SetFilterIndex(3) - - # Show the dialog and retrieve the user response. If it is the OK response, - # process the data. - if dlg.ShowModal() == wx.ID_OK: - # This returns a Python list of files that were selected. - proj_path = dlg.GetPath() - proj_name = dlg.GetFilename() - ps.Publisher().sendMessage('Open Project', proj_path) - print "TODO: Send Signal - Change frame title "+ proj_name - - # Destroy the dialog. Don't do this until you are done with it! - # BAD things can happen otherwise! - dlg.Destroy() - - if evt: - evt.Skip() + filepath = dlg.ShowOpenProjectDialog() + if filepath: + ps.Publisher().sendMessage('Open Project', filepath) def OnButton(self, evt): id = evt.GetId() if id == BTN_IMPORT_LOCAL: - self.OnLinkImport() + self.LinkImport() elif id == BTN_IMPORT_PACS: - self.OnLinkImportPACS() + self.LinkImportPACS() else: #elif id == BTN_OPEN_PROJECT: - self.OnLinkOpenProject() + self.LinkOpenProject() def TestLoadProjects(self): self.LoadProject("test1.inv3") @@ -235,7 +201,7 @@ class InnerTaskPanel(wx.Panel): proj_link.AutoBrowse(False) proj_link.UpdateLink() proj_link.Bind(hl.EVT_HYPERLINK_LEFT, - lambda e: self.OnLinkOpenProject(e, proj_name)) + lambda e: self.LinkOpenProject(proj_name)) # Add to existing frame self.sizer.Add(proj_link, 1, wx.GROW | wx.EXPAND | wx.ALL, 2) -- libgit2 0.21.2