Skip to content

Commit

Permalink
Fixed UI bugs in the Firefly robot display.
Browse files Browse the repository at this point in the history
  • Loading branch information
yannachen committed Jul 2, 2024
1 parent 8c9828d commit 13de054
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 51 deletions.
1 change: 1 addition & 0 deletions src/firefly/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ def all_actions(self):
*self.kb_mirrors.values(),
*self.mirrors.values(),
*self.motors.values(),
*self.robots.values(),
*self.slits.values(),
*self.tables.values(),
*self.xrf_detectors.values(),
Expand Down
14 changes: 9 additions & 5 deletions src/firefly/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from qasync import asyncSlot
from qtpy import QtCore, QtWidgets
from qtpy.QtCore import Signal
from qtpy.QtGui import QKeySequence
from qtpy.QtGui import QKeySequence, QIcon
from qtpy.QtWidgets import QAction

from haven import load_config
Expand Down Expand Up @@ -187,6 +187,7 @@ def setup_window_actions(self):
device_label="robots",
display_file=ui_dir / "robot.py",
device_key="DEVICE",
WindowClass=PlanMainWindow,
icon=qta.icon("mdi.robot-industrial"),
)
self.actions.xrf_detectors = self.device_actions(
Expand Down Expand Up @@ -421,9 +422,10 @@ def setup_queue_actions(self):
def device_actions(
self,
device_label: str,
display_file=None,
device_key="DEVICE",
icon=None,
display_file: str = None,
device_key: str = "DEVICE",
WindowClass: type = FireflyMainWindow,
icon: QIcon = None,
):
"""Generic routine to be called for individual classes of devices.
Expand All @@ -449,6 +451,8 @@ def device_actions(
dictionary. If *device_key* is "DEVICE" (default), then the
macros will be {"DEVICE": device.name}. Has no effect if
*window_slot* is used.
WindowClass
The type of window to create around this device display.
icon
A QIcon that will be added to the action.
Expand All @@ -469,7 +473,7 @@ def device_actions(
text=titelize(device.name),
display_file=display_file,
icon=icon,
WindowClass=FireflyMainWindow,
WindowClass=WindowClass,
macros={device_key: device.name},
)
for device in devices
Expand Down
4 changes: 1 addition & 3 deletions src/firefly/plans/regions_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def customize_ui(self):

# Create the initial (blank) regions
self.regions = []
self.ui.num_motor_spin_box.setValue(self.default_num_regions)
self.add_regions(self.default_num_regions)
# Set up the mechanism for changing region number
self.ui.num_motor_spin_box.valueChanged.connect(self.update_regions_slot)
Expand All @@ -80,9 +81,6 @@ def clearLayout(self, layout):
if item.widget():
item.widget().deleteLater()

def reset_default_regions(self):
self.ui.num_motor_spin_box.setValue(self.default_num_regions)

def add_regions(self, num: int = 1):
"""Add *num* regions to the list of scan parameters.
Expand Down
47 changes: 4 additions & 43 deletions src/firefly/robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
from qtpy import QtWidgets

from firefly.component_selector import ComponentSelector
from firefly.plans.regions_display import RegionBase, RegionsDisplay
from firefly.plans import regions_display # import RegionBase, RegionsDisplay

log = logging.getLogger(__name__)


class RobotMotorRegion(RegionBase):
class RobotMotorRegion(regions_display.RegionBase):
def setup_ui(self):
self.layout = QtWidgets.QHBoxLayout()

Expand All @@ -23,7 +23,7 @@ def setup_ui(self):
self.layout.addWidget(self.start_line_edit)


class RobotDisplay(RegionsDisplay):
class RobotDisplay(regions_display.RegionsDisplay):
"""Manage sample transfer using a robot plan.
.. code-block:: python
Expand All @@ -34,6 +34,7 @@ class RobotDisplay(RegionsDisplay):
"""

Region = RobotMotorRegion
default_num_regions = 0

def sample_numbers(self):
sample_names = [name for name, device in self.device.samples.walk_subdevices()]
Expand All @@ -48,46 +49,6 @@ def customize_ui(self):
for sam in self.sample_numbers():
self.ui.sample_combo_box.addItem(str(sam))

# disable the line edits in spin box
# self.ui.num_motor_spin_box.lineEdit().setReadOnly(True)
# self.ui.num_motor_spin_box.valueChanged.connect(self.update_regions)
# self.ui.run_button.clicked.connect(self.queue_plan)

# def reset_default_regions(self):
# default_num_regions = 1
# if not hasattr(self, "regions"):
# self.regions = []
# self.add_regions(default_num_regions)
# self.ui.num_motor_spin_box.setValue(default_num_regions)
# self.update_regions()

# def add_regions(self, num=1):
# for i in range(num):
# region = LineScanRegion()
# self.ui.regions_layout.addLayout(region.layout)
# # Save it to the list
# self.regions.append(region)

# def remove_regions(self, num=1):
# for i in range(num):
# layout = self.regions[-1].layout
# # iterate/wait, and delete all widgets in the layout in the end
# while layout.count() > 0:
# item = layout.takeAt(0)
# if item.widget():
# item.widget().deleteLater()
# self.regions.pop()

# def update_regions(self):
# new_region_num = self.ui.num_motor_spin_box.value()
# old_region_num = len(self.regions)
# diff_region_num = new_region_num - old_region_num

# if diff_region_num < 0:
# self.remove_regions(abs(diff_region_num))
# elif diff_region_num > 0:
# self.add_regions(diff_region_num)

def queue_plan(self, *args, **kwargs):
"""Execute this plan on the queueserver."""
# Get scan parameters from widgets
Expand Down

0 comments on commit 13de054

Please sign in to comment.