Commit 74219c06df213d0d52d82bd8b791866bfcc4bf93

Authored by tatiana
1 parent 9f741be9

ADD: Change notebook page based on fold panel

invesalius/gui/data_notebook.py
@@ -28,6 +28,7 @@ import wx.lib.flatnotebook as fnb @@ -28,6 +28,7 @@ import wx.lib.flatnotebook as fnb
28 import wx.lib.platebtn as pbtn 28 import wx.lib.platebtn as pbtn
29 import wx.lib.pubsub as ps 29 import wx.lib.pubsub as ps
30 30
  31 +import constants as const
31 import gui.dialogs as dlg 32 import gui.dialogs as dlg
32 import gui.widgets.listctrl as listmix 33 import gui.widgets.listctrl as listmix
33 import utils as ul 34 import utils as ul
@@ -49,9 +50,9 @@ class NotebookPanel(wx.Panel): @@ -49,9 +50,9 @@ class NotebookPanel(wx.Panel):
49 book.SetWindowVariant(wx.WINDOW_VARIANT_SMALL) 50 book.SetWindowVariant(wx.WINDOW_VARIANT_SMALL)
50 51
51 book.AddPage(MaskPage(book), _("Masks")) 52 book.AddPage(MaskPage(book), _("Masks"))
52 - book.AddPage(SurfacePage(book), _("Surfaces")) 53 + book.AddPage(SurfacePage(book), _("3D Surfaces"))
53 book.AddPage(MeasurePage(book), _("Measures")) 54 book.AddPage(MeasurePage(book), _("Measures"))
54 - #book.AddPage(AnnotationsListCtrlPanel(book), _("Annotations")) 55 + #book.AddPage(AnnotationsListCtrlPanel(book), _("Notes"))
55 56
56 book.SetSelection(0) 57 book.SetSelection(0)
57 58
@@ -60,18 +61,42 @@ class NotebookPanel(wx.Panel): @@ -60,18 +61,42 @@ class NotebookPanel(wx.Panel):
60 self.SetSizer(sizer) 61 self.SetSizer(sizer)
61 62
62 book.Refresh() 63 book.Refresh()
  64 + self.book = book
63 65
64 - #def __bind_events(self):  
65 - # ps.Publisher().subscribe(self._add_measure,  
66 - # "Add measure to list") 66 + self.__bind_events()
67 67
68 - #def _add_measure(self, pubsub_evt):  
69 - # type = pubsub_evt.data[0]  
70 - # value = pubsub_evt.data[1]  
71 - # self.measures_list.AddMeasure(type, value) 68 + def __bind_events(self):
  69 + ps.Publisher().subscribe(self._FoldSurface,
  70 + 'Fold surface task')
  71 + ps.Publisher().subscribe(self._FoldSurface,
  72 + 'Fold surface page')
  73 + ps.Publisher().subscribe(self._FoldMeasure,
  74 + 'Fold measure task')
  75 + ps.Publisher().subscribe(self._FoldMask,
  76 + 'Fold mask task')
  77 + ps.Publisher().subscribe(self._FoldMask,
  78 + 'Fold mask page')
  79 +
  80 +
  81 + def _FoldSurface(self, pubusb_evt):
  82 + """
  83 + Fold surface notebook page.
  84 + """
  85 + self.book.SetSelection(1)
72 86
  87 + def _FoldMeasure(self, pubsub_evt):
  88 + """
  89 + Fold measure notebook page.
  90 + """
  91 + self.book.SetSelection(2)
73 92
74 93
  94 + def _FoldMask(self, pubsub_evt):
  95 + """
  96 + Fold mask notebook page.
  97 + """
  98 + self.book.SetSelection(0)
  99 +
75 class MeasurePage(wx.Panel): 100 class MeasurePage(wx.Panel):
76 """ 101 """
77 Page related to mask items. 102 Page related to mask items.
@@ -123,6 +148,7 @@ class MeasureButtonControlPanel(wx.Panel): @@ -123,6 +148,7 @@ class MeasureButtonControlPanel(wx.Panel):
123 BMP_NEW, 148 BMP_NEW,
124 style=button_style, 149 style=button_style,
125 size = wx.Size(18, 18)) 150 size = wx.Size(18, 18))
  151 + self.button_new = button_new
126 button_remove = pbtn.PlateButton(self, BTN_REMOVE, "", 152 button_remove = pbtn.PlateButton(self, BTN_REMOVE, "",
127 BMP_REMOVE, 153 BMP_REMOVE,
128 style=button_style, 154 style=button_style,
@@ -131,6 +157,7 @@ class MeasureButtonControlPanel(wx.Panel): @@ -131,6 +157,7 @@ class MeasureButtonControlPanel(wx.Panel):
131 BMP_DUPLICATE, 157 BMP_DUPLICATE,
132 style=button_style, 158 style=button_style,
133 size = wx.Size(18, 18)) 159 size = wx.Size(18, 18))
  160 + button_duplicate.Disable()
134 161
135 # Add all controls to gui 162 # Add all controls to gui
136 sizer = wx.BoxSizer(wx.HORIZONTAL) 163 sizer = wx.BoxSizer(wx.HORIZONTAL)
@@ -140,6 +167,16 @@ class MeasureButtonControlPanel(wx.Panel): @@ -140,6 +167,16 @@ class MeasureButtonControlPanel(wx.Panel):
140 self.SetSizer(sizer) 167 self.SetSizer(sizer)
141 self.Fit() 168 self.Fit()
142 169
  170 + menu = wx.Menu()
  171 + item = wx.MenuItem(menu, const.MEASURE_LINEAR,
  172 + _("Measure distance"))
  173 + menu.AppendItem(item)
  174 + item = wx.MenuItem(menu, const.MEASURE_ANGULAR,
  175 + _("Measure angle"))
  176 + menu.AppendItem(item)
  177 + menu.Bind(wx.EVT_MENU, self.OnMenu)
  178 + self.menu = menu
  179 +
143 # Bindings 180 # Bindings
144 self.Bind(wx.EVT_BUTTON, self.OnButton) 181 self.Bind(wx.EVT_BUTTON, self.OnButton)
145 182
@@ -153,12 +190,17 @@ class MeasureButtonControlPanel(wx.Panel): @@ -153,12 +190,17 @@ class MeasureButtonControlPanel(wx.Panel):
153 self.OnDuplicate() 190 self.OnDuplicate()
154 191
155 def OnNew(self): 192 def OnNew(self):
156 - mask_name = dlg.NewMask()  
157 - if mask_name:  
158 - ps.Publisher().sendMessage('Set measurement state', mask_name) 193 + self.PopupMenu(self.menu)
  194 +
  195 + def OnMenu(self, evt):
  196 + id = evt.GetId()
  197 + if id == const.MEASURE_LINEAR:
  198 + ps.Publisher().sendMessage('Set tool linear measure')
  199 + else:
  200 + ps.Publisher().sendMessage('Set tool angular measure')
159 201
160 def OnRemove(self): 202 def OnRemove(self):
161 - self.parent.listctrl.RemoveMasks() 203 + self.parent.listctrl.RemoveMeasurements()
162 204
163 def OnDuplicate(self): 205 def OnDuplicate(self):
164 selected_items = self.parent.listctrl.GetSelected() 206 selected_items = self.parent.listctrl.GetSelected()
@@ -169,6 +211,8 @@ class MeasureButtonControlPanel(wx.Panel): @@ -169,6 +211,8 @@ class MeasureButtonControlPanel(wx.Panel):
169 211
170 212
171 213
  214 +
  215 +
