Skip to content
Snippets Groups Projects
Commit 93bf62c2 authored by Andreas Bolin's avatar Andreas Bolin
Browse files

better autocompile and more version debug msg

parent f0c6ca92
Branches
No related tags found
1 merge request!78Add scheduler GUI
Pipeline #72665 passed
# This Python file uses the following encoding: utf-8
"""B-ASIC Scheduler-gui Module. """B-ASIC Scheduler-gui Module.
Contains the scheduler-gui class for scheduling operations in an SFG. Contains the scheduler-gui class for scheduling operations in an SFG.
""" """
# This Python file uses the following encoding: utf-8
import os, sys import os, sys
from pathlib import Path from pathlib import Path
...@@ -11,6 +13,7 @@ from typing import Any ...@@ -11,6 +13,7 @@ from typing import Any
#from diagram import * #from diagram import *
from qtpy import uic, QtCore, QtGui, QtWidgets from qtpy import uic, QtCore, QtGui, QtWidgets
import qtpy
from qtpy.QtCore import Qt, Slot, QSettings from qtpy.QtCore import Qt, Slot, QSettings
from qtpy.QtGui import QCloseEvent from qtpy.QtGui import QCloseEvent
from qtpy.QtWidgets import QApplication, QMainWindow, QMessageBox from qtpy.QtWidgets import QApplication, QMainWindow, QMessageBox
...@@ -21,55 +24,47 @@ from qtpy.QtGui import ( ...@@ -21,55 +24,47 @@ from qtpy.QtGui import (
QPaintEvent, QPainter, QPainterPath, QColor, QBrush, QPen, QFont, QPolygon, QPaintEvent, QPainter, QPainterPath, QColor, QBrush, QPen, QFont, QPolygon,
QLinearGradient) 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__: 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. # Autocompile the .ui form to a python file.
try: try: # PyQt5, try autocompile
if QT_API.lower() == 'pyqt5': from qtpy.uic import compileUiDir
def _map_func(dir: str, file: str) -> tuple[str, str]: def _map_func(dir: str, file: str) -> tuple[str, str]:
file_base,_ = os.path.splitext(file) 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')
return (dir+'/ui/', file_base+'_ui.py') uic.compileUiDir('.', False, _map_func)
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: try:
from ui.main_window_ui import Ui_MainWindow from ui.main_window_ui import Ui_MainWindow
except ImportError: except: # Everything failed, exit
raise 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'")
elif QT_API.lower() == 'pyside2': os._exit(1)
# 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 + "'")
# Only availible when the form is compiled # Only availible when the form is compiled
from ui.main_window_ui import Ui_MainWindow from ui.main_window_ui import Ui_MainWindow
...@@ -192,13 +187,13 @@ class MainWindow(QMainWindow, Ui_MainWindow): ...@@ -192,13 +187,13 @@ class MainWindow(QMainWindow, Ui_MainWindow):
################ ################
#### Events #### #### Events ####
################ ################
def closeEvent(self, event: QCloseEvent) -> None: # def closeEvent(self, event: QCloseEvent) -> None:
"""Overloads QMainWindow default closeEvent(QCloseEvent) event""" # """Overloads QMainWindow default closeEvent(QCloseEvent) event"""
QMessageBox.StandardButton resBtn = QMessageBox::question( this, APP_NAME, # QMessageBox.StandardButton resBtn = QMessageBox::question( this, APP_NAME,
self.tr("Are you sure?\n"), # self.tr("Are you sure?\n"),
QMessageBox::Cancel | QMessageBox::No | QMessageBox::Yes, # QMessageBox::Cancel | QMessageBox::No | QMessageBox::Yes,
QMessageBox::Yes); # QMessageBox::Yes);
pass # pass
################################# #################################
...@@ -218,6 +213,7 @@ class MainWindow(QMainWindow, Ui_MainWindow): ...@@ -218,6 +213,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.statusbar.showMessage(msg) self.statusbar.showMessage(msg)
def start_gui(): def start_gui():
app = QApplication(sys.argv) app = QApplication(sys.argv)
window = MainWindow() window = MainWindow()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment