Commit b6796f8a106bdafd022d4c151c76d42c8f20711d
1 parent
afe704d3
Exists in
master
and in
6 other branches
FIX: Enable/disable items as project is open/close (fix #88)
Showing
5 changed files
with
180 additions
and
9 deletions
Show diff stats
invesalius/constants.py
... | ... | @@ -199,10 +199,10 @@ SURFACE_QUALITY = { |
199 | 199 | _("Low"): (3, 2, 0.3000, 0.4), |
200 | 200 | _("Medium"): (2, 2, 0.3000, 0.4), |
201 | 201 | _("High"): (0, 1, 0.3000, 0.1), |
202 | - _("Optimal *"): (0, 2, 0.3000, 0.4), | |
203 | - _("Custom"): (None, None, None, None)} | |
202 | + _("Optimal *"): (0, 2, 0.3000, 0.4)} | |
204 | 203 | DEFAULT_SURFACE_QUALITY = _("Optimal *") |
205 | 204 | |
205 | + | |
206 | 206 | # Surface properties |
207 | 207 | SURFACE_TRANSPARENCY = 0.0 |
208 | 208 | SURFACE_NAME_PATTERN = _("Surface %d") | ... | ... |
invesalius/control.py
... | ... | @@ -160,14 +160,17 @@ class Controller(): |
160 | 160 | if not answer: |
161 | 161 | print "Close without changes" |
162 | 162 | self.CloseProject() |
163 | + ps.Publisher().sendMessage("Enable state project", False) | |
163 | 164 | elif answer == 1: |
164 | 165 | self.ShowDialogSaveProject() |
165 | 166 | print "Save changes and close" |
166 | 167 | self.CloseProject() |
168 | + ps.Publisher().sendMessage("Enable state project", False) | |
167 | 169 | elif answer == -1: |
168 | 170 | print "Cancel" |
169 | 171 | else: |
170 | 172 | self.CloseProject() |
173 | + ps.Publisher().sendMessage("Enable state project", False) | |
171 | 174 | |
172 | 175 | ########################### |
173 | 176 | def OnOpenProject(self, pubsub_evt): |
... | ... | @@ -193,6 +196,7 @@ class Controller(): |
193 | 196 | |
194 | 197 | session = ses.Session() |
195 | 198 | session.OpenProject(filepath) |
199 | + ps.Publisher().sendMessage("Enable state project", True) | |
196 | 200 | |
197 | 201 | def SaveProject(self, path=None): |
198 | 202 | ps.Publisher().sendMessage('Begin busy cursor') |
... | ... | @@ -289,6 +293,7 @@ class Controller(): |
289 | 293 | print "No medical images found on given directory" |
290 | 294 | return |
291 | 295 | self.LoadProject() |
296 | + ps.Publisher().sendMessage("Enable state project", True) | |
292 | 297 | |
293 | 298 | def LoadProject(self): |
294 | 299 | proj = prj.Project() |
... | ... | @@ -361,6 +366,7 @@ class Controller(): |
361 | 366 | imagedata, dicom = self.OpenDicomGroup(group, gui=True) |
362 | 367 | self.CreateDicomProject(imagedata, dicom) |
363 | 368 | self.LoadProject() |
369 | + ps.Publisher().sendMessage("Enable state project", True) | |
364 | 370 | |
365 | 371 | def OpenDicomGroup(self, dicom_group, gui=True): |
366 | 372 | ... | ... |
invesalius/gui/default_tasks.py
... | ... | @@ -117,6 +117,8 @@ class LowerTaskPanel(wx.Panel): |
117 | 117 | self.GetSize(),fpb.FPB_DEFAULT_STYLE, |
118 | 118 | fpb.FPB_COLLAPSE_TO_BOTTOM) |
119 | 119 | |
120 | + self.enable_items = [] | |
121 | + | |
120 | 122 | sizer = wx.BoxSizer(wx.VERTICAL) |
121 | 123 | sizer.Add(fold_panel, 1, wx.GROW|wx.EXPAND) |
122 | 124 | self.SetSizer(sizer) |
... | ... | @@ -130,6 +132,7 @@ class LowerTaskPanel(wx.Panel): |
130 | 132 | foldIcons=image_list) |
131 | 133 | style = fold_panel.GetCaptionStyle(item) |
132 | 134 | col = style.GetFirstColour() |
135 | + self.enable_items.append(item) | |
133 | 136 | |
134 | 137 | fold_panel.AddFoldPanelWindow(item, nb.NotebookPanel(item), Spacing= 0, |
135 | 138 | leftSpacing=0, rightSpacing=0) |
... | ... | @@ -142,11 +145,35 @@ class LowerTaskPanel(wx.Panel): |
142 | 145 | # foldIcons=image_list) |
143 | 146 | #style = fold_panel.GetCaptionStyle(item) |
144 | 147 | #col = style.GetFirstColour() |
148 | + #self.enable_items.append(item) | |
145 | 149 | # |
146 | 150 | #fold_panel.AddFoldPanelWindow(item, tools.TaskPanel(item), Spacing= 0, |
147 | 151 | # leftSpacing=0, rightSpacing=0) |
148 | 152 | #fold_panel.Expand(fold_panel.GetFoldPanel(1)) |
149 | 153 | |
154 | + self.SetStateProjectClose() | |
155 | + self.__bind_events() | |
156 | + | |
157 | + | |
158 | + def __bind_events(self): | |
159 | + ps.Publisher().subscribe(self.OnEnableState, "Enable state project") | |
160 | + | |
161 | + def OnEnableState(self, pubsub_evt): | |
162 | + state = pubsub_evt.data | |
163 | + if state: | |
164 | + self.SetStateProjectOpen() | |
165 | + else: | |
166 | + self.SetStateProjectClose() | |
167 | + | |
168 | + def SetStateProjectClose(self): | |
169 | + for item in self.enable_items: | |
170 | + item.Disable() | |
171 | + | |
172 | + def SetStateProjectOpen(self): | |
173 | + for item in self.enable_items: | |
174 | + item.Enable() | |
175 | + | |
176 | + | |
150 | 177 | # Upper fold panel |
151 | 178 | class UpperTaskPanel(wx.Panel): |
152 | 179 | def __init__(self, parent): |
... | ... | @@ -169,6 +196,9 @@ class UpperTaskPanel(wx.Panel): |
169 | 196 | image_list.Add(GetExpandedIconBitmap()) |
170 | 197 | image_list.Add(GetCollapsedIconBitmap()) |
171 | 198 | |
199 | + | |
200 | + self.enable_items = [] | |
201 | + | |
172 | 202 | # Fold 1 - Import |
173 | 203 | |
174 | 204 | item = fold_panel.AddFoldPanel(_("1. InVesalius start"), collapsed=True, |
... | ... | @@ -186,6 +216,10 @@ class UpperTaskPanel(wx.Panel): |
186 | 216 | |
187 | 217 | item = fold_panel.AddFoldPanel(_("2. Select region of interest"), |
188 | 218 | collapsed=True, foldIcons=image_list) |
219 | + | |
220 | + | |
221 | + self.enable_items.append(item) | |
222 | + | |
189 | 223 | style = fold_panel.GetCaptionStyle(item) |
190 | 224 | col = style.GetFirstColour() |
191 | 225 | slice_panel = slice_.TaskPanel(item) |
... | ... | @@ -210,21 +244,44 @@ class UpperTaskPanel(wx.Panel): |
210 | 244 | Spacing= 0, leftSpacing=0, rightSpacing=0) |
211 | 245 | #fold_panel.Expand(fold_panel.GetFoldPanel(2)) |
212 | 246 | |
247 | + self.enable_items.append(item) | |
248 | + | |
249 | + | |
213 | 250 | # Fold 4 |
214 | 251 | # Export volume |
215 | 252 | item = fold_panel.AddFoldPanel(_("4. Export data"), collapsed=True, |
216 | 253 | foldIcons=image_list) |
217 | 254 | style = fold_panel.GetCaptionStyle(item) |
218 | 255 | col = style.GetFirstColour() |
219 | - | |
256 | + self.enable_items.append(item) | |
257 | + | |
220 | 258 | fold_panel.AddFoldPanelWindow(item, exporter.TaskPanel(item), |
221 | 259 | Spacing= 0, leftSpacing=0, rightSpacing=0) |
222 | 260 | |
223 | 261 | self.fold_panel = fold_panel |
224 | - self.__bind_evt() | |
225 | 262 | |
226 | - def __bind_evt(self): | |
263 | + self.SetStateProjectClose() | |
264 | + self.__bind_events() | |
265 | + | |
266 | + | |
267 | + def __bind_events(self): | |
227 | 268 | self.fold_panel.Bind(fpb.EVT_CAPTIONBAR, self.OnFoldPressCaption) |
269 | + ps.Publisher().subscribe(self.OnEnableState, "Enable state project") | |
270 | + | |
271 | + def OnEnableState(self, pubsub_evt): | |
272 | + state = pubsub_evt.data | |
273 | + if state: | |
274 | + self.SetStateProjectOpen() | |
275 | + else: | |
276 | + self.SetStateProjectClose() | |
277 | + | |
278 | + def SetStateProjectClose(self): | |
279 | + for item in self.enable_items: | |
280 | + item.Disable() | |
281 | + | |
282 | + def SetStateProjectOpen(self): | |
283 | + for item in self.enable_items: | |
284 | + item.Enable() | |
228 | 285 | |
229 | 286 | def OnFoldPressCaption(self, evt): |
230 | 287 | id = evt.GetTag().GetId() | ... | ... |
invesalius/gui/frame.py
... | ... | @@ -376,12 +376,37 @@ class MenuBar(wx.MenuBar): |
376 | 376 | #self.Append(options_menu, "Options") |
377 | 377 | self.Append(help_menu, _("Help")) |
378 | 378 | |
379 | + | |
380 | + self.enable_items = [const.ID_PROJECT_SAVE, const.ID_PROJECT_SAVE_AS, | |
381 | + const.ID_PROJECT_CLOSE] | |
382 | + | |
383 | + self.SetStateProjectClose() | |
384 | + | |
385 | + def OnEnableState(self, pubsub_evt): | |
386 | + print "----- OnEnableState" | |
387 | + state = pubsub_evt.data | |
388 | + print "state", state | |
389 | + if state: | |
390 | + self.SetStateProjectOpen() | |
391 | + else: | |
392 | + self.SetStateProjectClose() | |
393 | + | |
394 | + | |
395 | + def SetStateProjectOpen(self): | |
396 | + for item in self.enable_items: | |
397 | + self.Enable(item, True) | |
398 | + | |
399 | + def SetStateProjectClose(self): | |
400 | + for item in self.enable_items: | |
401 | + self.Enable(item, False) | |
402 | + | |
379 | 403 | def __bind_events(self): |
380 | 404 | # TODO: in future, possibly when wxPython 2.9 is available, |
381 | 405 | # events should be binded directly from wx.Menu / wx.MenuBar |
382 | 406 | # message "Binding events of wx.MenuBar" on [wxpython-users] |
383 | 407 | # mail list in Oct 20 2008 |
384 | - pass | |
408 | + ps.Publisher().subscribe(self.OnEnableState, "Enable state project") | |
409 | + | |
385 | 410 | |
386 | 411 | # ------------------------------------------------------------------ |
387 | 412 | class ProgressBar(wx.Gauge): |
... | ... | @@ -480,7 +505,6 @@ class ProjectToolBar(wx.ToolBar): |
480 | 505 | self.SetToolBitmapSize(wx.Size(32,32)) |
481 | 506 | |
482 | 507 | self.parent = parent |
483 | - | |
484 | 508 | self.__init_items() |
485 | 509 | self.__bind_events() |
486 | 510 | |
... | ... | @@ -540,11 +564,29 @@ class ProjectToolBar(wx.ToolBar): |
540 | 564 | #self.AddLabelTool(const.ID_PRINT_SCREENSHOT, |
541 | 565 | # "Print medical image...", |
542 | 566 | # BMP_PRINT) |
567 | + self.enable_items = [const.ID_PROJECT_SAVE] | |
543 | 568 | |
544 | 569 | self.Realize() |
570 | + self.SetStateProjectClose() | |
571 | + | |
572 | + def SetStateProjectOpen(self): | |
573 | + for tool in self.enable_items: | |
574 | + self.EnableTool(tool, True) | |
575 | + | |
576 | + def SetStateProjectClose(self): | |
577 | + for tool in self.enable_items: | |
578 | + self.EnableTool(tool, False) | |
579 | + | |
580 | + def OnEnableState(self, pubsub_evt): | |
581 | + state = pubsub_evt.data | |
582 | + if state: | |
583 | + self.SetStateProjectOpen() | |
584 | + else: | |
585 | + self.SetStateProjectClose() | |
545 | 586 | |
546 | 587 | def __bind_events(self): |
547 | - pass | |
588 | + ps.Publisher().subscribe(self.OnEnableState, "Enable state project") | |
589 | + | |
548 | 590 | #self.Bind(wx.EVT_TOOL, self.OnToolSave, id=const.ID_PROJECT_SAVE) |
549 | 591 | #self.Bind(wx.EVT_TOOL, self.OnToolOpen, id=const.ID_PROJECT_OPEN) |
550 | 592 | #self.Bind(wx.EVT_TOOL, self.OnToolImport, id=const.ID_DICOM_IMPORT) |
... | ... | @@ -647,7 +689,30 @@ class ObjectToolBar(wx.ToolBar): |
647 | 689 | self.AddLabelTool(const.STATE_WL, |
648 | 690 | _("Window and Level"), BMP_CONTRAST, |
649 | 691 | kind = wx.ITEM_CHECK) |
692 | + | |
693 | + self.enable_items = [const.STATE_WL, const.STATE_PAN, const.STATE_SPIN, | |
694 | + const.STATE_ZOOM_SL, const.STATE_ZOOM,] | |
695 | + | |
650 | 696 | self.Realize() |
697 | + self.SetStateProjectClose() | |
698 | + | |
699 | + | |
700 | + def OnEnableState(self, pubsub_evt): | |
701 | + state = pubsub_evt.data | |
702 | + if state: | |
703 | + self.SetStateProjectOpen() | |
704 | + else: | |
705 | + self.SetStateProjectClose() | |
706 | + | |
707 | + | |
708 | + | |
709 | + def SetStateProjectOpen(self): | |
710 | + for tool in self.enable_items: | |
711 | + self.EnableTool(tool, True) | |
712 | + | |
713 | + def SetStateProjectClose(self): | |
714 | + for tool in self.enable_items: | |
715 | + self.EnableTool(tool, False) | |
651 | 716 | |
652 | 717 | |
653 | 718 | def __bind_events_wx(self): |
... | ... | @@ -656,6 +721,8 @@ class ObjectToolBar(wx.ToolBar): |
656 | 721 | def __bind_events(self): |
657 | 722 | ps.Publisher().subscribe(self.UntoggleAllItems, |
658 | 723 | 'Untoggle object toolbar items') |
724 | + ps.Publisher().subscribe(self.OnEnableState, "Enable state project") | |
725 | + | |
659 | 726 | |
660 | 727 | def OnToggle(self, evt): |
661 | 728 | id = evt.GetId() |
... | ... | @@ -714,14 +781,33 @@ class SliceToolBar(wx.ToolBar): |
714 | 781 | self.AddCheckTool(const.SLICE_STATE_SCROLL, BMP_SLICE) |
715 | 782 | self.AddCheckTool(const.SLICE_STATE_CROSS, BMP_CROSS) |
716 | 783 | |
784 | + self.enable_items = [const.SLICE_STATE_SCROLL, const.SLICE_STATE_CROSS,] | |
717 | 785 | self.Realize() |
786 | + self.SetStateProjectClose() | |
787 | + | |
788 | + def SetStateProjectOpen(self): | |
789 | + for tool in self.enable_items: | |
790 | + self.EnableTool(tool, True) | |
718 | 791 | |
792 | + def SetStateProjectClose(self): | |
793 | + for tool in self.enable_items: | |
794 | + self.EnableTool(tool, False) | |
795 | + | |
719 | 796 | def __bind_events_wx(self): |
720 | 797 | self.Bind(wx.EVT_TOOL, self.OnClick) |
721 | 798 | |
722 | 799 | def __bind_events(self): |
723 | 800 | ps.Publisher().subscribe(self.UntoggleAllItem, |
724 | 801 | 'Untoggle slice toolbar items') |
802 | + ps.Publisher().subscribe(self.OnEnableState, "Enable state project") | |
803 | + | |
804 | + def OnEnableState(self, pubsub_evt): | |
805 | + state = pubsub_evt.data | |
806 | + if state: | |
807 | + self.SetStateProjectOpen() | |
808 | + else: | |
809 | + self.SetStateProjectClose() | |
810 | + | |
725 | 811 | |
726 | 812 | def OnClick(self, evt): |
727 | 813 | id = evt.GetId() |
... | ... | @@ -793,7 +879,19 @@ class LayoutToolBar(wx.ToolBar): |
793 | 879 | self.AddCheckTool(ID_TEXT, bitmap=BMP_TEXT, shortHelp= "Hide texts") |
794 | 880 | self.ToggleTool(ID_TEXT, True) |
795 | 881 | |
882 | + self.enable_items = [ID_TEXT] | |
796 | 883 | self.Realize() |
884 | + self.SetStateProjectClose() | |
885 | + | |
886 | + def SetStateProjectOpen(self): | |
887 | + for tool in self.enable_items: | |
888 | + self.EnableTool(tool, True) | |
889 | + | |
890 | + def SetStateProjectClose(self): | |
891 | + for tool in self.enable_items: | |
892 | + self.EnableTool(tool, False) | |
893 | + | |
894 | + | |
797 | 895 | |
798 | 896 | def __bind_events(self): |
799 | 897 | ps.Publisher().subscribe(self.SetLayoutButtonOnlyData, |
... | ... | @@ -801,6 +899,17 @@ class LayoutToolBar(wx.ToolBar): |
801 | 899 | ps.Publisher().subscribe(self.SetLayoutButtonFull, |
802 | 900 | "Set layout button full") |
803 | 901 | |
902 | + ps.Publisher().subscribe(self.OnEnableState, "Enable state project") | |
903 | + | |
904 | + def OnEnableState(self, pubsub_evt): | |
905 | + state = pubsub_evt.data | |
906 | + if state: | |
907 | + self.SetStateProjectOpen() | |
908 | + else: | |
909 | + self.SetStateProjectClose() | |
910 | + | |
911 | + | |
912 | + | |
804 | 913 | def __bind_events_wx(self): |
805 | 914 | self.Bind(wx.EVT_TOOL, self.OnClick) |
806 | 915 | ... | ... |
invesalius/invesalius.py