This repository was archived by the owner on Apr 15, 2024. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathgui.py
More file actions
184 lines (125 loc) · 4.98 KB
/
Copy pathgui.py
File metadata and controls
184 lines (125 loc) · 4.98 KB
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/usr/bin/env python
import os
import webbrowser
from PySide import QtCore, QtGui
from PySide.QtUiTools import QUiLoader
import core
import define as DEFINE
import config as Config
import presets as Presets
_CURRENTPATH = os.path.dirname(os.path.realpath(__file__))
CONFIG = Config.getLauncherConfig()
class MainWindow(QtCore.QObject):
"""
Main window class of this tool.
"""
_windowName = DEFINE.windowName
_windowTitle = DEFINE.windowTitle
_windowHeight = DEFINE.windowHeight
_windowWidth = DEFINE.windowWidth
toolIcon = QtGui.QIcon(DEFINE.toolIconPath)
def __init__(self):
super(MainWindow, self).__init__()
self.UI = None
self.initGUI()
def show(self):
self.UI.show()
def initGUI(self):
loader = QUiLoader()
self.UI = loader.load(DEFINE.mainUIPath)
self.createPresetsList() # Create self.presetList <- QListView
self.setSignals()
self.UI.setObjectName(self._windowName)
self.UI.setWindowTitle(self._windowTitle)
self.UI.setWindowIcon(self.toolIcon)
self.setApplications()
self.setProjects()
self.resetWindowSize()
def setSignals(self):
# self.UI.projectComboBox.changed.connect(self.setApplications)
self.UI.appComboBox.currentIndexChanged.connect(self.setVersions)
self.UI.appComboBox.currentIndexChanged.connect(self.setOptions)
self.UI.launchPushButton.clicked.connect(self.launchApp)
def resetWindowSize(self):
self.UI.resize(self._windowWidth, self._windowHeight)
def createPresetsList(self):
data = Config.getUserConfig()
self.presetsList = QtGui.QListView()
model = Presets.PresetsListModel(data=data, config=CONFIG)
self.presetsList.setModel(model)
delegate = Presets.PresetsListDelegate()
self.presetsList.setItemDelegate(delegate)
self.presetsList.setFrameShadow(QtGui.QFrame.Plain)
layout = QtGui.QVBoxLayout()
layout.addWidget(self.presetsList)
self.UI.presets.setLayout(layout)
def setProjects(self):
self.UI.projectComboBox.clear()
self.UI.projectComboBox.addItems(CONFIG['projects'].keys())
def setApplications(self):
self.UI.appComboBox.clear()
for app in CONFIG['apps'].keys():
icon_path = CONFIG['apps'].get(app).get('icon')
if icon_path:
self.UI.appComboBox.addItem(QtGui.QIcon(icon_path[0]), app)
else:
self.UI.appComboBox.addItem(app)
def setVersions(self):
self.UI.versionComboBox.clear()
currentApp = self.UI.appComboBox.currentText()
for appItems in CONFIG['apps'].items():
if currentApp == appItems[0]:
versions = appItems[1].get('versions').keys()
self.UI.versionComboBox.addItems(versions)
def setOptions(self, app=''):
self.UI.optionComboBox.clear()
currentApp = self.UI.appComboBox.currentText()
for appItems in CONFIG['apps'].items():
if currentApp == appItems[0]:
options = appItems[1].get('options')
if options:
self.UI.optionComboBox.addItems(options)
else:
self.UI.optionComboBox.addItem('default')
def getTabIndexByTitle(self, tabWidget, title):
index = 0
while index < tabWidget.count():
if tabWidget.tabText(index) == title:
return index
index += 1
return None
def launchApp(self):
if self.presetsList.currentIndex() == self.getTabIndexByTitle(self.UI.mainTabWidget, 'Presets'):
preset = self.presetsList.row()
print preset
elif self.UI.mainTabWidget.currentIndex() == self.getTabIndexByTitle(self.UI.mainTabWidget, 'Launch'):
project = self.UI.projectComboBox.currentText()
app = self.UI.appComboBox.currentText()
version = self.UI.versionComboBox.currentText()
option = self.UI.optionComboBox.currentText()
words = ["\n[[ START LAUNCHING ]] :: ",app, version,"as", option, "mode, on", project, "project."]
print ' '.join(words)
exe = CONFIG.get('apps').get(app).get('versions').get(version)
if not exe:
print "[[ DEFINITION ERROR ]] :: The app exe is not defined."
return
cmds = []
if not option == 'default':
elemetns = [exe, option]
cmds = ' '.join(elemetns)
else:
cmds = exe
print "[[ LAUNCH CMDS ]] :: " + cmds[0]
try:
core.launch(cmds=cmds)
except:
import traceback
print traceback.format_exc()
def main():
import sys
app = QtGui.QApplication(sys.argv)
mainWindow = MainWindow()
mainWindow.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()