Commit 465096eb365669351dd4ce5c63659c41d8436cfa

Authored by okahilak
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 309  
310 310  
311 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 315 self.image_fiducials = np.full([3, 3], np.nan)
316 316 self.correg = None
... ... @@ -485,12 +485,14 @@ class Navigation():
485 485 jobs.start()
486 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 491 def StopNavigation(self):
491 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 497 self.coord_queue.clear()
496 498 self.coord_queue.join()
... ... @@ -699,7 +701,9 @@ class NeuronavigationPanel(wx.Panel):
699 701 # Initialize global variables
700 702 self.pedal_connection = PedalConnection() if HAS_PEDAL_CONNECTION else None
701 703 self.tracker = Tracker()
702   - self.navigation = Navigation()
  704 + self.navigation = Navigation(
  705 + pedal_connection=self.pedal_connection,
  706 + )
703 707 self.icp = ICP()
704 708  
705 709 self.nav_status = False
... ... @@ -753,7 +757,7 @@ class NeuronavigationPanel(wx.Panel):
753 757 txt_fre = wx.StaticText(self, -1, _('FRE:'))
754 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 761 txt_pedal_pressed = wx.StaticText(self, -1, _('Pedal pressed:'))
758 762 else:
759 763 txt_pedal_pressed = None
... ... @@ -782,7 +786,7 @@ class NeuronavigationPanel(wx.Panel):
782 786 self.checkbox_icp = checkbox_icp
783 787  
784 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 790 tooltip = wx.ToolTip(_(u"Is the pedal pressed"))
787 791 checkbox_pedal_pressed = wx.CheckBox(self, -1, _(' '))
788 792 checkbox_pedal_pressed.SetValue(False)
... ... @@ -1132,7 +1136,9 @@ class NeuronavigationPanel(wx.Panel):
1132 1136 # TODO: Reset camera initial focus
1133 1137 Publisher.sendMessage('Reset cam clipping range')
1134 1138 self.navigation.StopNavigation()
1135   - self.navigation.__init__()
  1139 + self.navigation.__init__(
  1140 + pedal_connection=self.pedal_connection,
  1141 + )
1136 1142 self.tracker.__init__()
1137 1143 self.icp.__init__()
1138 1144  
... ...