Commit 6a015bc0ffb69dbf4200c5fbe1e9c13d863e9a80
Committed by
GitHub
1 parent
eddf4890
Exists in
master
MOD: Allow setting tracker fiducials by pedal (#335)
* MOD: Allow setting tracker fiducials by pedal * Review comments: Improve style in boolean check * Review comments: Remove hardcoded size from fiducial buttons
Showing
1 changed file
with
37 additions
and
9 deletions
Show diff stats
invesalius/gui/task_navigator.py
... | ... | @@ -64,6 +64,7 @@ import invesalius.data.vtk_utils as vtk_utils |
64 | 64 | import invesalius.gui.dialogs as dlg |
65 | 65 | import invesalius.project as prj |
66 | 66 | from invesalius import utils |
67 | +from invesalius.gui import utils as gui_utils | |
67 | 68 | |
68 | 69 | HAS_PEDAL_CONNECTION = True |
69 | 70 | try: |
... | ... | @@ -718,6 +719,7 @@ class NeuronavigationPanel(wx.Panel): |
718 | 719 | self.icp = ICP() |
719 | 720 | |
720 | 721 | self.nav_status = False |
722 | + self.tracker_fiducial_being_set = None | |
721 | 723 | |
722 | 724 | # Initialize list of buttons and numctrls for wx objects |
723 | 725 | self.btns_set_fiducial = [None, None, None, None, None, None] |
... | ... | @@ -750,9 +752,12 @@ class NeuronavigationPanel(wx.Panel): |
750 | 752 | label = fiducial['label'] |
751 | 753 | tip = fiducial['tip'] |
752 | 754 | |
753 | - self.btns_set_fiducial[n] = wx.ToggleButton(self, button_id, label=label, size=wx.Size(45, 23)) | |
754 | - self.btns_set_fiducial[n].SetToolTip(wx.ToolTip(tip)) | |
755 | - self.btns_set_fiducial[n].Bind(wx.EVT_TOGGLEBUTTON, partial(self.OnImageFiducials, n)) | |
755 | + ctrl = wx.ToggleButton(self, button_id, label=label) | |
756 | + ctrl.SetMinSize((gui_utils.calc_width_needed(ctrl, 3), -1)) | |
757 | + ctrl.SetToolTip(wx.ToolTip(tip)) | |
758 | + ctrl.Bind(wx.EVT_TOGGLEBUTTON, partial(self.OnImageFiducials, n)) | |
759 | + | |
760 | + self.btns_set_fiducial[n] = ctrl | |
756 | 761 | |
757 | 762 | # Push buttons for tracker fiducials |
758 | 763 | for n, fiducial in enumerate(const.TRACKER_FIDUCIALS): |
... | ... | @@ -760,9 +765,12 @@ class NeuronavigationPanel(wx.Panel): |
760 | 765 | label = fiducial['label'] |
761 | 766 | tip = fiducial['tip'] |
762 | 767 | |
763 | - self.btns_set_fiducial[n + 3] = wx.Button(self, button_id, label=label, size=wx.Size(45, 23)) | |
764 | - self.btns_set_fiducial[n + 3].SetToolTip(wx.ToolTip(tip)) | |
765 | - self.btns_set_fiducial[n + 3].Bind(wx.EVT_BUTTON, partial(self.OnTrackerFiducials, n)) | |
768 | + ctrl = wx.ToggleButton(self, button_id, label=label) | |
769 | + ctrl.SetMinSize((gui_utils.calc_width_needed(ctrl, 3), -1)) | |
770 | + ctrl.SetToolTip(wx.ToolTip(tip)) | |
771 | + ctrl.Bind(wx.EVT_TOGGLEBUTTON, partial(self.OnTrackerFiducials, n, ctrl=ctrl)) | |
772 | + | |
773 | + self.btns_set_fiducial[n + 3] = ctrl | |
766 | 774 | |
767 | 775 | # TODO: Find a better allignment between FRE, text and navigate button |
768 | 776 | txt_fre = wx.StaticText(self, -1, _('FRE:')) |
... | ... | @@ -1041,9 +1049,29 @@ class NeuronavigationPanel(wx.Panel): |
1041 | 1049 | Publisher.sendMessage('Set image fiducial', fiducial_name=fiducial_name, coord=np.nan) |
1042 | 1050 | Publisher.sendMessage('Delete fiducial marker', marker_id=marker_id) |
1043 | 1051 | |
1044 | - def OnTrackerFiducials(self, n, evt): | |
1045 | - fiducial_name = const.TRACKER_FIDUCIALS[n]['fiducial_name'] | |
1046 | - Publisher.sendMessage('Set tracker fiducial', fiducial_name=fiducial_name) | |
1052 | + def OnTrackerFiducials(self, n, evt, ctrl): | |
1053 | + | |
1054 | + # Do not allow several tracker fiducials to be set at the same time. | |
1055 | + if self.tracker_fiducial_being_set is not None and self.tracker_fiducial_being_set != n: | |
1056 | + ctrl.SetValue(False) | |
1057 | + return | |
1058 | + | |
1059 | + # Called when the button for setting the tracker fiducial is enabled and either pedal is pressed | |
1060 | + # or the button is pressed again. | |
1061 | + # | |
1062 | + def set_fiducial_callback(): | |
1063 | + fiducial_name = const.TRACKER_FIDUCIALS[n]['fiducial_name'] | |
1064 | + Publisher.sendMessage('Set tracker fiducial', fiducial_name=fiducial_name) | |
1065 | + self.pedal_connection.remove_callback('fiducial') | |
1066 | + | |
1067 | + ctrl.SetValue(False) | |
1068 | + self.tracker_fiducial_being_set = None | |
1069 | + | |
1070 | + if ctrl.GetValue(): | |
1071 | + self.tracker_fiducial_being_set = n | |
1072 | + self.pedal_connection.add_callback('fiducial', set_fiducial_callback) | |
1073 | + else: | |
1074 | + set_fiducial_callback() | |
1047 | 1075 | |
1048 | 1076 | def OnStopNavigation(self): |
1049 | 1077 | select_tracker_elem = self.select_tracker_elem | ... | ... |