mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-14 03:31:50 +02:00
feat: comboBox to switch between entries mode
This commit is contained in:
@ -508,6 +508,19 @@
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
@ -516,20 +529,17 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="radioButton_individual">
|
||||
<property name="text">
|
||||
<string>Individuals</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="radioButton_start_stop">
|
||||
<property name="text">
|
||||
<string>Start/Stop</string>
|
||||
</property>
|
||||
<widget class="QComboBox" name="comboBox_mode">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Individual</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Start/Stop</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
|
@ -23,6 +23,7 @@ from PyQt5.QtWidgets import (
|
||||
)
|
||||
from PyQt5.QtWidgets import QShortcut
|
||||
from pyqtgraph.Qt import QtWidgets, uic, QtCore
|
||||
from PyQt5.QtWidgets import QMessageBox
|
||||
|
||||
from bec_lib.core import MessageEndpoints, BECMessage
|
||||
from bec_widgets.qt_utils import DoubleValidationDelegate
|
||||
@ -84,6 +85,9 @@ class MotorApp(QWidget):
|
||||
self.init_ui()
|
||||
self.tag_N = 1 # position label for saved coordinates
|
||||
|
||||
# State tracking for entries
|
||||
self.last_selected_index = -1
|
||||
|
||||
# Get all motors available
|
||||
self.motor_thread.retrieve_all_motors() # TODO link to combobox that it always refresh
|
||||
|
||||
@ -435,6 +439,9 @@ class MotorApp(QWidget):
|
||||
|
||||
self.pushButton_help.clicked.connect(self.show_help_dialog)
|
||||
|
||||
# Mode switch
|
||||
self.comboBox_mode.currentIndexChanged.connect(self.update_table_header)
|
||||
|
||||
def init_ui(self) -> None:
|
||||
"""Setup all ui elements"""
|
||||
|
||||
@ -542,6 +549,40 @@ class MotorApp(QWidget):
|
||||
self.toolButton_up.setShortcut("")
|
||||
self.toolButton_down.setShortcut("")
|
||||
|
||||
def update_table_header(self):
|
||||
current_index = self.comboBox_mode.currentIndex()
|
||||
|
||||
if self.tableWidget_coordinates.rowCount() > 0:
|
||||
msgBox = QMessageBox()
|
||||
msgBox.setIcon(QMessageBox.Warning)
|
||||
msgBox.setText(
|
||||
"Switching modes will delete all table entries. Do you want to continue?"
|
||||
)
|
||||
msgBox.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel)
|
||||
returnValue = msgBox.exec()
|
||||
|
||||
if returnValue == QMessageBox.Cancel:
|
||||
self.comboBox_mode.blockSignals(True) # Block signals
|
||||
self.comboBox_mode.setCurrentIndex(self.last_selected_index)
|
||||
self.comboBox_mode.blockSignals(False) # Unblock signals
|
||||
return
|
||||
|
||||
self.tableWidget_coordinates.setRowCount(0) # Wipe table
|
||||
|
||||
if current_index == 0: # 'individual' is selected
|
||||
self.tableWidget_coordinates.setColumnCount(5)
|
||||
self.tableWidget_coordinates.setHorizontalHeaderLabels(
|
||||
["Move", "Show", "Tag", "X", "Y"]
|
||||
)
|
||||
|
||||
elif current_index == 1: # 'start/stop' is selected
|
||||
self.tableWidget_coordinates.setColumnCount(7)
|
||||
self.tableWidget_coordinates.setHorizontalHeaderLabels(
|
||||
["Move", "Show", "Tag", "X [start]", "Y [start]", "X [end]", "Y [end]"]
|
||||
)
|
||||
|
||||
self.last_selected_index = current_index # Save the last selected index
|
||||
|
||||
def generate_table_coordinate(
|
||||
self, table: QtWidgets.QTableWidget, coordinates: tuple, tag: str = None, precision: int = 0
|
||||
) -> None:
|
||||
|
Reference in New Issue
Block a user