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

import Schedule object from python script

parent f70876e6
No related branches found
No related tags found
1 merge request!78Add scheduler GUI
Pipeline #72746 passed
......@@ -3,8 +3,9 @@
Graphical user interface for B-ASIC scheduler.
"""
from .main_window import *
from .scheduler import *
from logger import *
from main_window import *
from scheduler import *
#__all__ = ['main_window', 'scheduler']
__version__ = '0.1'
......
......@@ -8,35 +8,49 @@ Start main-window with start_gui().
import os, sys
import os
import sys
from pathlib import Path
from types import ModuleType
from typing import Any
from pprint import pprint
#from matplotlib.pyplot import bar
#from diagram import *
import logger
from importlib.machinery import SourceFileLoader
import inspect
# Qt/qtpy
import qtpy
from qtpy import uic, QtCore, QtGui, QtWidgets
from qtpy.QtCore import Qt, Slot, QSettings
from qtpy.QtCore import Qt, Slot, QSettings, QStandardPaths
from qtpy.QtGui import QCloseEvent
from qtpy.QtWidgets import QApplication, QMainWindow, QMessageBox, QAbstractButton
from qtpy.QtWidgets import (
QApplication, QMainWindow, QMessageBox, QFileDialog, QInputDialog)
# QGraphics and QPainter imports
from qtpy.QtWidgets import (
QGraphicsView, QGraphicsScene, QGraphicsWidget,
QGraphicsLayout, QGraphicsLinearLayout, QGraphicsGridLayout, QGraphicsLayoutItem, QGraphicsAnchorLayout,
QGraphicsItem, QGraphicsItemGroup, QGraphicsItemAnimation
)
QGraphicsItem, QGraphicsItemGroup, QGraphicsItemAnimation)
from qtpy.QtGui import (
QPaintEvent, QPainter, QPainterPath, QColor, QBrush, QPen, QFont, QPolygon,
QLinearGradient)
from qtpy.QtCore import (
QRect)
# B-ASIC
import logger
#import b_asic.schedule
from b_asic.schedule import Schedule
log = logger.getLogger()
# Debug struff
if __debug__:
log.setLevel('DEBUG')
if __debug__:
# Print some system version information
QT_API = os.environ.get('QT_API')
......@@ -89,27 +103,29 @@ class MainWindow(QMainWindow, Ui_MainWindow):
"""Schedule of an SFG with scheduled Operations."""
_settings: QSettings
_schedules: dict
def __init__(self):
"""Initialize Schedule-gui."""
super(MainWindow, self).__init__()
self._settings = QSettings()
self._schedules = {}
self._init_ui()
self._init_graphics_view()
def _init_ui(self) -> None:
"""Initialize the ui"""
self._settings = QSettings()
self.setupUi(self)
# Connect signals to slots
self.pushbutton_add.clicked.connect(self.callback_pushButton)
self.menu_load_sfg.triggered.connect(self.open)
self.menu_save_schedule.triggered.connect(self.save)
self.menu_quit.triggered.connect(self.close)
self.menu_node_info.triggered.connect(self.toggle_component_info)
self.splitter_center.splitterMoved.connect(self._splitter_center_moved)
self.pushbutton_add .clicked .connect(self.callback_pushButton)
self.menu_load_from_file.triggered .connect(self._load_schedule_from_pyfile)
self.menu_save_schedule .triggered .connect(self.save)
self.menu_quit .triggered .connect(self.close)
self.menu_node_info .triggered .connect(self.toggle_component_info)
self.splitter_center .splitterMoved .connect(self._splitter_center_moved)
# Setup event member functions
self.closeEvent = self._close_event
......@@ -141,10 +157,59 @@ class MainWindow(QMainWindow, Ui_MainWindow):
@Slot()
def callback_pushButton(self) -> None:
#diagram = Diagram()
self.printButtonPressed(self.tr('callback_pushButton'))
pass
@Slot()
def open(self) -> None:
def _load_schedule_from_pyfile(self) -> None:
abs_path_filename = QFileDialog.getOpenFileName(self, self.tr("Open python file"),
QStandardPaths.standardLocations(QStandardPaths.HomeLocation)[0],
self.tr("Python Files (*.py *.py3)"))
abs_path_filename = abs_path_filename[0]
if not abs_path_filename: # return if empty filename (QFileDialog was canceled)
return
log.debug('abs_path_filename = {}.'.format(abs_path_filename))
module_name = inspect.getmodulename(abs_path_filename)
if not module_name: # return if empty module name
log.error('Could not load module from file \'{}\'.'.format(abs_path_filename))
return
try:
module = SourceFileLoader(module_name, abs_path_filename).load_module()
except:
log.exception('Exception occurred. Could not load module from file \'{}\'.'.format(abs_path_filename))
return
schedule_obj_list = dict(inspect.getmembers(module, (lambda x: type(x) == Schedule)))
if not schedule_obj_list: # return if no Schedule objects in script
QMessageBox.warning(self,
self.tr('File not found'),
self.tr('Could not find any Schedule object in file \'{}\'.')
.format(os.path.basename(abs_path_filename)))
log.info('Could not find any Schedule object in file \'{}\'.'
.format(os.path.basename(abs_path_filename)))
return
ret_tuple = QInputDialog.getItem(self,
self.tr('Load object'),
self.tr('Found the following Schedule object(s) in file.)\n\n'
'Select an object to proceed:'),
schedule_obj_list.keys(),0,False)
if not ret_tuple[1]: # User canceled the operation
log.debug('Load schedule operation: user canceled')
return
#TODO: Unique hash keys
#TODO: self.open(schedule_obj_list[ret_tuple[0])
self._schedules[ret_tuple[0]] = schedule_obj_list[ret_tuple[0]]
pprint(self._schedules)
#@Slot()
def open(self, schedule: Schedule) -> None:
"""This method loads an SFG and create a base schedule in gui."""
#TODO: all
self.printButtonPressed('load_sfg()')
......@@ -199,6 +264,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
ret = box.exec_()
if ret == QMessageBox.StandardButton.Yes:
log.info('Exit: {}'.format(os.path.basename(__file__)))
event.accept()
else:
event.ignore()
......
......@@ -86,7 +86,7 @@
<property name="title">
<string>&amp;File</string>
</property>
<addaction name="menu_load_sfg"/>
<addaction name="menu_load_from_file"/>
<addaction name="menu_save_schedule"/>
<addaction name="separator"/>
<addaction name="menu_quit"/>
......@@ -160,13 +160,13 @@
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="menu_load_sfg"/>
<addaction name="menu_load_from_file"/>
<addaction name="menu_save_schedule"/>
<addaction name="menu_node_info"/>
</widget>
<action name="menu_load_sfg">
<action name="menu_load_from_file">
<property name="text">
<string>&amp;Load SFG...</string>
<string>&amp;Load schedule from file...</string>
</property>
<property name="toolTip">
<string>Load Signal Flow Graph</string>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment