0
0
mirror of https://github.com/bec-project/bec_widgets.git synced 2025-07-14 03:31:50 +02:00

refactor: init_ui separated into multiple sections for each ui functionality

This commit is contained in:
wyzula-jan
2023-09-05 15:47:54 +02:00
parent 6324199299
commit b9920f3b6c
2 changed files with 135 additions and 66 deletions

View File

@ -6,10 +6,16 @@
<rect>
<x>0</x>
<y>0</y>
<width>1219</width>
<height>668</height>
<width>1409</width>
<height>748</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>1409</width>
<height>748</height>
</size>
</property>
<property name="windowTitle">
<string>Motor Controller</string>
</property>
@ -29,9 +35,21 @@
<height>471</height>
</size>
</property>
<layout class="QVBoxLayout" name="verticalLayout_6">
<layout class="QVBoxLayout" name="verticalLayout_6" stretch="1,1,1,0,1">
<property name="spacing">
<number>1</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetMinimumSize</enum>
</property>
<item>
<widget class="QGroupBox" name="motorSelection">
<property name="minimumSize">
<size>
<width>261</width>
<height>145</height>
</size>
</property>
<property name="title">
<string>Motor Selection</string>
</property>
@ -71,6 +89,9 @@
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Minimum</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
@ -81,6 +102,12 @@
</item>
<item>
<widget class="QGroupBox" name="motorControl">
<property name="minimumSize">
<size>
<width>261</width>
<height>339</height>
</size>
</property>
<property name="title">
<string>Motor Relative</string>
</property>
@ -100,12 +127,12 @@
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_6">
<item row="1" column="0">
<layout class="QGridLayout" name="step_grid">
<item row="2" column="0">
<widget class="QLabel" name="label_step_x">
<property name="minimumSize">
<size>
<width>108</width>
<width>111</width>
<height>19</height>
</size>
</property>
@ -118,7 +145,7 @@
<widget class="QSpinBox" name="spinBox_precision">
<property name="minimumSize">
<size>
<width>107</width>
<width>110</width>
<height>19</height>
</size>
</property>
@ -137,7 +164,7 @@
<widget class="QLabel" name="label_2">
<property name="minimumSize">
<size>
<width>108</width>
<width>111</width>
<height>19</height>
</size>
</property>
@ -146,11 +173,11 @@
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="spinBox_step">
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="spinBox_step_x">
<property name="minimumSize">
<size>
<width>107</width>
<width>110</width>
<height>19</height>
</size>
</property>
@ -171,11 +198,11 @@
</property>
</widget>
</item>
<item row="2" column="0">
<item row="3" column="0">
<widget class="QLabel" name="label_step_y">
<property name="minimumSize">
<size>
<width>108</width>
<width>111</width>
<height>19</height>
</size>
</property>
@ -184,11 +211,49 @@
</property>
</widget>
</item>
<item row="2" column="1">
<item row="3" column="1">
<widget class="QDoubleSpinBox" name="spinBox_step_y">
<property name="minimumSize">
<size>
<width>107</width>
<width>110</width>
<height>19</height>
</size>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="minimum">
<double>0.000000000000000</double>
</property>
<property name="maximum">
<double>99.000000000000000</double>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
</property>
<property name="value">
<double>1.000000000000000</double>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="minimumSize">
<size>
<width>111</width>
<height>19</height>
</size>
</property>
<property name="text">
<string>Old step</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="spinBox_step">
<property name="minimumSize">
<size>
<width>110</width>
<height>19</height>
</size>
</property>
@ -212,7 +277,7 @@
</layout>
</item>
<item>
<layout class="QGridLayout" name="gridLayout">
<layout class="QGridLayout" name="direction_grid">
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
@ -342,16 +407,25 @@
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Minimum</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>13</height>
<height>18</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QGroupBox" name="motorControl_absolute">
<property name="minimumSize">
<size>
<width>261</width>
<height>195</height>
</size>
</property>
<property name="title">
<string>Move Absolute</string>
</property>

View File

