diff --git a/b_asic/scheduler-gui/main_window.py b/b_asic/scheduler-gui/main_window.py index 8d77aa7726d3d0a0ec516ae754b4d39839a9997d..ed96d12ca6cee6ac3c5528882c03b82bc2e3b6e9 100644 --- a/b_asic/scheduler-gui/main_window.py +++ b/b_asic/scheduler-gui/main_window.py @@ -1,8 +1,10 @@ +# This Python file uses the following encoding: utf-8 """B-ASIC Scheduler-gui Module. Contains the scheduler-gui class for scheduling operations in an SFG. """ -# This Python file uses the following encoding: utf-8 + + import os, sys from pathlib import Path @@ -11,6 +13,7 @@ from typing import Any #from diagram import * from qtpy import uic, QtCore, QtGui, QtWidgets +import qtpy from qtpy.QtCore import Qt, Slot, QSettings from qtpy.QtGui import QCloseEvent from qtpy.QtWidgets import QApplication, QMainWindow, QMessageBox @@ -21,55 +24,47 @@ from qtpy.QtGui import ( QPaintEvent, QPainter, QPainterPath, QColor, QBrush, QPen, QFont, QPolygon, QLinearGradient) -# Debug stuff -QT_API = os.environ.get('QT_API') -print("QT_API: " + QT_API) -print("QT_VERSION: " + str(QtCore.qVersion())) -if QT_API.lower().startswith('pyqt'): print("PYQT_VERSION: " + str(Qt.PYQT_VERSION_STR)) + +# Debug struff if __debug__: + # Print some system version information + QT_API = os.environ.get('QT_API') + print('Qt version (runtime): ', str(QtCore.qVersion())) + print('Qt version (compiletime):', QtCore.__version__) + print('QT_API: ', QT_API) + if QT_API.lower().startswith('pyside'): + import PySide2 + print('PySide version: ', PySide2.__version__) + if QT_API.lower().startswith('pyqt'): + print('PyQt version: ', str(Qt.PYQT_VERSION_STR)) + print('QtPy version: ', qtpy.__version__) - # Compile the .ui form to a python file. - try: - if QT_API.lower() == 'pyqt5': - def _map_func(dir: str, file: str) -> tuple[str, str]: - file_base,_ = os.path.splitext(file) - print('DEBUG: Compile \'' + file_base + '.ui\' to \'' + os.getcwd() + '/ui/' + file_base + '_ui.py\'...') - return (dir+'/ui/', file_base+'_ui.py') - uic.compileUiDir('.', False, _map_func) + # Autocompile the .ui form to a python file. + try: # PyQt5, try autocompile + from qtpy.uic import compileUiDir + def _map_func(dir: str, file: str) -> tuple[str, str]: + file_base,_ = os.path.splitext(file) + return (dir+'/ui/', file_base+'_ui.py') + uic.compileUiDir('.', False, _map_func) + except: + try: # PySide2, try manual compile + import subprocess + OS = sys.platform + if OS.startswith('linux'): + cmds = ["mkdir -p ui", "pyside2-uic -o ui/main_window_ui.py main_window.ui"] + for cmd in cmds: + subprocess.call(cmd.split()) + else: + #TODO: Implement (startswith) 'win32', 'darwin' (MacOs) + raise SystemExit + except: # Compile failed, look for pre-compiled file try: from ui.main_window_ui import Ui_MainWindow - except ImportError: - raise - - elif QT_API.lower() == 'pyside2': - # try: - # from ui.main_window_ui import Ui_MainWindow - # except ImportError: - try: - import subprocess - OS = sys.platform - if OS.startswith('linux'): - cmds = ["mkdir -p ui", "pyside2-uic -o ui/main_window_ui.py main_window.ui"] - for cmd in cmds: - print('$ ' + cmd) - subprocess.call(cmd.split()) - else: - print('ERROR: Autocompile for ' + OS + ' is currently not supported.') - raise SystemExit - except: - raise - except: - print("ERROR: Could not import 'Ui_MainWindow'.") - print("ERROR: Can't autocompile under " + QT_API + " eviroment. Try to manual compile 'main_window.ui' to 'ui/main_window_ui.py'") - os._exit(1) - - - # Tell the user we are in debug mode. - argv = sys.orig_argv - argv.insert(1, '-O') - argv = ' '.join(argv) - print("DEBUG: Running in debug mode. To disable, start program with: '" + argv + "'") + except: # Everything failed, exit + print("ERROR: Could not import 'Ui_MainWindow'.") + print("ERROR: Can't autocompile under", QT_API, "eviroment. Try to manual compile 'main_window.ui' to 'ui/main_window_ui.py'") + os._exit(1) # Only availible when the form is compiled from ui.main_window_ui import Ui_MainWindow @@ -192,13 +187,13 @@ class MainWindow(QMainWindow, Ui_MainWindow): ################ #### Events #### ################ - def closeEvent(self, event: QCloseEvent) -> None: - """Overloads QMainWindow default closeEvent(QCloseEvent) event""" - QMessageBox.StandardButton resBtn = QMessageBox::question( this, APP_NAME, - self.tr("Are you sure?\n"), - QMessageBox::Cancel | QMessageBox::No | QMessageBox::Yes, - QMessageBox::Yes); - pass + # def closeEvent(self, event: QCloseEvent) -> None: + # """Overloads QMainWindow default closeEvent(QCloseEvent) event""" + # QMessageBox.StandardButton resBtn = QMessageBox::question( this, APP_NAME, + # self.tr("Are you sure?\n"), + # QMessageBox::Cancel | QMessageBox::No | QMessageBox::Yes, + # QMessageBox::Yes); + # pass ################################# @@ -218,6 +213,7 @@ class MainWindow(QMainWindow, Ui_MainWindow): self.statusbar.showMessage(msg) + def start_gui(): app = QApplication(sys.argv) window = MainWindow()