From 5461a8a8ce69f6e4a8980c11306d09ac892ec09d Mon Sep 17 00:00:00 2001
From: Andreas Bolin <2535580+andbo467@users.noreply.github.com>
Date: Tue, 5 Jul 2022 23:29:26 +0200
Subject: [PATCH] workspace dump

---
 b_asic/scheduler-gui/main_window.py  | 57 +++++++++++++++++++++++-----
 b_asic/scheduler-gui/resources_rc.py |  2 +-
 2 files changed, 48 insertions(+), 11 deletions(-)

diff --git a/b_asic/scheduler-gui/main_window.py b/b_asic/scheduler-gui/main_window.py
index 7d74f504..46213f49 100644
--- a/b_asic/scheduler-gui/main_window.py
+++ b/b_asic/scheduler-gui/main_window.py
@@ -8,13 +8,13 @@ import os
 from pathlib import Path
 import sys
 from typing import Any
+from pytest import ExitCode
 #from matplotlib.pyplot import bar
 #from diagram import *
 
 from qtpy import uic, QtCore, QtGui, QtWidgets
 from qtpy.QtCore import Qt, Slot
 from qtpy.QtWidgets import QApplication, QMainWindow, QMessageBox
-from PyQt5.uic import compileUi as comp
 
 # QPainter imports
 from qtpy.QtWidgets import QGraphicsView, QGraphicsScene
@@ -22,20 +22,58 @@ 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))
+
 if __debug__:
+    
+    # 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)
+            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 + "'")
 
-if __debug__:
-    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)
-
 
+# Only availible when the form is compiled
 from ui.main_window_ui import Ui_MainWindow
 
 
@@ -55,8 +93,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
         self._init_graphics_view()
 
     def _init_ui(self):
-        QT_API = os.environ.get('QT_API')
-        print("QT_API: " + QT_API)
+        
        
 
         # self._ui = uic.loadUi("main_window.ui", None)    # Load the .ui file
diff --git a/b_asic/scheduler-gui/resources_rc.py b/b_asic/scheduler-gui/resources_rc.py
index ad9a9908..7b09fbc1 100644
--- a/b_asic/scheduler-gui/resources_rc.py
+++ b/b_asic/scheduler-gui/resources_rc.py
@@ -6,7 +6,7 @@
 #
 # WARNING! All changes made in this file will be lost!
 
-from PyQt5 import QtCore
+from PySide2 import QtCore
 
 qt_resource_data = b"\
 \x00\x00\x9e\x1b\
-- 
GitLab