Skip to content

Commit

Permalink
Show/hide robot coil combobox when robot is connected/disconnected
Browse files Browse the repository at this point in the history
  • Loading branch information
Tolonen Luka committed Sep 1, 2024
1 parent 6f5152d commit 11c4e29
Showing 1 changed file with 44 additions and 32 deletions.
76 changes: 44 additions & 32 deletions invesalius/gui/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,38 +593,34 @@ def __init__(self, parent, navigation, tracker, pedal_connector):
)
self.inner_robot_sizer = inner_robot_sizer = wx.FlexGridSizer(2, 1, 1)

self.not_connected_txt = None
self.choice_robot_coil = None
if not self.robot.IsConnected():
self.not_connected_txt = wx.StaticText(self, -1, "Robot is not connected")
inner_robot_sizer.Add(
self.not_connected_txt, 1, wx.EXPAND | wx.ALIGN_CENTER_VERTICAL, 5
)
else:
choice_robot_coil_lbl = wx.StaticText(self, -1, _("Coil attached to robot: "))
self.choice_robot_coil = choice_robot_coil = wx.ComboBox(
self,
-1,
f"{self.robot.GetCoilName() or ''}",
size=wx.Size(90, 23),
choices=list(
self.navigation.coil_registrations
), # List of coils selected for navigation
style=wx.CB_DROPDOWN | wx.CB_READONLY,
)
self.robot_lbl = wx.StaticText(self, -1, _("Robot is connected. Coil attached to robot: "))
self.choice_robot_coil = choice_robot_coil = wx.ComboBox(
self,
-1,
f"{self.robot.GetCoilName() or ''}",
size=wx.Size(90, 23),
choices=list(
self.navigation.coil_registrations
), # List of coils selected for navigation
style=wx.CB_DROPDOWN | wx.CB_READONLY,
)

choice_robot_coil.SetToolTip(
"Specify which coil is attached to the robot",
)
choice_robot_coil.SetToolTip(
"Specify which coil is attached to the robot",
)

choice_robot_coil.Bind(wx.EVT_COMBOBOX, (lambda event: self.OnChoiceRobotCoil(event)))
choice_robot_coil.Bind(wx.EVT_COMBOBOX, self.OnChoiceRobotCoil)

if not self.robot.IsConnected():
self.robot_lbl.SetLabel("Robot is not connected")
choice_robot_coil.Show(False) # Hide the combobox

inner_robot_sizer.AddMany(
[
(choice_robot_coil_lbl, 1, wx.EXPAND | wx.ALIGN_CENTER_VERTICAL, 5),
(choice_robot_coil, 1, wx.EXPAND | wx.ALIGN_CENTER_VERTICAL, 5),
]
)
inner_robot_sizer.AddMany(
[
(self.robot_lbl, 1, wx.EXPAND | wx.ALIGN_CENTER_VERTICAL, 5),
(choice_robot_coil, 1, wx.EXPAND | wx.ALIGN_CENTER_VERTICAL, 5),
]
)

robot_sizer.Add(inner_robot_sizer, 0, wx.ALL | wx.EXPAND, 10)

Expand All @@ -642,6 +638,22 @@ def __init__(self, parent, navigation, tracker, pedal_connector):

self.LoadConfig()
self.Layout()

def __bind_events(self):
Publisher.subscribe(self.OnSetCoilCount, "Reset coil selection")
Publisher.subscribe(
self.OnRobotConnectionStatus, "Robot to Neuronavigation: Robot connection status"
)

def OnRobotConnectionStatus(self, data):
if data is None:
return

self.choice_robot_coil.Show(data)
if data:
self.robot_lbl.SetLabel("Robot is connected. Coil attached to robot: ")
else:
self.robot_lbl.SetLabel("Robot is not connected.")

def OnChoiceRobotCoil(self, event):
robot_coil_name = event.GetEventObject().GetStringSelection()
Expand All @@ -667,9 +679,6 @@ def AddCoilButton(self, coil_name, show_button=True):

self.inner_sel_sizer.Add(coil_btn, 1, wx.EXPAND, 5)

def __bind_events(self):
Publisher.subscribe(self.OnSetCoilCount, "Reset coil selection")

def ShowMulticoilGUI(self, show_multicoil):
# Show/hide singlecoil configuration text
self.config_txt.Show(not show_multicoil)
Expand All @@ -682,6 +691,9 @@ def ShowMulticoilGUI(self, show_multicoil):
self.robot_sizer.GetStaticBox().Show(show_multicoil)
self.robot_sizer.ShowItems(show_multicoil)

# Show the robot coil combobox only if the robot is connected
self.choice_robot_coil.Show(show_multicoil and self.robot.IsConnected())

self.Layout()

def OnSetCoilCount(self, n_coils):
Expand Down

0 comments on commit 11c4e29

Please sign in to comment.