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

feat: delete coordinate table row by DELETE or BACKSPACE key

This commit is contained in:
wyzula-jan
2023-08-25 17:22:27 +02:00
parent 7575c91c99
commit 5dd0af6894
2 changed files with 38 additions and 12 deletions

View File

@ -285,6 +285,12 @@
<layout class="QVBoxLayout" name="verticalLayout_3"> <layout class="QVBoxLayout" name="verticalLayout_3">
<item> <item>
<widget class="QTableWidget" name="tableWidget_coordinates"> <widget class="QTableWidget" name="tableWidget_coordinates">
<property name="selectionMode">
<enum>QAbstractItemView::MultiSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<column> <column>
<property name="text"> <property name="text">
<string>Tag</string> <string>Tag</string>

View File

@ -9,6 +9,9 @@ from PyQt5.QtCore import pyqtSignal, Qt
from PyQt5.QtWidgets import QApplication, QWidget from PyQt5.QtWidgets import QApplication, QWidget
from pyqtgraph.Qt import QtWidgets, uic from pyqtgraph.Qt import QtWidgets, uic
from PyQt5.QtGui import QKeySequence
from PyQt5.QtWidgets import QShortcut
from bec_lib.core import MessageEndpoints, BECMessage from bec_lib.core import MessageEndpoints, BECMessage
@ -220,6 +223,12 @@ class MotorApp(QWidget):
self.motorControl_absolute.setEnabled(False) self.motorControl_absolute.setEnabled(False)
self.tabWidget_tables.setTabEnabled(1, False) self.tabWidget_tables.setTabEnabled(1, False)
# Keyboard shortcuts
delete_shortcut = QShortcut(QKeySequence("Delete"), self)
backspace_shortcut = QShortcut(QKeySequence("Backspace"), self)
delete_shortcut.activated.connect(self.delete_selected_row)
backspace_shortcut.activated.connect(self.delete_selected_row)
def init_motor_map(self): def init_motor_map(self):
# Get motor limits # Get motor limits
limit_x_min, limit_x_max = self.motor_thread.get_motor_limits(self.motor_x) limit_x_min, limit_x_max = self.motor_thread.get_motor_limits(self.motor_x)
@ -322,6 +331,15 @@ class MotorApp(QWidget):
) )
table.resizeColumnsToContents() table.resizeColumnsToContents()
def delete_selected_row(self):
selected_rows = self.tableWidget_coordinates.selectionModel().selectedRows()
# If you allow multiple selections, you may want to loop through all selected rows
for row in reversed(selected_rows): # Reverse to delete from the end
self.tableWidget_coordinates.removeRow(row.row())
print(f"deleted {selected_rows}")
def save_absolute_coordinates(self): def save_absolute_coordinates(self):
self.generate_table_coordinate( self.generate_table_coordinate(
self.tableWidget_coordinates, self.tableWidget_coordinates,
@ -357,18 +375,7 @@ class MotorControl(QThread):
super().__init__(parent) super().__init__(parent)
self.action = None self.action = None
self._initialize_motor()
self.motor_x, self.motor_y = None, None
self.current_x, self.current_y = None, None
self.motors_consumer = None
# Get all available motors in the client
self.all_motors = self.get_all_motors()
self.all_motors_names = self.get_all_motors_names()
self.retrieve_all_motors() # send motor list to GUI
self.target_coordinates = None
def motor_by_string(self, motor_x_name: str, motor_y_name: str) -> tuple: def motor_by_string(self, motor_x_name: str, motor_y_name: str) -> tuple:
motor_x_index = self.all_motors_names.index(motor_x_name) motor_x_index = self.all_motors_names.index(motor_x_name)
@ -483,6 +490,19 @@ class MotorControl(QThread):
def set_target_coordinates(self, target_coordinates: tuple) -> None: def set_target_coordinates(self, target_coordinates: tuple) -> None:
self.target_coordinates = target_coordinates self.target_coordinates = target_coordinates
def _initialize_motor(self) -> None:
self.motor_x, self.motor_y = None, None
self.current_x, self.current_y = None, None
self.motors_consumer = None
# Get all available motors in the client
self.all_motors = self.get_all_motors()
self.all_motors_names = self.get_all_motors_names()
self.retrieve_all_motors() # send motor list to GUI
self.target_coordinates = None
def _move_motor_coordinate(self) -> None: def _move_motor_coordinate(self) -> None:
"""Move the motor to the specified coordinates""" """Move the motor to the specified coordinates"""
status = scans.mv( status = scans.mv(