From 3db4dc69af870156b03d021358d410d17c943f5f Mon Sep 17 00:00:00 2001
From: Andreas Bolin <andbo467@student.liu.se>
Date: Mon, 4 Jul 2022 19:34:44 +0200
Subject: [PATCH] workspace dump

---
 b_asic/schedule-gui/__init__.py    |  5 ++
 b_asic/schedule-gui/diagram.py     | 41 +++++++++++++
 b_asic/schedule-gui/diagram2.py    | 31 ++++++++++
 b_asic/schedule-gui/main_window.py | 98 ++++++++++++++++++++----------
 b_asic/schedule-gui/main_window.ui | 92 ++++++++++++++++++----------
 5 files changed, 201 insertions(+), 66 deletions(-)
 create mode 100644 b_asic/schedule-gui/__init__.py
 create mode 100644 b_asic/schedule-gui/diagram.py
 create mode 100644 b_asic/schedule-gui/diagram2.py

diff --git a/b_asic/schedule-gui/__init__.py b/b_asic/schedule-gui/__init__.py
new file mode 100644
index 00000000..920e2e70
--- /dev/null
+++ b/b_asic/schedule-gui/__init__.py
@@ -0,0 +1,5 @@
+"""B-ASIC Scheduler-gui Module.
+
+Graphical user interface for B-ASIC scheduler.
+"""
+from b_asic.schedule-gui.main_window import *
\ No newline at end of file
diff --git a/b_asic/schedule-gui/diagram.py b/b_asic/schedule-gui/diagram.py
new file mode 100644
index 00000000..38e41b05
--- /dev/null
+++ b/b_asic/schedule-gui/diagram.py
@@ -0,0 +1,41 @@
+"""B-ASIC Schedule-gui Diagram Module.
+
+Contains the Diagram class for painting an schedule.
+"""
+# This Python file uses the following encoding: utf-8
+
+from qtpy import QtCore
+from qtpy import QtWidgets
+from qtpy.QtGui import (
+    QPaintEvent, QPainter, QPainterPath, QColor, QBrush, QPen, QFont, QPolygon,
+    QLinearGradient)
+from qtpy.QtWidgets import QCanvasView
+
+# QPaintEvent is a class
+class Diagram(QtWidgets.QWidget):
+
+    _antialiasing: bool = False
+
+    def __init__(self, parent):
+        pass
+
+    def add_component(self):
+        pass
+
+    def paintEvent(self, event):
+        # Create a few pen colors 
+        self.black = '#000000' 
+        self.blue = '#2041F1' 
+        self.green = '#12A708' 
+        self.purple = '#6512F0' 
+        self.red = '#E00C0C' 
+        self.orange = '#FF930A' 
+        
+        painter = QPainter(self)
+        #painter.Antialiasing(self._antialiasing)
+
+        painter.begin(self)
+        painter.drawLine(10, 10, 100, 100)
+
+        painter.end()
+
diff --git a/b_asic/schedule-gui/diagram2.py b/b_asic/schedule-gui/diagram2.py
new file mode 100644
index 00000000..1caf2947
--- /dev/null
+++ b/b_asic/schedule-gui/diagram2.py
@@ -0,0 +1,31 @@
+from qtpy import QtGui
+from qtpy.QtWidgets import QApplication, QMainWindow
+import sys
+from qtpy.QtGui import QPainter, QBrush, QPen
+from qtpy.QtCore import Qt
+
+class Window(QMainWindow):
+
+    def __init__(self):
+        super().__init__()
+        self.title = "PyQt5 Drawing Tutorial"
+        self.top= 150
+        self.left= 150
+        self.width = 500
+        self.height = 500
+        self.InitWindow()
+
+    def InitWindow(self):
+        self.setWindowTitle(self.title)
+        self.setGeometry(self.top, self.left, self.width, self.height)
+        self.show()
+    
+    def paintEvent(self, event):
+        painter = QPainter(self)
+        painter.setPen(QPen(Qt.green,  8, Qt.SolidLine))
+        painter.setBrush(QBrush(Qt.red, Qt.SolidPattern))
+        painter.drawEllipse(40, 40, 400, 400)
+
+App = QApplication(sys.argv)
+window = Window()
+sys.exit(App.exec())
\ No newline at end of file
diff --git a/b_asic/schedule-gui/main_window.py b/b_asic/schedule-gui/main_window.py
index 7424c82e..4da81442 100644
--- a/b_asic/schedule-gui/main_window.py
+++ b/b_asic/schedule-gui/main_window.py
@@ -1,66 +1,98 @@
-# This Python file uses the following encoding: utf-8
-"""B-ASIC Schedule-gui Main Window Module.
+"""B-ASIC Schedule-gui Module.
 
-This file opens the main window of the schedule-gui for B-ASIC when run.
+Contains the schedule-gui class for scheduling operations in an SFG.
 """
+# This Python file uses the following encoding: utf-8
+
 import os
 #from pathlib import Path
 import sys
 from typing import Any
 #from matplotlib.pyplot import bar
+#from diagram import *
 
+from qtpy import QtCore, QtGui, QtWidgets
+from qtpy.QtCore import Qt, Slot
 from qtpy.QtWidgets import QApplication, QMainWindow, QMessageBox
-#from qtpy.QtCore import QFile
+
+# QPainter imports
+from qtpy.QtWidgets import QGraphicsView, QGraphicsScene
+from qtpy.QtGui import (
+    QPaintEvent, QPainter, QPainterPath, QColor, QBrush, QPen, QFont, QPolygon,
+    QLinearGradient)
 
 
 
 class MainWindow(QMainWindow):
 
-    _test: int
-    _ui: Any
+    _ui: QMainWindow                            # <class '__main__.Ui_MainWindow'>
+    _widget: QMainWindow                # <class 'PyQt5.QtWidgets.QMainWindow'>
 
     def __init__(self):
         super(MainWindow, self).__init__()
-        self._test = 5
-        self.init_ui()
+        self._init_ui()
+        self._init_graphics_view()
+
+    def _init_ui(self):
+        QT_API = os.environ.get('QT_API')
+        print("QT_API: " + QT_API)
 
-    def init_ui(self):
         from qtpy import uic
         #uic.compileUiDir('.', False, \
         #    lambda dir, file : [dir+str('/ui/'), str('ui_')+file],)
-        _ui = uic.loadUi("main_window.ui", self)    # Load the .ui file
-        _ui.pushButton.clicked.connect(self.callback_pushButton)
-        _ui.actionLoad_SFG.triggered.connect(self.callback_menu_load_SFG)
-        _ui.actionSave_schedule.triggered.connect(self.callback_menu_save_schedule)
-        _ui.actionQuit.triggered.connect(self.close)
-        _ui.actionNode_info.triggered.connect(self.callback_menu_node_info)
-        #_ui.actionNode_info.triggered.connect(self.update_statusbar)
-
-        print(type(_ui))
-        #_ui, _base_class = uic.loadUiType("main_window_ui.ui", None)    # Load the .ui file
-        #print(type(_base_class))
-        print(type(self._test))
-        QT_API = os.environ.get('QT_API')
-        print("QT_API: " + QT_API)
 
+        # self._ui = uic.loadUi("main_window.ui", None)    # Load the .ui file
+        # #self._ui.setupUi(self)
+        # print('self:\t\t' + str(type(self)))
+        # print('self._ui:\t' + str(type(self._ui)))
+        # self._ui.pushbutton_add.clicked.connect(self.callback_pushButton)
+        # self._ui.menu_load_sfg.triggered.connect(self.load_sfg)
+        # self._ui.menu_save_schedule.triggered.connect(self.save_schedule)
+        # self._ui.menu_quit.triggered.connect(self._ui.close)
+        # self._ui.menu_node_info.triggered.connect(self.toggle_node_info)
+        # self._ui.show()
+        
+        uic.loadUi("main_window.ui", self)    # Load the .ui file
+        self.pushbutton_add.clicked.connect(self.callback_pushButton)
+        self.menu_load_sfg.triggered.connect(self.load_sfg)
+        self.menu_save_schedule.triggered.connect(self.save_schedule)
+        self.menu_quit.triggered.connect(self.close)
+        self.menu_node_info.triggered.connect(self.toggle_node_info)
+        self.show()
+
+        #print('self:\t\t' + str(type(self)))
+
+    def _init_graphics_view(self):
+        self.scene = QGraphicsScene(self)
+        self.graphic_view = QGraphicsView(self.scene, self)
+        self.graphic_view.setRenderHint(QPainter.Antialiasing)
+        self.graphic_view.setGeometry(20, 20, self.width(), self.height())
+        self.graphic_view.setDragMode(QGraphicsView.RubberBandDrag)
+    
+
+    @Slot()
     def callback_pushButton(self):
+        #diagram = Diagram()
         self.printButtonPressed('callback_pushButton')
-
-    def callback_menu_load_SFG(self):
-        self.printButtonPressed('callback_menu_load_SFG')
+    
+    @Slot()
+    def load_sfg(self):
+        self.printButtonPressed('load_sfg()')
         self.update_statusbar('SFG loaded successfully')
     
-    def callback_menu_save_schedule(self):
-        self.printButtonPressed('callback_menu_save_schedule')
+    @Slot()
+    def save_schedule(self):
+        self.printButtonPressed('save_schedule()')
         self.update_statusbar('Schedule saved successfully')
     
-    def callback_menu_node_info(self, checked: bool):
+    @Slot(bool)
+    def toggle_node_info(self, checked: bool):
         #if _ui.actionNode_info.
         print(type(checked))
         print(checked)
-        self.printButtonPressed('callback_menu_node_info')
+        self.printButtonPressed('toggle_node_info()')
         #self.update_statusbar()
-
+    
 
     def printButtonPressed(self, func_name: str):
         self.label_2.setText("hello")
@@ -75,8 +107,8 @@ class MainWindow(QMainWindow):
 
 def start_gui():
     app = QApplication(sys.argv)
-    widget = MainWindow()
-    widget.show()
+    window = MainWindow()
+    #window.show()
     sys.exit(app.exec_())
 
 if __name__ == "__main__":
diff --git a/b_asic/schedule-gui/main_window.ui b/b_asic/schedule-gui/main_window.ui
index 9be1254c..a4de5189 100644
--- a/b_asic/schedule-gui/main_window.ui
+++ b/b_asic/schedule-gui/main_window.ui
@@ -23,14 +23,18 @@
    </size>
   </property>
   <property name="windowTitle">
-   <string>MainWindow</string>
+   <string>B-ASIC scheduler</string>
+  </property>
+  <property name="windowIcon">
+   <iconset>
+    <normaloff>../../small_logo.png</normaloff>../../small_logo.png</iconset>
   </property>
   <widget class="QWidget" name="centralwidget">
    <widget class="QScrollArea" name="scrollArea">
     <property name="geometry">
      <rect>
-      <x>150</x>
-      <y>90</y>
+      <x>80</x>
+      <y>100</y>
       <width>461</width>
       <height>351</height>
      </rect>
@@ -47,24 +51,11 @@
        <height>349</height>
       </rect>
      </property>
-     <widget class="QPushButton" name="pushButton">
-      <property name="geometry">
-       <rect>
-        <x>120</x>
-        <y>110</y>
-        <width>83</width>
-        <height>25</height>
-       </rect>
-      </property>
-      <property name="text">
-       <string>PushButton</string>
-      </property>
-     </widget>
      <widget class="QLabel" name="label_2">
       <property name="geometry">
        <rect>
-        <x>50</x>
-        <y>40</y>
+        <x>10</x>
+        <y>10</y>
         <width>62</width>
         <height>17</height>
        </rect>
@@ -88,6 +79,32 @@
      <string>label</string>
     </property>
    </widget>
+   <widget class="QPushButton" name="pushbutton_add">
+    <property name="geometry">
+     <rect>
+      <x>560</x>
+      <y>100</y>
+      <width>83</width>
+      <height>25</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>+</string>
+    </property>
+   </widget>
+   <widget class="QPushButton" name="pushbutton_remove">
+    <property name="geometry">
+     <rect>
+      <x>560</x>
+      <y>150</y>
+      <width>83</width>
+      <height>25</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>-</string>
+    </property>
+   </widget>
   </widget>
   <widget class="QMenuBar" name="menubar">
    <property name="geometry">
@@ -102,33 +119,42 @@
     <property name="title">
      <string>&amp;File</string>
     </property>
-    <addaction name="actionLoad_SFG"/>
-    <addaction name="actionSave_schedule"/>
+    <addaction name="menu_load_sfg"/>
+    <addaction name="menu_save_schedule"/>
     <addaction name="separator"/>
-    <addaction name="actionQuit"/>
+    <addaction name="menu_quit"/>
    </widget>
    <widget class="QMenu" name="menuView">
     <property name="title">
      <string>&amp;View</string>
     </property>
-    <addaction name="actionNode_info"/>
+    <addaction name="menu_node_info"/>
+   </widget>
+   <widget class="QMenu" name="menu_Edit">
+    <property name="title">
+     <string>&amp;Edit</string>
+    </property>
    </widget>
    <addaction name="menuFile"/>
+   <addaction name="menu_Edit"/>
    <addaction name="menuView"/>
   </widget>
   <widget class="QStatusBar" name="statusbar"/>
-  <action name="actionLoad_SFG">
+  <action name="menu_load_sfg">
    <property name="text">
     <string>&amp;Load SFG...</string>
    </property>
    <property name="toolTip">
     <string>Load Signal Flow Graph</string>
    </property>
+   <property name="statusTip">
+    <string/>
+   </property>
    <property name="shortcut">
     <string>Ctrl+O</string>
    </property>
   </action>
-  <action name="actionSave_schedule">
+  <action name="menu_save_schedule">
    <property name="text">
     <string>&amp;Save schedule...</string>
    </property>
@@ -136,15 +162,7 @@
     <string>Ctrl+S</string>
    </property>
   </action>
-  <action name="actionQuit">
-   <property name="text">
-    <string>&amp;Quit</string>
-   </property>
-   <property name="shortcut">
-    <string>Ctrl+Q</string>
-   </property>
-  </action>
-  <action name="actionNode_info">
+  <action name="menu_node_info">
    <property name="checkable">
     <bool>true</bool>
    </property>
@@ -155,6 +173,14 @@
     <string>Ctrl+I</string>
    </property>
   </action>
+  <action name="menu_quit">
+   <property name="text">
+    <string>&amp;Quit</string>
+   </property>
+   <property name="shortcut">
+    <string>Ctrl+Q</string>
+   </property>
+  </action>
  </widget>
  <resources/>
  <connections/>
-- 
GitLab