Skip to content

Commit

Permalink
RUFF format
Browse files Browse the repository at this point in the history
  • Loading branch information
Tolonen Luka committed Aug 31, 2024
1 parent 33a0612 commit dee2cdb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
19 changes: 8 additions & 11 deletions invesalius/gui/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ def AddCoilButton(self, coil_name, show_button=True):
coil_btn.Bind(
wx.EVT_RIGHT_DOWN, lambda event, name=coil_name: self.OnRightClickCoil(event, name)
)
coil_btn.Show(show_button)
coil_btn.Show(show_button)
self.coil_btns[coil_name] = (coil_btn, 1, wx.EXPAND | wx.ALIGN_CENTER_VERTICAL, 5)

self.inner_sel_sizer.Add(coil_btn, 1, wx.EXPAND, 5)
Expand All @@ -684,17 +684,16 @@ def ShowMulticoilGUI(self, show_multicoil):

self.robot_sizer.GetStaticBox().Show(show_multicoil)
self.robot_sizer.ShowItems(show_multicoil)

self.Layout()

self.Layout()

def OnSetCoilCount(self, n_coils):
multicoil_mode = n_coils > 1
multicoil_mode = n_coils > 1

if multicoil_mode:
# Update multicoil GUI elements
self.sel_sizer.GetStaticBox().SetLabel(f"TMS coil selection (0 out of {n_coils})")

# Reset (enable and unpress) all coil-buttons
for btn, *junk in self.coil_btns.values():
btn.Enable()
Expand Down Expand Up @@ -722,7 +721,7 @@ def LoadConfig(self):
self.config_txt.SetLabel(
f"{os.path.basename(self.coil_registrations.get('default_coil', {}).get('path', 'None'))}"
)

n_coils_selected = len(selected_coils)
self.sel_sizer.GetStaticBox().SetLabel(
f"TMS coil selection ({n_coils_selected} out of {n_coils})"
Expand All @@ -732,12 +731,10 @@ def LoadConfig(self):
self.CoilSelectionDone()

def CoilSelectionDone(self):
if self.navigation.n_coils == 1: # Tell the robot the coil name
if self.navigation.n_coils == 1: # Tell the robot the coil name
self.robot.SetCoilName(next(iter(self.navigation.coil_registrations)))

Publisher.sendMessage(
"Coil selection done", done=True
)
Publisher.sendMessage("Coil selection done", done=True)
Publisher.sendMessage("Update status text in GUI", label=_("Ready"))

# Allow only n_coils buttons to be pressed, so disable unpressed coil-buttons
Expand Down Expand Up @@ -787,7 +784,7 @@ def OnSelectCoil(self, event=None, name=None, select=False):
)
event.GetEventObject().SetValue(False) # Unpress the button
return

# Press the coil button here in case selection was done via code without pressing button
self.coil_btns[name][0].SetValue(True)

Expand Down
4 changes: 1 addition & 3 deletions invesalius/navigation/navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,7 @@ def LoadConfig(self):
if coil_name in saved_coil_registrations
}
if self.coil_registrations:
self.main_coil = self.main_coil or next(
iter(self.coil_registrations)
)
self.main_coil = self.main_coil or next(iter(self.coil_registrations))

# Try to load stylus orientation data
if "r_stylus" in state:
Expand Down
13 changes: 8 additions & 5 deletions invesalius/navigation/robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ def SaveConfig(self, key=None, value=None):
session = ses.Session()
if key is None or value is None:
# Save the whole state
state = {"robot_ip": self.robot_ip, "tracker_to_robot": self.matrix_tracker_to_robot.tolist()}
state = {
"robot_ip": self.robot_ip,
"tracker_to_robot": self.matrix_tracker_to_robot.tolist(),
}
if self.coil_name is not None:
state["robot_coil"] = self.coil_name
else:
Expand All @@ -101,16 +104,16 @@ def SaveConfig(self, key=None, value=None):
def LoadConfig(self):
session = ses.Session()
state = session.GetConfig("robot", {})

self.coil_name = state.get("robot_coil", None)

self.robot_ip = state.get("robot_ip", None)

self.matrix_tracker_to_robot = state.get("tracker_to_robot", None)
if self.matrix_tracker_to_robot is not None:
self.matrix_tracker_to_robot = np.array(self.matrix_tracker_to_robot)

success = (self.robot_ip is not None and self.matrix_tracker_to_robot is not None)
success = self.robot_ip is not None and self.matrix_tracker_to_robot is not None
return success

def OnRobotConnectionStatus(self, data):
Expand Down Expand Up @@ -154,7 +157,7 @@ def AbortRobotConfiguration(self):
def IsConnected(self):
return self.is_robot_connected

def IsReady(self): # LUKATODO: use this check before enabling robot for navigation...
def IsReady(self): # LUKATODO: use this check before enabling robot for navigation...
self.IsConnected() and (self.coil_name in self.navigation.coil_registrations)

def SetRobotIP(self, data):
Expand Down

0 comments on commit dee2cdb

Please sign in to comment.