Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plan window improvement #311

Merged
merged 13 commits into from
Jan 7, 2025
74 changes: 61 additions & 13 deletions src/firefly/plans/grid_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def setup_ui(self):
"Motor",
"Start",
"Stop",
"Scan points",
"N. points",
"Size",
"Snake",
"Fly",
]
Expand All @@ -38,7 +39,7 @@ def setup_ui(self):
# fix widths so the labels are aligned with GridScanRegions
Qlabels_all["Priority axis"].setFixedWidth(70)
Qlabels_all["Motor"].setFixedWidth(100)
Qlabels_all["Scan points"].setFixedWidth(68)
Qlabels_all["N. points"].setFixedWidth(68)
Qlabels_all["Snake"].setFixedWidth(53)
Qlabels_all["Fly"].setFixedWidth(43)

Expand All @@ -52,48 +53,84 @@ class GridScanRegion(regions_display.RegionBase):
def setup_ui(self):
self.layout = QtWidgets.QHBoxLayout()

# First item, motor No.
# motor No.
self.motor_label = QtWidgets.QLCDNumber()
self.motor_label.setStyleSheet(
"QLCDNumber { background-color: white; color: red; }"
)
self.motor_label.display(self.line_label)
self.layout.addWidget(self.motor_label)

# Second item, ComponentSelector
# ComponentSelector
self.motor_box = ComponentSelector()
self.layout.addWidget(self.motor_box)

# Third item, start point
# Start point
self.start_line_edit = QtWidgets.QLineEdit()
self.start_line_edit.setValidator(QDoubleValidator()) # only takes floats
self.start_line_edit.setPlaceholderText("Start…")
self.layout.addWidget(self.start_line_edit)

# Forth item, stop point
# Stop point
self.stop_line_edit = QtWidgets.QLineEdit()
self.stop_line_edit.setValidator(QDoubleValidator()) # only takes floats
self.stop_line_edit.setPlaceholderText("Stop…")
self.layout.addWidget(self.stop_line_edit)

# Fifth item, number of scan point
# Number of scan point
self.scan_pts_spin_box = QtWidgets.QSpinBox()
self.scan_pts_spin_box.setMinimum(1)
self.scan_pts_spin_box.setMaximum(99999)
self.layout.addWidget(self.scan_pts_spin_box)

# Sixth item, snake checkbox
# Step size (non-editable)
self.step_size_line_edit = QtWidgets.QLineEdit()
self.step_size_line_edit.setReadOnly(True)
self.step_size_line_edit.setDisabled(True)
self.step_size_line_edit.setPlaceholderText("Step Size…")
self.layout.addWidget(self.step_size_line_edit)

# Snake checkbox
self.snake_checkbox = QtWidgets.QCheckBox()
self.snake_checkbox.setText("Snake")
self.snake_checkbox.setEnabled(True)
self.layout.addWidget(self.snake_checkbox)

# Seventh item, fly checkbox # not available right now
# Fly checkbox # not available right now
self.fly_checkbox = QtWidgets.QCheckBox()
self.fly_checkbox.setText("Fly")
self.fly_checkbox.setEnabled(False)
self.layout.addWidget(self.fly_checkbox)

# Connect signals
self.start_line_edit.textChanged.connect(self.update_step_size)
self.stop_line_edit.textChanged.connect(self.update_step_size)
self.scan_pts_spin_box.valueChanged.connect(self.update_step_size)

def update_step_size(self):
try:
# Get Start and Stop values
start_text = self.start_line_edit.text().strip()
stop_text = self.stop_line_edit.text().strip()
if not start_text or not stop_text:
self.step_size_line_edit.setText("N/A")
return

start = float(start_text)
stop = float(stop_text)

# Ensure num_points is an integer
num_points = int(self.scan_pts_spin_box.value()) # Corrected method call

# Calculate step size
if num_points > 1:
step_size = (stop - start) / (num_points - 1)
self.step_size_line_edit.setText(f"{step_size}")
else:
self.step_size_line_edit.setText("N/A")
except ValueError:
self.step_size_line_edit.setText("N/A")