@ -225,17 +225,8 @@ class MotorApp(QWidget):
self.spinBox_precision.setValue(self.precision)
self.update_precision(self.precision)
def init_ui(self) -> None:
"""Setup all ui elements"""
# TODO can be separated to multiple functions
# Set default parameters
self.set_from_config()
##########################
# 2D Plot
##########################
def init_ui_plot_elements(self) -> None:
"""Initialize the plot elements"""
self.label_coorditanes = self.glw.addLabel(f"Motor position: (X, Y)", row=0, col=0)
self.plot_map = self.glw.addPlot(row=1, col=0)
self.limit_map = pg.ImageItem()
@ -257,17 +248,10 @@ class MotorApp(QWidget):
self.plot_map.addItem(self.saved_motor_map)
self.plot_map.showGrid(x=True, y=True)
##########################
# Motor General setting
##########################
# # TODO make function to update precision
# self.precision = 2 # self.spinBox_precision.value() # Define the decimal precision
##########################
# Motor movements signals
##########################
def init_ui_motor_control(self) -> None:
"""Initialize the motor control elements"""
# Directional buttons for relative movement
self.toolButton_right.clicked.connect(
lambda: self.move_motor_relative(self.motor_x, self.spinBox_step.value())
)
@ -292,36 +276,18 @@ class MotorApp(QWidget):
)
)
# Go absolute button
# self.pushButton_go_absolute.clicked.connect(self.save_absolute_coordinates)
self.pushButton_go_absolute.setShortcut("Ctrl+G")
self.pushButton_go_absolute.setToolTip("Ctrl+G")
# Set absolute coordinates
self.pushButton_set.clicked.connect(self.save_absolute_coordinates)
self.pushButton_set.setShortcut("Ctrl+D")
self.pushButton_set.setToolTip("Ctrl+D")
# Save Current coordinates
self.pushButton_save.clicked.connect(self.save_current_coordinates)
self.pushButton_save.setShortcut("Ctrl+S")
self.pushButton_save.setToolTip("Ctrl+S")
# Stop Button
self.pushButton_stop.clicked.connect(self.motor_thread.stop_movement)
self.pushButton_stop.setShortcut("Ctrl+X")
self.pushButton_stop.setToolTip("Ctrl+X")
# Enable/Disable GUI
self.motor_thread.move_finished.connect(lambda: self.enable_motor_controls(True))
# Update precision
# Precision update
self.spinBox_precision.valueChanged.connect(lambda x: self.update_precision(x))
##########################
# Motor Configs
##########################
# SpinBoxes - Motor Limits #TODO make spinboxes own limits updated, currently is [-1000, 1000]
def init_ui_motor_configs(self) -> None:
"""Limit and plot spinBoxes"""
# SpinBoxes change color to yellow before updated, limits are updated with update button
self.spinBox_x_min.valueChanged.connect(lambda: self.param_changed(self.spinBox_x_min))
@ -340,7 +306,7 @@ class MotorApp(QWidget):
lambda: self.param_changed(self.spinBox_scatter_size)
)
# Config updates
# Limit Update
self.pushButton_updateLimits.clicked.connect(
lambda: self.update_all_motor_limits(
x_limit=[self.spinBox_x_min.value(), self.spinBox_x_max.value()],
@ -348,6 +314,7 @@ class MotorApp(QWidget):
)
)
# Plot Update
self.pushButton_update_config.clicked.connect(
lambda: self.update_plot_setting(
max_points=self.spinBox_max_points.value(),
@ -356,12 +323,15 @@ class MotorApp(QWidget):
)
)
# TODO map with floats as well -> or decide system for higher precision
self.pushButton_enableGUI.clicked.connect(lambda: self.enable_motor_controls(True))
def init_ui_motor_connections(self) -> None:
# Signal from motor thread to update coordinates
self.motor_thread.coordinates_updated.connect(
lambda x, y: self.update_image_map(round(x, self.precision), round(y, self.precision))
)
# Motor connections
# Motor connections button
self.pushButton_connecMotors.clicked.connect(
lambda: self.connect_motor(
self.comboBox_motor_x.currentText(), self.comboBox_motor_y.currentText()
@ -374,7 +344,8 @@ class MotorApp(QWidget):
self.motorControl_absolute.setEnabled(False)
self.tabWidget_tables.setTabEnabled(1, False)
# Keyboard shortcuts
def init_keyboard_shortcuts(self) -> None:
"""Initialize the keyboard shortcuts"""
# Delete table entry
delete_shortcut = QShortcut(QKeySequence("Delete"), self)
@ -382,13 +353,37 @@ class MotorApp(QWidget):
delete_shortcut.activated.connect(self.delete_selected_row)
backspace_shortcut.activated.connect(self.delete_selected_row)
# Increase/decrease step
# Increase/decrease step #TODO has to be adapted for separate x and y
increase_shortcut = QShortcut(QKeySequence("Ctrl+A"), self)
decrease_shortcut = QShortcut(QKeySequence("Ctrl+Z"), self)
increase_shortcut.activated.connect(self.increase_step)
decrease_shortcut.activated.connect(self.decrease_step)
self.pushButton_enableGUI.clicked.connect(lambda: self.enable_motor_controls(True))
# Go absolute button
self.pushButton_go_absolute.setShortcut("Ctrl+G")
self.pushButton_go_absolute.setToolTip("Ctrl+G")
# Set absolute coordinates
self.pushButton_set.setShortcut("Ctrl+D")
self.pushButton_set.setToolTip("Ctrl+D")
# Save Current coordinates
self.pushButton_save.setShortcut("Ctrl+S")
self.pushButton_save.setToolTip("Ctrl+S")
# Stop Button
self.pushButton_stop.setShortcut("Ctrl+X")
self.pushButton_stop.setToolTip("Ctrl+X")
def init_ui(self) -> None:
"""Setup all ui elements"""
self.set_from_config() # Set default parameters
self.init_ui_plot_elements() # 2D Plot
self.init_ui_motor_control() # Motor Controls
self.init_ui_motor_configs() # Motor Configs
self.init_ui_motor_connections() # Motor Connections
self.init_keyboard_shortcuts() # Keyboard Shortcuts
def init_motor_map(self):
# Get motor limits