172 class MaskPage(wx.Panel): 216 class MaskPage(wx.Panel):
173 """ 217 """
174 Page related to mask items. 218 Page related to mask items.
@@ -248,9 +292,17 @@ class ButtonControlPanel(wx.Panel): @@ -248,9 +292,17 @@ class ButtonControlPanel(wx.Panel):
248 self.OnDuplicate() 292 self.OnDuplicate()
249 293
250 def OnNew(self): 294 def OnNew(self):
251 - mask_name = dlg.NewMask()  
252 - if mask_name:  
253 - ps.Publisher().sendMessage('Create new mask', mask_name) 295 + dialog = dlg.NewMask()
  296 +
  297 + try:
  298 + answer = dialog.ShowModal()
  299 + except(wx._core.PyAssertionError): #TODO: FIX win64
  300 + answer = wx.ID_YES
  301 +
  302 + if wx.ID_YES:
  303 + mask_name = dialog.GetValue()
  304 + if mask_name:
  305 + ps.Publisher().sendMessage('Create new mask', mask_name)
254 306
255 def OnRemove(self): 307 def OnRemove(self):
256 self.parent.listctrl.RemoveMasks() 308 self.parent.listctrl.RemoveMasks()
@@ -886,7 +938,7 @@ class MeasuresListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): @@ -886,7 +938,7 @@ class MeasuresListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin):
886 938
887 def RemoveMeasurements(self): 939 def RemoveMeasurements(self):
888 """ 940 """
889 - Remove item given its index. 941 + Remove items selected.
890 """ 942 """
891 # it is necessary to update internal dictionary 943 # it is necessary to update internal dictionary
892 # that maps bitmap given item index 944 # that maps bitmap given item index
@@ -906,7 +958,7 @@ class MeasuresListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): @@ -906,7 +958,7 @@ class MeasuresListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin):
906 958
907 ps.Publisher().sendMessage('Remove measurements', selected_items) 959 ps.Publisher().sendMessage('Remove measurements', selected_items)
908 else: 960 else:
909 - dlg.SurfaceSelectionRequiredForRemoval() 961 + dlg.MeasureSelectionRequiredForRemoval()
910 962
911 963
912 def OnCloseProject(self, pubsub_evt): 964 def OnCloseProject(self, pubsub_evt):
@@ -1011,8 +1063,8 @@ class MeasuresListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): @@ -1011,8 +1063,8 @@ class MeasuresListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin):
1011 index = pubsub_evt.data[0] 1063 index = pubsub_evt.data[0]
1012 name = pubsub_evt.data[1] 1064 name = pubsub_evt.data[1]
1013 colour = pubsub_evt.data[2] 1065 colour = pubsub_evt.data[2]
1014 - type_ = pubsub_evt.data[3]  
1015 - location = pubsub_evt.data[4] 1066 + location = pubsub_evt.data[3]
  1067 + type_ = pubsub_evt.data[4]
1016 value = pubsub_evt.data[5] 1068 value = pubsub_evt.data[5]
1017 1069
1018 1070
invesalius/gui/default_tasks.py
@@ -241,7 +241,8 @@ class UpperTaskPanel(wx.Panel): @@ -241,7 +241,8 @@ class UpperTaskPanel(wx.Panel):
241 # slice editor. 241 # slice editor.
242 if name == _("Select region of interest"): 242 if name == _("Select region of interest"):
243 self.__id_slice = item.GetId() 243 self.__id_slice = item.GetId()
244 - 244 + elif name == _("Configure 3D surface"):
  245 + self.__id_surface = item.GetId()
245 246
246 fold_panel.Expand(fold_panel.GetFoldPanel(0)) 247 fold_panel.Expand(fold_panel.GetFoldPanel(0))
247 self.fold_panel = fold_panel 248 self.fold_panel = fold_panel
@@ -287,8 +288,11 @@ class UpperTaskPanel(wx.Panel): @@ -287,8 +288,11 @@ class UpperTaskPanel(wx.Panel):
287 id = evt.GetTag().GetId() 288 id = evt.GetTag().GetId()
288 closed = evt.GetFoldStatus() 289 closed = evt.GetFoldStatus()
289 290
290 - if self.__id_slice == id: 291 + if id == self.__id_slice:
291 ps.Publisher().sendMessage('Retrieve task slice style') 292 ps.Publisher().sendMessage('Retrieve task slice style')
  293 + ps.Publisher().sendMessage('Fold mask page')
  294 + elif id == self.__id_surface:
  295 + ps.Publisher().sendMessage('Fold surface page')
