-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui.py
140 lines (118 loc) · 4.44 KB
/
gui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/env python3
from datetime import datetime
from enum import Enum
from functools import partial
import argparse
import os
import random
import sys
import typing
import uuid
import viz
from fbs_runtime.application_context.PySide2 import ApplicationContext as AppCtx
from PySide2 import QtGui, QtWidgets
from PySide2.QtCore import (Qt, QUrl, Signal, Slot, QTimer, QObject)
from PySide2.QtGui import (
QColor,
QFont,
QPainter,
QPen,
QPixmap,
QTransform)
from PySide2.QtMultimedia import QMediaContent, QMediaPlayer, QSound, QSoundEffect
from PySide2.QtPrintSupport import *
from PySide2.QtQml import QQmlApplicationEngine
from PySide2.QtWidgets import *
EXPIRY_DATE = '9999-12-31'
class QHLine(QFrame):
def __init__(self, stretch):
super(QHLine, self).__init__()
self.setFrameShape(QFrame.HLine)
self.setFrameShadow(QFrame.Sunken)
sizepol = QtWidgets.QSizePolicy
policy = QtWidgets.QSizePolicy(sizepol.Expanding, sizepol.Fixed)
policy.setHorizontalStretch(stretch)
self.setSizePolicy(policy)
class QVLine(QFrame):
def __init__(self):
super(QVLine, self).__init__()
self.setFrameShape(QFrame.VLine)
self.setFrameShadow(QFrame.Sunken)
class Grid(QWidget):
def __init__(self, *args, **kwargs):
super(Grid, self).__init__(*args, **kwargs)
# make the widgets
layout = QGridLayout()
layout.addWidget(QLabel('template11'), 0, 0, 1, 1)
layout.addWidget(QComboBox(), 0, 1, 1, 1)
layout.addWidget(QHLine(), 1, 0, 1, 2)
layout.addWidget(QLabel('template2'), 2, 0, 1, 1)
layout.addWidget(QComboBox(), 2, 1, 1, 1)
self.setLayout(layout)
class MainWindow(QMainWindow):
def __init__(self, mainWidget):
QMainWindow.__init__(self)
self.setWindowTitle('BETA: app template version 0.0.1')
self.menu = self.menuBar()
self.file_menu = self.menu.addMenu('File')
self.file_menu = self.menu.addMenu('Edit')
self.help_menu = self.menu.addMenu('View')
self.help_menu = self.menu.addMenu('Help')
def showHelp():
helpBox = QMessageBox()
helpBox.setText(HELP_DICT)
helpButton = QPushButton('OK')
helpBox.setDefaultButton(helpButton)
helpBox.exec_()
help_action = QAction('How to use this program', self)
help_action.setStatusTip('How to use this program')
help_action.triggered.connect(showHelp)
self.help_menu.addAction(help_action)
exit_action = QAction('Exit', self)
exit_action.setShortcut('Ctrl+Q')
exit_action.triggered.connect(self.exit_app)
self.file_menu.addAction(exit_action)
self.setCentralWidget(mainWidget)
def closeEvent(self, event):
if DEV: event.accept()
if True: # PLACEHOLDER: add confirmation/cleanup dialogue here
event.accept()
else:
event.ignore()
@Slot()
def exit_app(self, checked):
QApplication.quit()
class AppContext(AppCtx):
def __init__(self, *args, **kwargs):
super(AppContext, self).__init__(*args, **kwargs)
self.session_id = str(uuid.uuid4()) # good for debugging
def run(self):
self.grid = Grid()
if DEV:
print('show DEV things here...')
self.mainWindow = MainWindow(self.grid)
self.mainWindow.resize(1600, 900)
self.mainWindow.show()
if not DEV and datetime.today().isoformat() > EXPIRY_DATE:
exitBox = QMessageBox()
exitBox.setText('This program is no longer available')
exitButton = QPushButton('OK')
exitBox.setDefaultButton(exitButton)
sys.exit(exitBox.exec_())
return self.app.exec_()
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--dev', '-d', help='''\
reveals some more widgets and does not send session\
data on program closing''')
parser.add_argument('--live', '-l',
help='enables live reloading when source code is changed',
action='store_true')
args = parser.parse_args()
if (args.dev is not None and (
args.dev.lower() in ('true', 't', 'tru', 'yes', 'y'))):
DEV = True
appctxt = AppContext() # 1. Instantiate AppCtx
appctxt.app.setStyle('Fusion')
exit_code = appctxt.run() # 2. Invoke appctxt.app.exec_()
sys.exit(exit_code)