-
Notifications
You must be signed in to change notification settings - Fork 0
/
lightvj.py
132 lines (112 loc) · 4.68 KB
/
lightvj.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
import webbrowser
from PyQt5 import QtGui, QtWidgets, uic
from PyQt5.QtCore import Qt, QSettings, pyqtSignal, pyqtSlot
from PyQt5.QtWidgets import (QApplication, QDialog)
from qt_material import apply_stylesheet
from screens.MainWidget import mainWidget
from screens.about import About
QtWidgets.QApplication.setAttribute(Qt.AA_EnableHighDpiScaling, True)
# Main window
class MainWindow(QtWidgets.QMainWindow):
# menu bar creation
def _createMenuBar(self):
# filling up a menu bar
bar = self.menuBar()
# File menu
file_menu = bar.addMenu('File')
# adding actions to file menu
open_action = QtWidgets.QAction('Open', self)
save_action = QtWidgets.QAction('Save', self)
saveas_action = QtWidgets.QAction('Save as', self)
close_action = QtWidgets.QAction('Quit', self)
file_menu.addAction(open_action)
file_menu.addAction(save_action)
file_menu.addAction(saveas_action)
file_menu.addAction(close_action)
# Edit menu
edit_menu = bar.addMenu('Edit')
# adding actions to edit menu
set_action = QtWidgets.QAction('Settings', self)
edit_menu.addAction(set_action)
# Help menu
help_menu = bar.addMenu('Help')
# adding actions to edit menu
update_action = QtWidgets.QAction('Check for Updates', self)
guide_action = QtWidgets.QAction('Guide', self)
gh_action = QtWidgets.QAction('My Github', self)
about_action = QtWidgets.QAction('About LightVJ', self)
help_menu.addAction(update_action)
help_menu.addAction(guide_action)
help_menu.addAction(gh_action)
help_menu.addAction(about_action)
# use `connect` method to bind signals to desired behavior
close_action.triggered.connect(self.close)
set_action.triggered.connect(self.set_clicked)
gh_action.triggered.connect(lambda: webbrowser.open('https://github.com/maximoospital'))
about_action.triggered.connect(self.about_clicked)
# settings button functionality
def set_clicked(self, s):
button = Settings().exec_()
# about button functionality
def about_clicked(self, s):
dlg = About()
button = dlg.exec()
def __init__(self, parent=None):
super().__init__(parent)
# title, icon and size definition
self.setWindowTitle("LightVJ")
self.setWindowIcon(QtGui.QIcon('resources/lvjicon.png'))
self.mainWidget = mainWidget(parent=self)
self.setCentralWidget(self.mainWidget)
self._createMenuBar()
self.resize(640, 480)
self.settings = QSettings('Maximo Ospital', 'LightVJ')
# print(self.settings.fileName())
try:
self.resize(self.settings.value('window size'))
self.move(self.settings.value('window position'))
except:
pass
@pyqtSlot()
def CambioDeOpciones(self):
configuracion = QSettings('Maximo Ospital', 'LightVJ')
if configuracion.contains("theme"):
apply_stylesheet(app, theme=configuracion.value('theme'))
else:
apply_stylesheet(app, theme=configuracion.value('dark_red.xml'))
def closeEvent(self, event):
self.settings.setValue('window size', self.size())
self.settings.setValue('window position', self.pos())
class Settings(QDialog):
settingsSignal = pyqtSignal()
def apply(self):
self.settings.setValue('theme', self.theme.currentText())
apply_stylesheet(app, theme=self.settings.value('theme'))
apply_stylesheet(self, theme=self.settings.value('theme'))
def __init__(self, parent=None):
super().__init__(parent)
self.setWindowFlag(Qt.WindowStaysOnTopHint)
self.setWindowFlags(self.windowFlags() & (~Qt.WindowContextHelpButtonHint))
uic.loadUi('screens/settings.ui', self) # Load the .ui file
self.settings = QSettings('Maximo Ospital', 'LightVJ')
apply_stylesheet(self, theme=self.settings.value('theme'))
self.applybutton.clicked.connect(self.apply)
try:
self.move(self.settings.value('help window position'))
except:
pass
self.show() # Show the GUI
def closeEvent(self, event):
self.settings.setValue('help window position', self.pos())
if __name__ == '__main__':
import sys
app = QApplication(sys.argv)
# apply material style and show window
config = QSettings('Maximo Ospital', 'LightVJ')
if config.contains("theme"):
apply_stylesheet(app, theme=config.value('theme'))
else:
apply_stylesheet(app, theme=config.value('dark_red.xml'))
main = MainWindow()
main.show()
sys.exit(app.exec_())