mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-12-31 11:11:17 +01:00
fix(general_app): adapted to new custom loader
This commit is contained in:
@@ -1,52 +1,48 @@
|
||||
import sys
|
||||
|
||||
from qtpy import PYSIDE6
|
||||
from qtpy.QtCore import QFile
|
||||
from qtpy.QtUiTools import QUiLoader
|
||||
from qtpy.QtWidgets import QApplication, QMainWindow
|
||||
|
||||
from bec_widgets.examples.plugin_example_pyside.tictactoe import TicTacToe
|
||||
from bec_widgets.widgets.bec_status_box.bec_status_box import BECStatusBox
|
||||
from bec_widgets.widgets.device_inputs import DeviceComboBox, DeviceLineEdit
|
||||
from bec_widgets.widgets.vscode.vscode import VSCodeEditor
|
||||
import webbrowser
|
||||
|
||||
from bec_widgets.utils import UILoader
|
||||
|
||||
|
||||
class CustomUiLoader(QUiLoader):
|
||||
def __init__(self, baseinstance):
|
||||
super(CustomUiLoader, self).__init__(baseinstance)
|
||||
self.custom_widgets = {
|
||||
"TicTacToe": TicTacToe,
|
||||
"VSCodeEditor": VSCodeEditor,
|
||||
"BECStatusBox": BECStatusBox,
|
||||
"DeviceLineEdit": DeviceLineEdit,
|
||||
"DeviceComboBox": DeviceComboBox,
|
||||
}
|
||||
class BECWebLinksMixin:
|
||||
@staticmethod
|
||||
def open_bec_docs():
|
||||
webbrowser.open("https://beamline-experiment-control.readthedocs.io/en/latest/")
|
||||
|
||||
self.baseinstance = baseinstance
|
||||
@staticmethod
|
||||
def open_bec_widgets_docs():
|
||||
webbrowser.open("https://bec.readthedocs.io/projects/bec-widgets/en/latest/")
|
||||
|
||||
def createWidget(self, class_name, parent=None, name=""):
|
||||
if class_name in self.custom_widgets:
|
||||
widget = self.custom_widgets[class_name](parent)
|
||||
widget.setObjectName(name)
|
||||
return widget
|
||||
return super(CustomUiLoader, self).createWidget(class_name, parent, name)
|
||||
@staticmethod
|
||||
def open_bec_bug_report():
|
||||
webbrowser.open("https://gitlab.psi.ch/groups/bec/-/issues/")
|
||||
|
||||
|
||||
class CustomMainWindow(QMainWindow):
|
||||
def __init__(self, ui_file, parent=None):
|
||||
super(CustomMainWindow, self).__init__(parent)
|
||||
self.load_ui(ui_file)
|
||||
class BECGeneralApp(QMainWindow):
|
||||
def __init__(self, parent=None):
|
||||
super(BECGeneralApp, self).__init__(parent)
|
||||
self.load_ui("general_app.ui")
|
||||
|
||||
self.resize(1280, 720)
|
||||
|
||||
self.ini_ui()
|
||||
|
||||
def ini_ui(self):
|
||||
self._hook_menubar()
|
||||
|
||||
def load_ui(self, ui_file):
|
||||
loader = CustomUiLoader(self)
|
||||
ui_file = QFile(ui_file)
|
||||
ui_file.open(QFile.ReadOnly)
|
||||
self.ui = loader.load(ui_file)
|
||||
ui_file.close()
|
||||
loader = UILoader(self)
|
||||
self.ui = loader.loader(ui_file)
|
||||
self.setCentralWidget(self.ui)
|
||||
|
||||
def _hook_menubar(self):
|
||||
self.ui.action_BEC_docs.triggered.connect(BECWebLinksMixin.open_bec_docs)
|
||||
self.ui.action_BEC_widgets_docs.triggered.connect(BECWebLinksMixin.open_bec_widgets_docs)
|
||||
self.ui.action_bug_report.triggered.connect(BECWebLinksMixin.open_bec_bug_report)
|
||||
|
||||
|
||||
def main(): # pragma: no cover
|
||||
from qtpy import PYSIDE6
|
||||
@@ -58,7 +54,7 @@ def main(): # pragma: no cover
|
||||
return
|
||||
|
||||
app = QApplication(sys.argv)
|
||||
main_window = CustomMainWindow("general_app.ui")
|
||||
main_window = BECGeneralApp()
|
||||
main_window.show()
|
||||
sys.exit(app.exec_())
|
||||
|
||||
|
||||
@@ -55,9 +55,9 @@
|
||||
<property name="title">
|
||||
<string>Help</string>
|
||||
</property>
|
||||
<addaction name="actionBEC_Docs"/>
|
||||
<addaction name="actionBEC_Widgets_Docs"/>
|
||||
<addaction name="actionBug_Report"/>
|
||||
<addaction name="action_BEC_docs"/>
|
||||
<addaction name="action_BEC_widgets_docs"/>
|
||||
<addaction name="action_bug_report"/>
|
||||
</widget>
|
||||
<addaction name="menuHelp"/>
|
||||
</widget>
|
||||
@@ -144,6 +144,83 @@
|
||||
</set>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="flags">
|
||||
<set>ItemIsSelectable|ItemIsDragEnabled|ItemIsDropEnabled|ItemIsUserCheckable
|
||||
</set>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="flags">
|
||||
<set>ItemIsSelectable|ItemIsDragEnabled|ItemIsDropEnabled|ItemIsUserCheckable
|
||||
</set>
|
||||
</property>
|
||||
</item>
|
||||
</item>
|
||||
<item>
|
||||
<property name="flags">
|
||||
<set>ItemIsSelectable|ItemIsDragEnabled|ItemIsDropEnabled|ItemIsUserCheckable</set>
|
||||
</property>
|
||||
<item>
|
||||
<property name="flags">
|
||||
<set>ItemIsSelectable|ItemIsDragEnabled|ItemIsDropEnabled|ItemIsUserCheckable
|
||||
</set>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="flags">
|
||||
<set>ItemIsSelectable|ItemIsDragEnabled|ItemIsDropEnabled|ItemIsUserCheckable
|
||||
</set>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="flags">
|
||||
<set>ItemIsSelectable|ItemIsDragEnabled|ItemIsDropEnabled|ItemIsUserCheckable
|
||||
</set>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="flags">
|
||||
<set>ItemIsSelectable|ItemIsDragEnabled|ItemIsDropEnabled|ItemIsUserCheckable
|
||||
</set>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="flags">
|
||||
<set>ItemIsSelectable|ItemIsDragEnabled|ItemIsDropEnabled|ItemIsUserCheckable
|
||||
</set>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="flags">
|
||||
<set>ItemIsSelectable|ItemIsDragEnabled|ItemIsDropEnabled|ItemIsUserCheckable
|
||||
</set>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="flags">
|
||||
<set>ItemIsSelectable|ItemIsDragEnabled|ItemIsDropEnabled|ItemIsUserCheckable
|
||||
</set>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="flags">
|
||||
<set>ItemIsSelectable|ItemIsDragEnabled|ItemIsDropEnabled|ItemIsUserCheckable
|
||||
</set>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="flags">
|
||||
<set>ItemIsSelectable|ItemIsDragEnabled|ItemIsDropEnabled|ItemIsUserCheckable
|
||||
</set>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="flags">
|
||||
<set>ItemIsSelectable|ItemIsDragEnabled|ItemIsDropEnabled|ItemIsUserCheckable
|
||||
</set>
|
||||
</property>
|
||||
</item>
|
||||
</item>
|
||||
<item>
|
||||
<property name="flags">
|
||||
@@ -230,7 +307,7 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<action name="actionBEC_Docs">
|
||||
<action name="action_BEC_docs">
|
||||
<property name="icon">
|
||||
<iconset theme="QIcon::ThemeIcon::DialogQuestion"/>
|
||||
</property>
|
||||
@@ -238,7 +315,7 @@
|
||||
<string>BEC Docs</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionBEC_Widgets_Docs">
|
||||
<action name="action_BEC_widgets_docs">
|
||||
<property name="icon">
|
||||
<iconset theme="QIcon::ThemeIcon::DialogQuestion"/>
|
||||
</property>
|
||||
@@ -246,7 +323,7 @@
|
||||
<string>BEC Widgets Docs</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionBug_Report">
|
||||
<action name="action_bug_report">
|
||||
<property name="icon">
|
||||
<iconset theme="QIcon::ThemeIcon::DialogError"/>
|
||||
</property>
|
||||
|
||||
Reference in New Issue
Block a user