292 else: 296 else:
293 ps.Publisher().sendMessage('Disable task slice style') 297 ps.Publisher().sendMessage('Disable task slice style')
294 298
invesalius/gui/frame.py
@@ -783,8 +783,8 @@ class ObjectToolBar(wx.ToolBar): @@ -783,8 +783,8 @@ class ObjectToolBar(wx.ToolBar):
783 const.STATE_SPIN, const.STATE_ZOOM_SL, 783 const.STATE_SPIN, const.STATE_ZOOM_SL,
784 const.STATE_ZOOM, 784 const.STATE_ZOOM,
785 const.STATE_MEASURE_DISTANCE, 785 const.STATE_MEASURE_DISTANCE,
786 - const.STATE_MEASURE_ANGLE,  
787 - const.STATE_ANNOTATE] 786 + const.STATE_MEASURE_ANGLE,]
  787 + #const.STATE_ANNOTATE]
788 self.__init_items() 788 self.__init_items()
789 self.__bind_events() 789 self.__bind_events()
790 self.__bind_events_wx() 790 self.__bind_events_wx()
@@ -799,7 +799,8 @@ class ObjectToolBar(wx.ToolBar): @@ -799,7 +799,8 @@ class ObjectToolBar(wx.ToolBar):
799 sub = ps.Publisher().subscribe 799 sub = ps.Publisher().subscribe
800 sub(self._EnableState, "Enable state project") 800 sub(self._EnableState, "Enable state project")
801 sub(self._UntoggleAllItems, 'Untoggle object toolbar items') 801 sub(self._UntoggleAllItems, 'Untoggle object toolbar items')
802 - 802 + sub(self._ToggleLinearMeasure, "Set tool linear measure")
  803 + sub(self._ToggleAngularMeasure, "Set tool angular measure")
803 804
804 def __bind_events_wx(self): 805 def __bind_events_wx(self):
805 """ 806 """
@@ -834,8 +835,8 @@ class ObjectToolBar(wx.ToolBar): @@ -834,8 +835,8 @@ class ObjectToolBar(wx.ToolBar):
834 path = os.path.join(d, "measure_angle_original.png") 835 path = os.path.join(d, "measure_angle_original.png")
835 BMP_ANGLE = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) 836 BMP_ANGLE = wx.Bitmap(path, wx.BITMAP_TYPE_PNG)
836 837
837 - path = os.path.join(d, "tool_annotation_original.png")  
838 - BMP_ANNOTATE = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) 838 + #path = os.path.join(d, "tool_annotation_original.png")
  839 + #BMP_ANNOTATE = wx.Bitmap(path, wx.BITMAP_TYPE_PNG)
839 840
840 else: 841 else:
841 path = os.path.join(d, "tool_rotate.gif") 842 path = os.path.join(d, "tool_rotate.gif")
@@ -859,8 +860,8 @@ class ObjectToolBar(wx.ToolBar): @@ -859,8 +860,8 @@ class ObjectToolBar(wx.ToolBar):
859 path = os.path.join(d, "measure_angle.png") 860 path = os.path.join(d, "measure_angle.png")
860 BMP_ANGLE = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) 861 BMP_ANGLE = wx.Bitmap(path, wx.BITMAP_TYPE_PNG)
861 862
862 - path = os.path.join(d, "tool_annotation.png")  
863 - BMP_ANNOTATE = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) 863 + #path = os.path.join(d, "tool_annotation.png")
  864 + #BMP_ANNOTATE = wx.Bitmap(path, wx.BITMAP_TYPE_PNG)
864 865
865 # Create tool items based on bitmaps 866 # Create tool items based on bitmaps
866 self.AddLabelTool(const.STATE_ZOOM, 867 self.AddLabelTool(const.STATE_ZOOM,
@@ -898,11 +899,11 @@ class ObjectToolBar(wx.ToolBar): @@ -898,11 +899,11 @@ class ObjectToolBar(wx.ToolBar):
898 shortHelp = _("Measure angle"), 899 shortHelp = _("Measure angle"),
899 bitmap = BMP_ANGLE, 900 bitmap = BMP_ANGLE,
900 kind = wx.ITEM_CHECK) 901 kind = wx.ITEM_CHECK)
901 - self.AddLabelTool(const.STATE_ANNOTATE,  
902 - "",  
903 - shortHelp = _("Add annotation"),  
904 - bitmap = BMP_ANNOTATE,  
905 - kind = wx.ITEM_CHECK) 902 + #self.AddLabelTool(const.STATE_ANNOTATE,
  903 + # "",
  904 + # shortHelp = _("Add annotation"),
  905 + # bitmap = BMP_ANNOTATE,
  906 + # kind = wx.ITEM_CHECK)
906 907
907 def _EnableState(self, pubsub_evt): 908 def _EnableState(self, pubsub_evt):
908 """ 909 """
@@ -924,6 +925,35 @@ class ObjectToolBar(wx.ToolBar): @@ -924,6 +925,35 @@ class ObjectToolBar(wx.ToolBar):
924 if state: 925 if state:
925 self.ToggleTool(id, False) 926 self.ToggleTool(id, False)
926 927
  928 + def _ToggleLinearMeasure(self, pubsub_evt):
  929 + """
  930 + Force measure distance tool to be toggled and bind pubsub
  931 + events to other classes whici are interested on this.
  932 + """
  933 + id = const.STATE_MEASURE_DISTANCE
  934 + self.ToggleTool(id, True)
  935 + ps.Publisher().sendMessage('Enable style', id)
  936 + ps.Publisher().sendMessage('Untoggle slice toolbar items')
  937 + for item in const.TOOL_STATES:
  938 + state = self.GetToolState(item)
  939 + if state and (item != id):
  940 + self.ToggleTool(item, False)
  941 +
  942 +
  943 + def _ToggleAngularMeasure(self, pubsub_evt):
  944 + """
  945 + Force measure angle tool to be toggled and bind pubsub
  946 + events to other classes which are interested on this.
  947 + """
  948 + id = const.STATE_MEASURE_ANGLE
  949 + self.ToggleTool(id, True)
  950 + ps.Publisher().sendMessage('Enable style', id)
  951 + ps.Publisher().sendMessage('Untoggle slice toolbar items')
  952 + for item in const.TOOL_STATES:
  953 + state = self.GetToolState(item)
  954 + if state and (item != id):
  955 + self.ToggleTool(item, False)
  956 +
927 def OnToggle(self, evt): 957 def OnToggle(self, evt):
928 """ 958 """
929 Update status of other items on toolbar (only one item 959 Update status of other items on toolbar (only one item
@@ -931,6 +961,10 @@ class ObjectToolBar(wx.ToolBar): @@ -931,6 +961,10 @@ class ObjectToolBar(wx.ToolBar):
931 """ 961 """
932 id = evt.GetId() 962 id = evt.GetId()
933 state = self.GetToolState(id) 963 state = self.GetToolState(id)
  964 + if state and ((id == const.STATE_MEASURE_DISTANCE) or\
  965 + (id == const.STATE_MEASURE_ANGLE)):
  966 + ps.Publisher().sendMessage('Fold measure task')
  967 +
934 if state: 968 if state:
935 ps.Publisher().sendMessage('Enable style', id) 969 ps.Publisher().sendMessage('Enable style', id)
936 ps.Publisher().sendMessage('Untoggle slice toolbar items') 970 ps.Publisher().sendMessage('Untoggle slice toolbar items')
@@ -1009,7 +1043,7 @@ class SliceToolBar(wx.ToolBar): @@ -1009,7 +1043,7 @@ class SliceToolBar(wx.ToolBar):
1009 1043
1010 self.AddCheckTool(const.SLICE_STATE_CROSS, 1044 self.AddCheckTool(const.SLICE_STATE_CROSS,
1011 BMP_CROSS, 1045 BMP_CROSS,
1012 - shortHelp = _("Cross intersection")) 1046 + shortHelp = _("Slices' cross intersection"))
1013 1047
1014 def __bind_events(self): 1048 def __bind_events(self):
1015 """ 1049 """