Skip to content

Commit

Permalink
Show/hide robot coil combobox when robot is connected/disconnected. R…
Browse files Browse the repository at this point in the history
…UFF format
  • Loading branch information
Tolonen Luka committed Sep 2, 2024
1 parent 7d8439c commit 95ff0f7
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 34 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)

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)

Expand All @@ -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)
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
4 changes: 2 additions & 2 deletions invesalius/navigation/navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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"],
Expand Down

0 comments on commit 95ff0f7

Please sign in to comment.