mirror of
https://github.com/bec-project/bec_widgets.git
synced 2026-03-05 00:12:49 +01:00
refactor: improvements to enum access
This commit is contained in:
@@ -596,7 +596,7 @@ class AdvancedDockArea(DockAreaWidget):
|
||||
origin_label=lambda n: profile_origin_display(n, namespace=namespace),
|
||||
quick_select_checked=quickselect_default,
|
||||
)
|
||||
if dialog.exec() != QDialog.Accepted:
|
||||
if dialog.exec() != QDialog.DialogCode.Accepted:
|
||||
return
|
||||
|
||||
name = dialog.get_profile_name()
|
||||
@@ -760,10 +760,10 @@ class AdvancedDockArea(DockAreaWidget):
|
||||
"Delete Profile",
|
||||
f"Are you sure you want to delete the profile '{name}'?\n\n"
|
||||
f"This action cannot be undone.",
|
||||
QMessageBox.Yes | QMessageBox.No,
|
||||
QMessageBox.No,
|
||||
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No,
|
||||
QMessageBox.StandardButton.No,
|
||||
)
|
||||
if reply != QMessageBox.Yes:
|
||||
if reply != QMessageBox.StandardButton.Yes:
|
||||
return
|
||||
|
||||
namespace = self.profile_namespace
|
||||
@@ -833,8 +833,9 @@ class AdvancedDockArea(DockAreaWidget):
|
||||
def _manage_dialog_closed(self):
|
||||
self.manage_widget.close()
|
||||
self.manage_widget.deleteLater()
|
||||
self.manage_dialog.deleteLater()
|
||||
self.manage_dialog = None
|
||||
if self.manage_dialog is not None:
|
||||
self.manage_dialog.deleteLater()
|
||||
self.manage_dialog = None
|
||||
self.toolbar.components.get_action("manage_workspaces").action.setChecked(False)
|
||||
|
||||
################################################################################
|
||||
|
||||
@@ -18,7 +18,7 @@ class ProfileComboBox(QComboBox):
|
||||
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
|
||||
self.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Fixed)
|
||||
self._quick_provider: Callable[[], list[str]] = list_quick_profiles
|
||||
|
||||
def set_quick_profile_provider(self, provider: Callable[[], list[str]]) -> None:
|
||||
@@ -48,9 +48,9 @@ class ProfileComboBox(QComboBox):
|
||||
idx = self.count() - 1
|
||||
|
||||
# Reset any custom styling
|
||||
self.setItemData(idx, None, Qt.FontRole)
|
||||
self.setItemData(idx, None, Qt.ToolTipRole)
|
||||
self.setItemData(idx, None, Qt.ForegroundRole)
|
||||
self.setItemData(idx, None, Qt.ItemDataRole.FontRole)
|
||||
self.setItemData(idx, None, Qt.ItemDataRole.ToolTipRole)
|
||||
self.setItemData(idx, None, Qt.ItemDataRole.ForegroundRole)
|
||||
|
||||
if active_profile and profile == active_profile:
|
||||
tooltip = "Active workspace profile"
|
||||
@@ -58,13 +58,15 @@ class ProfileComboBox(QComboBox):
|
||||
font = QFont(self.font())
|
||||
font.setItalic(True)
|
||||
font.setBold(True)
|
||||
self.setItemData(idx, font, Qt.FontRole)
|
||||
self.setItemData(idx, self.palette().highlight().color(), Qt.ForegroundRole)
|
||||
self.setItemData(idx, font, Qt.ItemDataRole.FontRole)
|
||||
self.setItemData(
|
||||
idx, self.palette().highlight().color(), Qt.ItemDataRole.ForegroundRole
|
||||
)
|
||||
tooltip = "Active profile (not in quick select)"
|
||||
self.setItemData(idx, tooltip, Qt.ToolTipRole)
|
||||
self.setItemData(idx, tooltip, Qt.ItemDataRole.ToolTipRole)
|
||||
self.setCurrentIndex(idx)
|
||||
elif profile not in quick_set:
|
||||
self.setItemData(idx, "Not in quick select", Qt.ToolTipRole)
|
||||
self.setItemData(idx, "Not in quick select", Qt.ItemDataRole.ToolTipRole)
|
||||
|
||||
# Restore selection if possible
|
||||
index = self.findText(current_text)
|
||||
|
||||
@@ -5,7 +5,6 @@ from qtpy.QtCore import QMimeData, Qt, Signal
|
||||
from qtpy.QtGui import QDrag
|
||||
from qtpy.QtWidgets import QHBoxLayout, QPushButton, QSizePolicy, QToolButton, QVBoxLayout, QWidget
|
||||
|
||||
from bec_widgets.utils.colors import get_theme_palette
|
||||
from bec_widgets.utils.error_popups import SafeProperty
|
||||
|
||||
|
||||
@@ -49,6 +48,8 @@ class CollapsibleSection(QWidget):
|
||||
|
||||
# Create header button
|
||||
self.header_button = QPushButton()
|
||||
# Apply theme variant for title styling
|
||||
self.header_button.setProperty("variant", "title")
|
||||
self.header_button.clicked.connect(self.toggle_expanded)
|
||||
|
||||
# Enable drag and drop for reordering
|
||||
@@ -72,7 +73,7 @@ class CollapsibleSection(QWidget):
|
||||
self.header_add_button.setFixedSize(28, 28)
|
||||
self.header_add_button.setToolTip("Add item")
|
||||
self.header_add_button.setVisible(show_add_button)
|
||||
self.header_add_button.setToolButtonStyle(Qt.ToolButtonIconOnly)
|
||||
self.header_add_button.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonIconOnly)
|
||||
self.header_add_button.setAutoRaise(True)
|
||||
|
||||
self.header_add_button.setIcon(material_icon("add", size=(28, 28), convert_to_pixmap=False))
|
||||
@@ -105,24 +106,6 @@ class CollapsibleSection(QWidget):
|
||||
self.header_button.setIcon(icon)
|
||||
self.header_button.setText(self.title)
|
||||
|
||||
# Get theme colors
|
||||
palette = get_theme_palette()
|
||||
text_color = palette.text().color().name()
|
||||
|
||||
self.header_button.setStyleSheet(
|
||||
f"""
|
||||
QPushButton {{
|
||||
font-weight: bold;
|
||||
text-align: left;
|
||||
margin: 0;
|
||||
padding: 0px;
|
||||
border: none;
|
||||
background: transparent;
|
||||
icon-size: 20px 20px;
|
||||
}}
|
||||
"""
|
||||
)
|
||||
|
||||
def toggle_expanded(self):
|
||||
"""Toggle the expanded state and update size policy"""
|
||||
self.expanded = not self.expanded
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from bec_lib.endpoints import MessageEndpoints
|
||||
from qtpy.QtCore import QEvent, QSize, Qt, QTimer
|
||||
@@ -34,7 +35,7 @@ from bec_widgets.widgets.progress.scan_progressbar.scan_progressbar import ScanP
|
||||
MODULE_PATH = os.path.dirname(bec_widgets.__file__)
|
||||
|
||||
# Ensure the application does not use the native menu bar on macOS to be consistent with linux development.
|
||||
QApplication.setAttribute(Qt.AA_DontUseNativeMenuBar, True)
|
||||
QApplication.setAttribute(Qt.ApplicationAttribute.AA_DontUseNativeMenuBar, True)
|
||||
|
||||
|
||||
class BECMainWindow(BECWidget, QMainWindow):
|
||||
@@ -43,16 +44,8 @@ class BECMainWindow(BECWidget, QMainWindow):
|
||||
SCAN_PROGRESS_WIDTH = 100 # px
|
||||
SCAN_PROGRESS_HEIGHT = 12 # px
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
parent=None,
|
||||
gui_id: str = None,
|
||||
client=None,
|
||||
window_title: str = "BEC",
|
||||
*args,
|
||||
**kwargs,
|
||||
):
|
||||
super().__init__(parent=parent, gui_id=gui_id, **kwargs)
|
||||
def __init__(self, parent=None, window_title: str = "BEC", **kwargs):
|
||||
super().__init__(parent=parent, **kwargs)
|
||||
|
||||
self.app = QApplication.instance()
|
||||
self.status_bar = self.statusBar()
|
||||
@@ -330,8 +323,8 @@ class BECMainWindow(BECWidget, QMainWindow):
|
||||
# Help menu
|
||||
help_menu = menu_bar.addMenu("Help")
|
||||
|
||||
help_icon = QApplication.style().standardIcon(QStyle.SP_MessageBoxQuestion)
|
||||
bug_icon = QApplication.style().standardIcon(QStyle.SP_MessageBoxInformation)
|
||||
help_icon = QApplication.style().standardIcon(QStyle.StandardPixmap.SP_MessageBoxQuestion)
|
||||
bug_icon = QApplication.style().standardIcon(QStyle.StandardPixmap.SP_MessageBoxInformation)
|
||||
|
||||
bec_docs = QAction("BEC Docs", self)
|
||||
bec_docs.setIcon(help_icon)
|
||||
|
||||
@@ -333,7 +333,7 @@ class PositionerBox2D(PositionerBoxBase):
|
||||
"tweak_decrease": self.ui.tweak_decrease_hor,
|
||||
"units": self.ui.units_hor,
|
||||
}
|
||||
elif device == "vertical":
|
||||
if device == "vertical":
|
||||
return {
|
||||
"spinner": self.ui.spinner_widget_ver,
|
||||
"position_indicator": self.ui.position_indicator_ver,
|
||||
@@ -346,8 +346,7 @@ class PositionerBox2D(PositionerBoxBase):
|
||||
"tweak_decrease": self.ui.tweak_decrease_ver,
|
||||
"units": self.ui.units_ver,
|
||||
}
|
||||
else:
|
||||
raise ValueError(f"Device {device} is not represented by this UI")
|
||||
raise ValueError(f"Device {device} is not represented by this UI")
|
||||
|
||||
def _device_ui_components(self, device: str):
|
||||
if device == self.device_hor:
|
||||
|
||||
@@ -125,7 +125,7 @@ class ScanControl(BECWidget, QWidget):
|
||||
# Label to reload the last scan parameters within scan selection group box
|
||||
self.toggle_layout = QHBoxLayout()
|
||||
self.toggle_layout.addSpacerItem(
|
||||
QSpacerItem(0, 0, QSizePolicy.Expanding, QSizePolicy.Fixed)
|
||||
QSpacerItem(0, 0, QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Fixed)
|
||||
)
|
||||
self.last_scan_label = QLabel("Restore last scan parameters", self.scan_selection_group)
|
||||
self.toggle = ToggleSwitch(parent=self.scan_selection_group, checked=False)
|
||||
@@ -133,12 +133,16 @@ class ScanControl(BECWidget, QWidget):
|
||||
self.toggle_layout.addWidget(self.last_scan_label)
|
||||
self.toggle_layout.addWidget(self.toggle)
|
||||
self.scan_selection_group.layout().addLayout(self.toggle_layout)
|
||||
self.scan_selection_group.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed)
|
||||
self.scan_selection_group.setSizePolicy(
|
||||
QSizePolicy.Policy.Preferred, QSizePolicy.Policy.Fixed
|
||||
)
|
||||
self.layout.addWidget(self.scan_selection_group)
|
||||
|
||||
# Scan control (Run/Stop) buttons
|
||||
self.scan_control_group = QWidget(self)
|
||||
self.scan_control_group.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed)
|
||||
self.scan_control_group.setSizePolicy(
|
||||
QSizePolicy.Policy.Preferred, QSizePolicy.Policy.Fixed
|
||||
)
|
||||
self.button_layout = QHBoxLayout(self.scan_control_group)
|
||||
self.button_run_scan = QPushButton("Start", self.scan_control_group)
|
||||
self.button_run_scan.setProperty("variant", "success")
|
||||
@@ -417,7 +421,7 @@ class ScanControl(BECWidget, QWidget):
|
||||
position = self.ARG_BOX_POSITION + (1 if self.arg_box is not None else 0)
|
||||
for group in groups:
|
||||
box = ScanGroupBox(box_type="kwargs", config=group)
|
||||
box.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed)
|
||||
box.setSizePolicy(QSizePolicy.Policy.Preferred, QSizePolicy.Policy.Fixed)
|
||||
self.layout.insertWidget(position + len(self.kwarg_boxes), box)
|
||||
self.kwarg_boxes.append(box)
|
||||
box.setVisible(not self._hide_kwarg_boxes)
|
||||
@@ -430,7 +434,7 @@ class ScanControl(BECWidget, QWidget):
|
||||
"""
|
||||
self.arg_box = ScanGroupBox(box_type="args", config=group)
|
||||
self.arg_box.device_selected.connect(self.emit_device_selected)
|
||||
self.arg_box.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed)
|
||||
self.arg_box.setSizePolicy(QSizePolicy.Policy.Preferred, QSizePolicy.Policy.Fixed)
|
||||
self.arg_box.hide_add_remove_buttons = self._hide_add_remove_buttons
|
||||
self.layout.insertWidget(self.ARG_BOX_POSITION, self.arg_box)
|
||||
self.arg_box.setVisible(not self._hide_arg_box)
|
||||
|
||||
@@ -209,7 +209,7 @@ class BECQueue(BECWidget, CompactPopupWidget):
|
||||
if not content or not isinstance(content, str):
|
||||
content = ""
|
||||
item = QTableWidgetItem(content)
|
||||
item.setTextAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
|
||||
item.setTextAlignment(Qt.AlignmentFlag.AlignHCenter | Qt.AlignmentFlag.AlignVCenter)
|
||||
# item.setFlags(item.flags() & ~Qt.ItemFlag.ItemIsEditable)
|
||||
|
||||
if status:
|
||||
|
||||
Reference in New Issue
Block a user