From 74219c06df213d0d52d82bd8b791866bfcc4bf93 Mon Sep 17 00:00:00 2001 From: tatiana Date: Fri, 5 Mar 2010 01:30:26 +0000 Subject: [PATCH] ADD: Change notebook page based on fold panel --- invesalius/gui/data_notebook.py | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------- invesalius/gui/default_tasks.py | 8 ++++++-- invesalius/gui/frame.py | 60 +++++++++++++++++++++++++++++++++++++++++++++++------------- 3 files changed, 125 insertions(+), 35 deletions(-) diff --git a/invesalius/gui/data_notebook.py b/invesalius/gui/data_notebook.py index 81332b6..b612953 100644 --- a/invesalius/gui/data_notebook.py +++ b/invesalius/gui/data_notebook.py @@ -28,6 +28,7 @@ import wx.lib.flatnotebook as fnb import wx.lib.platebtn as pbtn import wx.lib.pubsub as ps +import constants as const import gui.dialogs as dlg import gui.widgets.listctrl as listmix import utils as ul @@ -49,9 +50,9 @@ class NotebookPanel(wx.Panel): book.SetWindowVariant(wx.WINDOW_VARIANT_SMALL) book.AddPage(MaskPage(book), _("Masks")) - book.AddPage(SurfacePage(book), _("Surfaces")) + book.AddPage(SurfacePage(book), _("3D Surfaces")) book.AddPage(MeasurePage(book), _("Measures")) - #book.AddPage(AnnotationsListCtrlPanel(book), _("Annotations")) + #book.AddPage(AnnotationsListCtrlPanel(book), _("Notes")) book.SetSelection(0) @@ -60,18 +61,42 @@ class NotebookPanel(wx.Panel): self.SetSizer(sizer) book.Refresh() + self.book = book - #def __bind_events(self): - # ps.Publisher().subscribe(self._add_measure, - # "Add measure to list") + self.__bind_events() - #def _add_measure(self, pubsub_evt): - # type = pubsub_evt.data[0] - # value = pubsub_evt.data[1] - # self.measures_list.AddMeasure(type, value) + def __bind_events(self): + ps.Publisher().subscribe(self._FoldSurface, + 'Fold surface task') + ps.Publisher().subscribe(self._FoldSurface, + 'Fold surface page') + ps.Publisher().subscribe(self._FoldMeasure, + 'Fold measure task') + ps.Publisher().subscribe(self._FoldMask, + 'Fold mask task') + ps.Publisher().subscribe(self._FoldMask, + 'Fold mask page') + + + def _FoldSurface(self, pubusb_evt): + """ + Fold surface notebook page. + """ + self.book.SetSelection(1) + def _FoldMeasure(self, pubsub_evt): + """ + Fold measure notebook page. + """ + self.book.SetSelection(2) + def _FoldMask(self, pubsub_evt): + """ + Fold mask notebook page. + """ + self.book.SetSelection(0) + class MeasurePage(wx.Panel): """ Page related to mask items. @@ -123,6 +148,7 @@ class MeasureButtonControlPanel(wx.Panel): BMP_NEW, style=button_style, size = wx.Size(18, 18)) + self.button_new = button_new button_remove = pbtn.PlateButton(self, BTN_REMOVE, "", BMP_REMOVE, style=button_style, @@ -131,6 +157,7 @@ class MeasureButtonControlPanel(wx.Panel): BMP_DUPLICATE, style=button_style, size = wx.Size(18, 18)) + button_duplicate.Disable() # Add all controls to gui sizer = wx.BoxSizer(wx.HORIZONTAL) @@ -140,6 +167,16 @@ class MeasureButtonControlPanel(wx.Panel): self.SetSizer(sizer) self.Fit() + menu = wx.Menu() + item = wx.MenuItem(menu, const.MEASURE_LINEAR, + _("Measure distance")) + menu.AppendItem(item) + item = wx.MenuItem(menu, const.MEASURE_ANGULAR, + _("Measure angle")) + menu.AppendItem(item) + menu.Bind(wx.EVT_MENU, self.OnMenu) + self.menu = menu + # Bindings self.Bind(wx.EVT_BUTTON, self.OnButton) @@ -153,12 +190,17 @@ class MeasureButtonControlPanel(wx.Panel): self.OnDuplicate() def OnNew(self): - mask_name = dlg.NewMask() - if mask_name: - ps.Publisher().sendMessage('Set measurement state', mask_name) + self.PopupMenu(self.menu) + + def OnMenu(self, evt): + id = evt.GetId() + if id == const.MEASURE_LINEAR: + ps.Publisher().sendMessage('Set tool linear measure') + else: + ps.Publisher().sendMessage('Set tool angular measure') def OnRemove(self): - self.parent.listctrl.RemoveMasks() + self.parent.listctrl.RemoveMeasurements() def OnDuplicate(self): selected_items = self.parent.listctrl.GetSelected() @@ -169,6 +211,8 @@ class MeasureButtonControlPanel(wx.Panel): + + class MaskPage(wx.Panel): """ Page related to mask items. @@ -248,9 +292,17 @@ class ButtonControlPanel(wx.Panel): self.OnDuplicate() def OnNew(self): - mask_name = dlg.NewMask() - if mask_name: - ps.Publisher().sendMessage('Create new mask', mask_name) + dialog = dlg.NewMask() + + try: + answer = dialog.ShowModal() + except(wx._core.PyAssertionError): #TODO: FIX win64 + answer = wx.ID_YES + + if wx.ID_YES: + mask_name = dialog.GetValue() + if mask_name: + ps.Publisher().sendMessage('Create new mask', mask_name) def OnRemove(self): self.parent.listctrl.RemoveMasks() @@ -886,7 +938,7 @@ class MeasuresListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): def RemoveMeasurements(self): """ - Remove item given its index. + Remove items selected. """ # it is necessary to update internal dictionary # that maps bitmap given item index @@ -906,7 +958,7 @@ class MeasuresListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): ps.Publisher().sendMessage('Remove measurements', selected_items) else: - dlg.SurfaceSelectionRequiredForRemoval() + dlg.MeasureSelectionRequiredForRemoval() def OnCloseProject(self, pubsub_evt): @@ -1011,8 +1063,8 @@ class MeasuresListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): index = pubsub_evt.data[0] name = pubsub_evt.data[1] colour = pubsub_evt.data[2] - type_ = pubsub_evt.data[3] - location = pubsub_evt.data[4] + location = pubsub_evt.data[3] + type_ = pubsub_evt.data[4] value = pubsub_evt.data[5] diff --git a/invesalius/gui/default_tasks.py b/invesalius/gui/default_tasks.py index 26b6d25..de453e6 100755 --- a/invesalius/gui/default_tasks.py +++ b/invesalius/gui/default_tasks.py @@ -241,7 +241,8 @@ class UpperTaskPanel(wx.Panel): # slice editor. if name == _("Select region of interest"): self.__id_slice = item.GetId() - + elif name == _("Configure 3D surface"): + self.__id_surface = item.GetId() fold_panel.Expand(fold_panel.GetFoldPanel(0)) self.fold_panel = fold_panel @@ -287,8 +288,11 @@ class UpperTaskPanel(wx.Panel): id = evt.GetTag().GetId() closed = evt.GetFoldStatus() - if self.__id_slice == id: + if id == self.__id_slice: ps.Publisher().sendMessage('Retrieve task slice style') + ps.Publisher().sendMessage('Fold mask page') + elif id == self.__id_surface: + ps.Publisher().sendMessage('Fold surface page') else: ps.Publisher().sendMessage('Disable task slice style') diff --git a/invesalius/gui/frame.py b/invesalius/gui/frame.py index 7b6adca..df7abd1 100755 --- a/invesalius/gui/frame.py +++ b/invesalius/gui/frame.py @@ -783,8 +783,8 @@ class ObjectToolBar(wx.ToolBar): const.STATE_SPIN, const.STATE_ZOOM_SL, const.STATE_ZOOM, const.STATE_MEASURE_DISTANCE, - const.STATE_MEASURE_ANGLE, - const.STATE_ANNOTATE] + const.STATE_MEASURE_ANGLE,] + #const.STATE_ANNOTATE] self.__init_items() self.__bind_events() self.__bind_events_wx() @@ -799,7 +799,8 @@ class ObjectToolBar(wx.ToolBar): sub = ps.Publisher().subscribe sub(self._EnableState, "Enable state project") sub(self._UntoggleAllItems, 'Untoggle object toolbar items') - + sub(self._ToggleLinearMeasure, "Set tool linear measure") + sub(self._ToggleAngularMeasure, "Set tool angular measure") def __bind_events_wx(self): """ @@ -834,8 +835,8 @@ class ObjectToolBar(wx.ToolBar): path = os.path.join(d, "measure_angle_original.png") BMP_ANGLE = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) - path = os.path.join(d, "tool_annotation_original.png") - BMP_ANNOTATE = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) + #path = os.path.join(d, "tool_annotation_original.png") + #BMP_ANNOTATE = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) else: path = os.path.join(d, "tool_rotate.gif") @@ -859,8 +860,8 @@ class ObjectToolBar(wx.ToolBar): path = os.path.join(d, "measure_angle.png") BMP_ANGLE = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) - path = os.path.join(d, "tool_annotation.png") - BMP_ANNOTATE = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) + #path = os.path.join(d, "tool_annotation.png") + #BMP_ANNOTATE = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) # Create tool items based on bitmaps self.AddLabelTool(const.STATE_ZOOM, @@ -898,11 +899,11 @@ class ObjectToolBar(wx.ToolBar): shortHelp = _("Measure angle"), bitmap = BMP_ANGLE, kind = wx.ITEM_CHECK) - self.AddLabelTool(const.STATE_ANNOTATE, - "", - shortHelp = _("Add annotation"), - bitmap = BMP_ANNOTATE, - kind = wx.ITEM_CHECK) + #self.AddLabelTool(const.STATE_ANNOTATE, + # "", + # shortHelp = _("Add annotation"), + # bitmap = BMP_ANNOTATE, + # kind = wx.ITEM_CHECK) def _EnableState(self, pubsub_evt): """ @@ -924,6 +925,35 @@ class ObjectToolBar(wx.ToolBar): if state: self.ToggleTool(id, False) + def _ToggleLinearMeasure(self, pubsub_evt): + """ + Force measure distance tool to be toggled and bind pubsub + events to other classes whici are interested on this. + """ + id = const.STATE_MEASURE_DISTANCE + self.ToggleTool(id, True) + ps.Publisher().sendMessage('Enable style', id) + ps.Publisher().sendMessage('Untoggle slice toolbar items') + for item in const.TOOL_STATES: + state = self.GetToolState(item) + if state and (item != id): + self.ToggleTool(item, False) + + + def _ToggleAngularMeasure(self, pubsub_evt): + """ + Force measure angle tool to be toggled and bind pubsub + events to other classes which are interested on this. + """ + id = const.STATE_MEASURE_ANGLE + self.ToggleTool(id, True) + ps.Publisher().sendMessage('Enable style', id) + ps.Publisher().sendMessage('Untoggle slice toolbar items') + for item in const.TOOL_STATES: + state = self.GetToolState(item) + if state and (item != id): + self.ToggleTool(item, False) + def OnToggle(self, evt): """ Update status of other items on toolbar (only one item @@ -931,6 +961,10 @@ class ObjectToolBar(wx.ToolBar): """ id = evt.GetId() state = self.GetToolState(id) + if state and ((id == const.STATE_MEASURE_DISTANCE) or\ + (id == const.STATE_MEASURE_ANGLE)): + ps.Publisher().sendMessage('Fold measure task') + if state: ps.Publisher().sendMessage('Enable style', id) ps.Publisher().sendMessage('Untoggle slice toolbar items') @@ -1009,7 +1043,7 @@ class SliceToolBar(wx.ToolBar): self.AddCheckTool(const.SLICE_STATE_CROSS, BMP_CROSS, - shortHelp = _("Cross intersection")) + shortHelp = _("Slices' cross intersection")) def __bind_events(self): """ -- libgit2 0.21.2