From 95ff0f7143ea78a94e6590dcf44cc2be3e372cf1 Mon Sep 17 00:00:00 2001 From: Tolonen Luka Date: Sun, 1 Sep 2024 22:00:53 +0300 Subject: [PATCH] Show/hide robot coil combobox when robot is connected/disconnected. RUFF format --- invesalius/gui/preferences.py | 76 +++++++++++++++++------------ invesalius/navigation/navigation.py | 4 +- 2 files changed, 46 insertions(+), 34 deletions(-) diff --git a/invesalius/gui/preferences.py b/invesalius/gui/preferences.py index 464187cb0..7af9145d9 100644 --- a/invesalius/gui/preferences.py +++ b/invesalius/gui/preferences.py @@ -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) - 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), - ] - ) + 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( + [ + (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) @@ -643,6 +639,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() self.robot.SetCoilName(robot_coil_name) @@ -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) @@ -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): diff --git a/invesalius/navigation/navigation.py b/invesalius/navigation/navigation.py index 277905dab..11689b868 100644 --- a/invesalius/navigation/navigation.py +++ b/invesalius/navigation/navigation.py @@ -28,6 +28,7 @@ import invesalius.data.bases as db import invesalius.data.coregistration as dcr import invesalius.data.e_field as e_field +import invesalius.data.polydata_utils as pu import invesalius.data.serial_port_connection as spc import invesalius.data.slice_ as sl import invesalius.data.tractography as dti @@ -45,7 +46,6 @@ from invesalius.net.pedal_connection import PedalConnector from invesalius.pubsub import pub as Publisher from invesalius.utils import Singleton -import invesalius.data.polydata_utils as pu class NavigationHub(metaclass=Singleton): @@ -568,7 +568,7 @@ def StartNavigation(self, tracker, icp): robot = Robot() if robot.GetCoilName() in self.coil_registrations: - # Tell robot at which index (obj_id) to find its coil in + # Tell robot at which index (obj_id) to find its coil in (relevant when there are multiple coils) Publisher.sendMessage( "Neuronavigation to Robot: Set coil index", data=self.coil_registrations[robot.GetCoilName()]["obj_id"],