-
Notifications
You must be signed in to change notification settings - Fork 0
/
gm.py
115 lines (94 loc) · 3.61 KB
/
gm.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
#!/usr/bin/python3
import os
import sys
import PyQt5.QtCore as QtCore
from PyQt5.QtWidgets import (QApplication, QMainWindow, QWidget,
QDesktopWidget,
QHBoxLayout, QVBoxLayout,
QLabel, QComboBox, QPushButton)
from PyQt5.QtGui import QIcon
THIS_DIR = os.path.dirname(os.path.realpath(__file__))
sys.path.append(os.path.join(THIS_DIR, 'pylib'))
from Common import get_pixmap_from_base64
from resources import icon_png
class ChooseSystem(QMainWindow):
def __init__(self):
super().__init__()
self.system_path = None
# self.setWindowIcon( QIcon( 'images/icon.png' ) )
self.setWindowIcon(QIcon(get_pixmap_from_base64(icon_png)))
self.setWindowTitle('Choose system')
text = QLabel('Choose system')
systems = self.get_systems()
self.choose = choose = QComboBox(self)
for system in systems:
choose.addItem(*system)
button_layout = QHBoxLayout()
ok_button = QPushButton('OK', self)
ok_button.clicked.connect(self.ok)
cancel_button = QPushButton('Cancel', self)
cancel_button.clicked.connect(self.cancel)
button_layout.addStretch(1)
button_layout.addWidget(ok_button)
button_layout.addWidget(cancel_button)
layout = QVBoxLayout()
layout.addWidget(text, alignment=QtCore.Qt.AlignCenter)
layout.addWidget(choose, alignment=QtCore.Qt.AlignCenter)
layout.addLayout(button_layout)
central_widget = QWidget()
self.setCentralWidget(central_widget)
central_widget.setLayout(layout)
self.show()
self.center()
self.clearFocus()
ok_button.setFocus()
def center(self):
qt_rectangle = self.frameGeometry()
center_point = QDesktopWidget().availableGeometry().center()
qt_rectangle.moveCenter(center_point)
self.move(qt_rectangle.topLeft())
def get_systems(self):
systems = []
walk = os.walk(os.path.join(THIS_DIR, 'systems'))
for dir_tup in walk:
# print( dir_tup )
current_dir = dir_tup[0]
files = dir_tup[2]
if 'SystemSettings.py' in files:
# print( 'Bingo' )
ss_path = os.path.join(current_dir, 'SystemSettings.py')
with open(ss_path) as ss_file:
for line in ss_file:
if 'systemName' in line:
# print( line )
d = {}
exec(line, d, d)
# print( d['systemName'] )
systems.append((d['systemName'], current_dir))
break
return systems
def get_system_path(self):
return self.system_path
def set_system_path(self, system_path):
self.system_path = system_path
def ok(self):
self.close()
system_path = self.choose.currentData()
# self.w = MainWindow( system_path )
#sys.path.append(os.path.join(THIS_DIR, 'pylib'))
sys.path.append(system_path)
import Windows
self.w = Windows.MainWindow(system_path)
def cancel(self):
self.close()
if __name__ == '__main__':
app = QApplication(sys.argv)
cs = ChooseSystem()
# system_path = cs.get_system_path()
# print( system_path )
# if system_path is not None:
# sys.path.append( os.path.join( THIS_DIR, 'pylib' ) )
# sys.path.append( system_path )
# import Windows
# mw = Windows.MainWindow()
sys.exit(app.exec_())