Commit 8a14b3092ec83e5547c8ec32bb75b1107cd83a15
1 parent
b966468a
Exists in
master
FIX: Using pedal for setting fiducials
Previously, the callback for setting the fiducial was removed while executing the callback. However, that did not work because it made the list of callbacks that PedalConnection looped over change on the fly. Instead, use 'remove when released' option for callbacks to automatically remove the callback when the pedal is released.
Showing
3 changed files
with
20 additions
and
9 deletions
Show diff stats
invesalius/gui/dialogs.py
... | ... | @@ -3556,8 +3556,6 @@ class ObjectCalibrationDialog(wx.Dialog): |
3556 | 3556 | def set_fiducial_callback(state): |
3557 | 3557 | if state: |
3558 | 3558 | Publisher.sendMessage('Set object fiducial', fiducial_index=index) |
3559 | - if self.pedal_connection is not None: | |
3560 | - self.pedal_connection.remove_callback('fiducial') | |
3561 | 3559 | |
3562 | 3560 | ctrl.SetValue(False) |
3563 | 3561 | self.object_fiducial_being_set = None |
... | ... | @@ -3566,10 +3564,17 @@ class ObjectCalibrationDialog(wx.Dialog): |
3566 | 3564 | self.object_fiducial_being_set = index |
3567 | 3565 | |
3568 | 3566 | if self.pedal_connection is not None: |
3569 | - self.pedal_connection.add_callback('fiducial', set_fiducial_callback) | |
3567 | + self.pedal_connection.add_callback( | |
3568 | + name='fiducial', | |
3569 | + callback=set_fiducial_callback, | |
3570 | + remove_when_released=True, | |
3571 | + ) | |
3570 | 3572 | else: |
3571 | 3573 | set_fiducial_callback(True) |
3572 | 3574 | |
3575 | + if self.pedal_connection is not None: | |
3576 | + self.pedal_connection.remove_callback(name='fiducial') | |
3577 | + | |
3573 | 3578 | def SetObjectFiducial(self, fiducial_index): |
3574 | 3579 | coord, coord_raw = self.tracker.GetTrackerCoordinates( |
3575 | 3580 | # XXX: Always use static reference mode when getting the coordinates. This is what the | ... | ... |
invesalius/gui/task_navigator.py
... | ... | @@ -425,7 +425,7 @@ class NeuronavigationPanel(wx.Panel): |
425 | 425 | checkbox_pedal_pressed.Enable(False) |
426 | 426 | checkbox_pedal_pressed.SetToolTip(tooltip) |
427 | 427 | |
428 | - pedal_connection.add_callback('gui', checkbox_pedal_pressed.SetValue) | |
428 | + pedal_connection.add_callback(name='gui', callback=checkbox_pedal_pressed.SetValue) | |
429 | 429 | |
430 | 430 | self.checkbox_pedal_pressed = checkbox_pedal_pressed |
431 | 431 | else: |
... | ... | @@ -688,19 +688,25 @@ class NeuronavigationPanel(wx.Panel): |
688 | 688 | if state: |
689 | 689 | fiducial_name = const.TRACKER_FIDUCIALS[n]['fiducial_name'] |
690 | 690 | Publisher.sendMessage('Set tracker fiducial', fiducial_name=fiducial_name) |
691 | - if self.pedal_connection is not None: | |
692 | - self.pedal_connection.remove_callback('fiducial') | |
693 | 691 | |
694 | 692 | ctrl.SetValue(False) |
695 | 693 | self.tracker_fiducial_being_set = None |
696 | 694 | |
697 | 695 | if ctrl.GetValue(): |
698 | 696 | self.tracker_fiducial_being_set = n |
697 | + | |
699 | 698 | if self.pedal_connection is not None: |
700 | - self.pedal_connection.add_callback('fiducial', set_fiducial_callback) | |
699 | + self.pedal_connection.add_callback( | |
700 | + name='fiducial', | |
701 | + callback=set_fiducial_callback, | |
702 | + remove_when_released=True, | |
703 | + ) | |
701 | 704 | else: |
702 | 705 | set_fiducial_callback(True) |
703 | 706 | |
707 | + if self.pedal_connection is not None: | |
708 | + self.pedal_connection.remove_callback(name='fiducial') | |
709 | + | |
704 | 710 | def OnStopNavigation(self): |
705 | 711 | select_tracker_elem = self.select_tracker_elem |
706 | 712 | choice_ref = self.choice_ref | ... | ... |
invesalius/navigation/navigation.py
... | ... | @@ -313,13 +313,13 @@ class Navigation(): |
313 | 313 | # del jobs |
314 | 314 | |
315 | 315 | if self.pedal_connection is not None: |
316 | - self.pedal_connection.add_callback('navigation', self.PedalStateChanged) | |
316 | + self.pedal_connection.add_callback(name='navigation', callback=self.PedalStateChanged) | |
317 | 317 | |
318 | 318 | def StopNavigation(self): |
319 | 319 | self.event.set() |
320 | 320 | |
321 | 321 | if self.pedal_connection is not None: |
322 | - self.pedal_connection.remove_callback('navigation') | |
322 | + self.pedal_connection.remove_callback(name='navigation') | |
323 | 323 | |
324 | 324 | self.coord_queue.clear() |
325 | 325 | self.coord_queue.join() | ... | ... |