Commit 465096eb365669351dd4ce5c63659c41d8436cfa
Committed by
GitHub
1 parent
12551024
Exists in
master
FIX: Pedal connection crashing if mido library is not installed (#328)
Showing
1 changed file
with
14 additions
and
8 deletions
Show diff stats
invesalius/gui/task_navigator.py
@@ -309,8 +309,8 @@ class InnerFoldPanel(wx.Panel): | @@ -309,8 +309,8 @@ class InnerFoldPanel(wx.Panel): | ||
309 | 309 | ||
310 | 310 | ||
311 | class Navigation(): | 311 | class Navigation(): |
312 | - def __init__(self): | ||
313 | - self.pedal_connection = PedalConnection() | 312 | + def __init__(self, pedal_connection): |
313 | + self.pedal_connection = pedal_connection | ||
314 | 314 | ||
315 | self.image_fiducials = np.full([3, 3], np.nan) | 315 | self.image_fiducials = np.full([3, 3], np.nan) |
316 | self.correg = None | 316 | self.correg = None |
@@ -485,12 +485,14 @@ class Navigation(): | @@ -485,12 +485,14 @@ class Navigation(): | ||
485 | jobs.start() | 485 | jobs.start() |
486 | # del jobs | 486 | # del jobs |
487 | 487 | ||
488 | - self.pedal_connection.add_callback('navigation', self.PedalStateChanged) | 488 | + if self.pedal_connection is not None: |
489 | + self.pedal_connection.add_callback('navigation', self.PedalStateChanged) | ||
489 | 490 | ||
490 | def StopNavigation(self): | 491 | def StopNavigation(self): |
491 | self.event.set() | 492 | self.event.set() |
492 | 493 | ||
493 | - self.pedal_connection.remove_callback('navigation') | 494 | + if self.pedal_connection is not None: |
495 | + self.pedal_connection.remove_callback('navigation') | ||
494 | 496 | ||
495 | self.coord_queue.clear() | 497 | self.coord_queue.clear() |
496 | self.coord_queue.join() | 498 | self.coord_queue.join() |
@@ -699,7 +701,9 @@ class NeuronavigationPanel(wx.Panel): | @@ -699,7 +701,9 @@ class NeuronavigationPanel(wx.Panel): | ||
699 | # Initialize global variables | 701 | # Initialize global variables |
700 | self.pedal_connection = PedalConnection() if HAS_PEDAL_CONNECTION else None | 702 | self.pedal_connection = PedalConnection() if HAS_PEDAL_CONNECTION else None |
701 | self.tracker = Tracker() | 703 | self.tracker = Tracker() |
702 | - self.navigation = Navigation() | 704 | + self.navigation = Navigation( |
705 | + pedal_connection=self.pedal_connection, | ||
706 | + ) | ||
703 | self.icp = ICP() | 707 | self.icp = ICP() |
704 | 708 | ||
705 | self.nav_status = False | 709 | self.nav_status = False |
@@ -753,7 +757,7 @@ class NeuronavigationPanel(wx.Panel): | @@ -753,7 +757,7 @@ class NeuronavigationPanel(wx.Panel): | ||
753 | txt_fre = wx.StaticText(self, -1, _('FRE:')) | 757 | txt_fre = wx.StaticText(self, -1, _('FRE:')) |
754 | txt_icp = wx.StaticText(self, -1, _('Refine:')) | 758 | txt_icp = wx.StaticText(self, -1, _('Refine:')) |
755 | 759 | ||
756 | - if HAS_PEDAL_CONNECTION and self.pedal_connection.in_use: | 760 | + if self.pedal_connection is not None and self.pedal_connection.in_use: |
757 | txt_pedal_pressed = wx.StaticText(self, -1, _('Pedal pressed:')) | 761 | txt_pedal_pressed = wx.StaticText(self, -1, _('Pedal pressed:')) |
758 | else: | 762 | else: |
759 | txt_pedal_pressed = None | 763 | txt_pedal_pressed = None |
@@ -782,7 +786,7 @@ class NeuronavigationPanel(wx.Panel): | @@ -782,7 +786,7 @@ class NeuronavigationPanel(wx.Panel): | ||
782 | self.checkbox_icp = checkbox_icp | 786 | self.checkbox_icp = checkbox_icp |
783 | 787 | ||
784 | # An indicator for pedal trigger | 788 | # An indicator for pedal trigger |
785 | - if HAS_PEDAL_CONNECTION and self.pedal_connection.in_use: | 789 | + if self.pedal_connection is not None and self.pedal_connection.in_use: |
786 | tooltip = wx.ToolTip(_(u"Is the pedal pressed")) | 790 | tooltip = wx.ToolTip(_(u"Is the pedal pressed")) |
787 | checkbox_pedal_pressed = wx.CheckBox(self, -1, _(' ')) | 791 | checkbox_pedal_pressed = wx.CheckBox(self, -1, _(' ')) |
788 | checkbox_pedal_pressed.SetValue(False) | 792 | checkbox_pedal_pressed.SetValue(False) |
@@ -1132,7 +1136,9 @@ class NeuronavigationPanel(wx.Panel): | @@ -1132,7 +1136,9 @@ class NeuronavigationPanel(wx.Panel): | ||
1132 | # TODO: Reset camera initial focus | 1136 | # TODO: Reset camera initial focus |
1133 | Publisher.sendMessage('Reset cam clipping range') | 1137 | Publisher.sendMessage('Reset cam clipping range') |
1134 | self.navigation.StopNavigation() | 1138 | self.navigation.StopNavigation() |
1135 | - self.navigation.__init__() | 1139 | + self.navigation.__init__( |
1140 | + pedal_connection=self.pedal_connection, | ||
1141 | + ) | ||
1136 | self.tracker.__init__() | 1142 | self.tracker.__init__() |
1137 | self.icp.__init__() | 1143 | self.icp.__init__() |
1138 | 1144 |