mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-14 03:31:50 +02:00
WIP qapp and bec widget POC adjustments
This commit is contained in:
@ -1,16 +1,58 @@
|
||||
import os
|
||||
|
||||
from qtpy.QtCore import QSize
|
||||
from qtpy.QtGui import QIcon
|
||||
from qtpy.QtWidgets import QApplication
|
||||
|
||||
import bec_widgets
|
||||
from bec_widgets.cli.rpc.rpc_register import RPCRegister
|
||||
from bec_widgets.utils import BECDispatcher
|
||||
|
||||
MODULE_PATH = os.path.dirname(bec_widgets.__file__)
|
||||
|
||||
|
||||
class BECQApplication(QApplication):
|
||||
def __init__(self, client=None, gui_id: str | None = None, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.client = None
|
||||
self.rpc_register = None
|
||||
self.dispatcher = None
|
||||
self.is_bec_app = None
|
||||
self.bec_props = None
|
||||
self.gui_id = None
|
||||
self.setup_bec_features()
|
||||
|
||||
def setup_bec_features(self):
|
||||
self.bec_props = {}
|
||||
self.is_bec_app = True
|
||||
print("[BECQApplication]: Features initialized.")
|
||||
self.dispatcher = BECDispatcher()
|
||||
self.rpc_register = RPCRegister()
|
||||
self.client = self.dispatcher.client
|
||||
self.gui_id = "1234"
|
||||
self.rpc_register.add_rpc(self)
|
||||
self.setup_icon()
|
||||
print("[BECQApplication]: Features initialized with BECDispatcher singleton.")
|
||||
|
||||
def inject_property(self, name, value):
|
||||
self.bec_props[name] = value
|
||||
print(f"[BECQApplication]: Injected property '{name}' = {value}")
|
||||
|
||||
def show_gui_id(self):
|
||||
print(f"[BECQApplication]: GUI ID: {self.gui_id}")
|
||||
|
||||
def setup_icon(self):
|
||||
icon = QIcon()
|
||||
icon.addFile(
|
||||
os.path.join(MODULE_PATH, "assets", "app_icons", "bec_widgets_icon.png"),
|
||||
size=QSize(48, 48),
|
||||
)
|
||||
self.setWindowIcon(icon)
|
||||
print("[BECQApplication]: Window icon set.")
|
||||
|
||||
def shutdown(self):
|
||||
self.dispatcher.disconnect_all()
|
||||
super().shutdown()
|
||||
|
||||
|
||||
def upgrade_to_becqapp():
|
||||
app = QApplication.instance()
|
||||
|
@ -1,5 +1,5 @@
|
||||
from qtpy.QtWidgets import QWidget, QLabel, QVBoxLayout, QApplication
|
||||
from bec_qapp import upgrade_to_becqapp
|
||||
from qtpy.QtWidgets import QApplication, QLabel, QVBoxLayout, QWidget
|
||||
|
||||
|
||||
class BECWidget(QWidget):
|
||||
|
@ -1,20 +1,19 @@
|
||||
import sys
|
||||
import os
|
||||
|
||||
from PySide6.QtWidgets import QMainWindow, QWidget, QVBoxLayout
|
||||
from PySide6.QtWidgets import QApplication
|
||||
|
||||
# Set this early!
|
||||
# os.environ["PYSIDE_DISABLE_INTERNAL_QT_WARNINGS"] = "1"
|
||||
|
||||
from qtpy.QtWidgets import QApplication
|
||||
from bec_widget import BECWidget
|
||||
from qtpy.QtWidgets import QMainWindow, QVBoxLayout, QWidget
|
||||
|
||||
from bec_widgets.examples.qapp_custom.bec_qapp import BECQApplication
|
||||
from bec_widgets.widgets.containers.main_window.main_window import BECMainWindow
|
||||
|
||||
|
||||
class DemoApp(QMainWindow):
|
||||
class DemoApp(BECMainWindow):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.setWindowTitle("Demo Application")
|
||||
self.setGeometry(100, 100, 600, 400)
|
||||
# self.setWindowTitle("Demo Application")
|
||||
# self.setGeometry(100, 100, 600, 400)
|
||||
|
||||
# Create an instance of BECWidget
|
||||
self.main_widget = QWidget(self)
|
||||
@ -31,9 +30,12 @@ class DemoApp(QMainWindow):
|
||||
self.main_widget.layout.addWidget(self.bec_widget_1)
|
||||
self.main_widget.layout.addWidget(self.bec_widget_2)
|
||||
|
||||
self.setWindowIcon(self.windowIcon())
|
||||
|
||||
|
||||
def main():
|
||||
app = QApplication(sys.argv)
|
||||
# app = BECQApplication(sys.argv)
|
||||
widget = DemoApp()
|
||||
widget.resize(400, 200)
|
||||
widget.show()
|
||||
|
@ -1,18 +1,89 @@
|
||||
import os
|
||||
|
||||
from bec_lib.logger import bec_logger
|
||||
from PySide6.QtCore import QSize
|
||||
from PySide6.QtGui import QAction, QActionGroup, QIcon
|
||||
from PySide6.QtWidgets import QFileDialog, QMessageBox, QStyle, QWidget
|
||||
from qtpy.QtCore import Qt
|
||||
from qtpy.QtWidgets import QApplication, QMainWindow
|
||||
|
||||
import bec_widgets
|
||||
from bec_widgets.cli.rpc.rpc_register import RPCRegister
|
||||
from bec_widgets.qt_utils.toolbar import MaterialIconAction
|
||||
from bec_widgets.utils.bec_widget import BECWidget
|
||||
from bec_widgets.utils.colors import apply_theme
|
||||
from bec_widgets.utils.container_utils import WidgetContainerUtils
|
||||
from bec_widgets.widgets.containers.dock.dock_area import BECDockArea
|
||||
from bec_widgets.widgets.containers.main_window.web_links import BECWebLinksMixin
|
||||
|
||||
logger = bec_logger.logger
|
||||
|
||||
|
||||
class BECMainWindow(BECWidget, QMainWindow):
|
||||
def __init__(self, gui_id: str = None, *args, **kwargs):
|
||||
def __init__(self, gui_id: str = None, default_widget=QWidget, *args, **kwargs):
|
||||
BECWidget.__init__(self, gui_id=gui_id, **kwargs)
|
||||
QMainWindow.__init__(self, *args, **kwargs)
|
||||
self.app = QApplication.instance()
|
||||
|
||||
self._init_ui()
|
||||
|
||||
def _init_ui(self):
|
||||
# Set the window title
|
||||
self.setWindowTitle("BEC")
|
||||
|
||||
# Set Menu and Status bar
|
||||
self._setup_menu_bar()
|
||||
self.statusBar().showMessage(f"App ID: {self.app.gui_id}")
|
||||
|
||||
def _setup_menu_bar(self):
|
||||
"""
|
||||
Setup the menu bar for the main window.
|
||||
"""
|
||||
menu_bar = self.menuBar()
|
||||
|
||||
########################################
|
||||
# Theme menu
|
||||
theme_menu = menu_bar.addMenu("Theme")
|
||||
|
||||
theme_group = QActionGroup(self)
|
||||
light_theme_action = QAction("Light Theme", self, checkable=True)
|
||||
dark_theme_action = QAction("Dark Theme", self, checkable=True)
|
||||
theme_group.addAction(light_theme_action)
|
||||
theme_group.addAction(dark_theme_action)
|
||||
theme_group.setExclusive(True)
|
||||
|
||||
theme_menu.addAction(light_theme_action)
|
||||
theme_menu.addAction(dark_theme_action)
|
||||
|
||||
# Connect theme actions
|
||||
light_theme_action.triggered.connect(lambda: self.change_theme("light"))
|
||||
dark_theme_action.triggered.connect(lambda: self.change_theme("dark"))
|
||||
|
||||
# Set the default theme
|
||||
# TODO can be fetched from app
|
||||
light_theme_action.setChecked(True)
|
||||
|
||||
########################################
|
||||
# Help menu
|
||||
help_menu = menu_bar.addMenu("Help")
|
||||
|
||||
help_icon = QApplication.style().standardIcon(QStyle.SP_MessageBoxQuestion)
|
||||
bug_icon = QApplication.style().standardIcon(QStyle.SP_MessageBoxInformation)
|
||||
|
||||
bec_docs = QAction("BEC Docs", self)
|
||||
bec_docs.setIcon(help_icon)
|
||||
widgets_docs = QAction("BEC Widgets Docs", self)
|
||||
widgets_docs.setIcon(help_icon)
|
||||
bug_report = QAction("Bug Report", self)
|
||||
bug_report.setIcon(bug_icon)
|
||||
|
||||
bec_docs.triggered.connect(BECWebLinksMixin.open_bec_docs)
|
||||
widgets_docs.triggered.connect(BECWebLinksMixin.open_bec_widgets_docs)
|
||||
bug_report.triggered.connect(BECWebLinksMixin.open_bec_bug_report)
|
||||
|
||||
help_menu.addAction(bec_docs)
|
||||
help_menu.addAction(widgets_docs)
|
||||
help_menu.addAction(bug_report)
|
||||
|
||||
def _dump(self):
|
||||
"""Return a dictionary with informations about the application state, for use in tests"""
|
||||
@ -38,6 +109,9 @@ class BECMainWindow(BECWidget, QMainWindow):
|
||||
}
|
||||
return info
|
||||
|
||||
def change_theme(self, theme):
|
||||
apply_theme(theme)
|
||||
|
||||
def new_dock_area(
|
||||
self, name: str | None = None, geometry: tuple[int, int, int, int] | None = None
|
||||
) -> BECDockArea:
|
||||
|
Reference in New Issue
Block a user