Skip to content

Commit

Permalink
Merge pull request #311 from spc-group/plan_window_improvement
Browse files Browse the repository at this point in the history
Plan window improvement
  • Loading branch information
Cathyhjj authored Jan 7, 2025
2 parents 3d46fc4 + f23f33d commit 2407ebc
Show file tree
Hide file tree
Showing 7 changed files with 509 additions and 308 deletions.
59 changes: 46 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,10 +145,6 @@ 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:
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

0 comments on commit 2407ebc

Please sign in to comment.