class GridScanDisplay(regions_display.RegionsDisplay):
Region = GridScanRegion
Expand All @@ -108,14 +145,25 @@ def customize_ui(self):
# add title layout
self.title_region = TitleRegion()
self.ui.title_layout.addLayout(self.title_region.layout)
# When selections of detectors changed update_total_time
# self.ui.detectors_list.selectionModel().selectionChanged.connect(
# self.update_total_time
# )
self.ui.spinBox_repeat_scan_num.valueChanged.connect(self.update_total_time)
# Connect scan points change to update total time
for region in self.regions:
region.scan_pts_spin_box.valueChanged.connect(self.update_total_time)
self.ui.relative_scan_checkbox.stateChanged.connect(self.change_background)

def change_background(self, state):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this method be moved to the RegionsDisplay class so we don't need to write it twice? It looks identical between the line scan and grid scan versions.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea!

"""
Change the background color of the relative scan checkbox based on its state.
"""
if state: # Checked
self.ui.relative_scan_checkbox.setStyleSheet(
"background-color: rgb(255, 85, 127);"
)

else: # Unchecked
self.ui.relative_scan_checkbox.setStyleSheet(
"background-color: rgb(0, 170, 255);"
)

def time_per_scan(self, detector_time):
total_num_pnts = np.prod(
Expand Down
178 changes: 94 additions & 84 deletions src/firefly/plans/grid_scan.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>983</width>
<height>432</height>
<width>800</width>
<height>385</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -65,9 +65,15 @@
</item>
<item>
<widget class="QCheckBox" name="relative_scan_checkbox">
<property name="styleSheet">
<string notr="true">background-color: rgb(255, 85, 127);</string>
</property>
<property name="text">
<string>Relative</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
Expand All @@ -86,93 +92,97 @@
</layout>
</item>
<item row="2" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_7">
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="widgetResizable">
<bool>true</bool>
<widget class="QSplitter" name="splitter">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>471</width>
<height>215</height>
</rect>
<widget class="QScrollArea" name="scrollArea_2">
<property name="minimumSize">
<size>
<width>500</width>
<height>0</height>
</size>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<layout class="QVBoxLayout" name="title_layout">
<property name="topMargin">
<number>3</number>
</property>
<property name="bottomMargin">
<number>3</number>
</property>
</layout>
</item>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents_2">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>498</width>
<height>207</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_7">
<item>
<layout class="QVBoxLayout" name="title_layout">
<property name="topMargin">
<number>3</number>
</property>
<property name="bottomMargin">
<number>3</number>
</property>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="regions_layout">
<property name="topMargin">
<number>3</number>
</property>
<property name="bottomMargin">
<number>3</number>
</property>
</layout>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
<widget class="QWidget" name="layoutWidget">
<layout class="QVBoxLayout" name="verticalLayout_8">
<item>
<layout class="QVBoxLayout" name="regions_layout">
<property name="topMargin">
<number>3</number>
<widget class="QLabel" name="detectors_label_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="bottomMargin">
<number>3</number>
<property name="text">
<string>Detectors</string>
</property>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
<widget class="DetectorListView" name="detectors_list">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Use &lt;span style=&quot; font-weight:600;&quot;&gt;ctrl&lt;/span&gt; to select multiple detectors&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
<property name="selectionMode">
<enum>QAbstractItemView::MultiSelection</enum>
</property>
</spacer>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
<item>
<widget class="Line" name="line_5">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QLabel" name="detectors_label">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Detectors</string>
</property>
</widget>
</item>
<item>
<widget class="DetectorListView" name="detectors_list">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Use &lt;span style=&quot; font-weight:600;&quot;&gt;ctrl&lt;/span&gt; to select multiple detectors&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::MultiSelection</enum>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item row="3" column="0">
Expand All @@ -182,6 +192,13 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="Line" name="line_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="4" column="0">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="2">
Expand All @@ -190,7 +207,7 @@
<string>Experiment purpose:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
</widget>
</item>
Expand Down Expand Up @@ -235,7 +252,7 @@
<string>Exposure time each scan:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
</widget>
</item>
Expand All @@ -248,7 +265,7 @@
<string>Total exposure time:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
</widget>
</item>
Expand Down Expand Up @@ -502,13 +519,6 @@
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="Line" name="line_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</item>
</layout>
Expand Down
Loading
Loading