-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtool_main.py
More file actions
212 lines (155 loc) · 6.98 KB
/
tool_main.py
File metadata and controls
212 lines (155 loc) · 6.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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
import sys
import os
import json
from tool_ui_v1 import Ui_MainWindow
from PyQt5 import QtWidgets as qtw
from PyQt5 import QtCore as qtc
from PyQt5.QtWidgets import QFileDialog, QListWidgetItem, QTabWidget
from PyQt5.QtWidgets import QMessageBox
from PyQt5.QtWidgets import QListWidget
from PyQt5.QtWidgets import QWidget
from PyQt5.QtCore import QSettings
# CREATING A .JSON SAVE FILE FOR THE ADDED PROFILES / APPS
if not os.path.isfile('save.json'):
open("save.json", "a+")
# LOADS .JSON DATA INTO THE 'PROFILES' VARIABLE
try:
with open('save.json') as infile:
profiles = json.load(infile)
keys_list = []
for key in profiles:
keys_list.append(key)
print("Available profiles: ", keys_list)
except:
print('No Current Profiles')
profiles = {}
# CONNECTING TO THE ORIGINAL UI.PY
class tool_window(qtw.QMainWindow, Ui_MainWindow):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.setupUi(self)
# STYLING TWEAKS
if len(profiles) > 2:
self.tabWidget.setUsesScrollButtons(True)
# LOADING A WELCOME MESSAGE QLISTWIDGET
if profiles == {}:
self.tut_tab = qtw.QWidget()
self.tabWidget.addTab(self.tut_tab, "Get Started")
# CREATES LISTWIDGET WITHIN TAB
self.newTab_listWidget = qtw.QListWidget(self.tut_tab)
self.newTab_listWidget.setGeometry(qtc.QRect(12, 15, 310, 310))
self.newTab_listWidget.addItem("Hello!")
self.newTab_listWidget.addItem("Welcome to my BootUp Tool 1.0")
self.newTab_listWidget.addItem("To get started:")
self.newTab_listWidget.addItem("- Enter a Profile Name")
self.newTab_listWidget.addItem('- Hit Enter or click "Add Profile"')
self.newTab_listWidget.addItem("- Select any apps you wish to boot")
self.newTab_listWidget.addItem("- Rinse and repeat!")
self.tabWidget.setTabsClosable(False)
# lOADS ANY PREVIOUSLY SAVED ADDED PROFILES / APPS
i = 0
for key in profiles:
# CREATES A TAB FOR EACH PROFILE
self.new_tab = qtw.QWidget()
self.tabWidget.addTab(self.new_tab, key)
# CREATES A LIST WIDGET FOR EACH TAB
self.newTab_listWidget = qtw.QListWidget(self.new_tab)
self.newTab_listWidget.setGeometry(qtc.QRect(12, 15, 310, 310))
# APPENDS ANY APPS TO SAID TAB'S LIST WIDGET
for item in profiles[key]:
self.newTab_listWidget.addItem(item)
# SETS NEW OBJECT NAMES FOR ITERATION PURPOSES
self.new_tab.setObjectName(f"{key}")
self.newTab_listWidget.setObjectName(f"newTab_listWidget{i}")
i += 1
# PROFILE/TABS BUTTON FUNC / SPECS
self.proButton.clicked.connect(self.add_tab)
self.proNameEdit.returnPressed.connect(self.add_tab)
self.tabWidget.setMovable(False)
# EMITS THE INDEX OF WHICH TAB IS REQUESTING CLOSURE
self.tabWidget.tabCloseRequested.connect(self.remove_tab)
# APPLICATIONS/LISTS BUTTON FUNC / SPECS
self.appButton.clicked.connect(self.add_app)
# LAUNCH BUTTON FUNC
self.launchButton.clicked.connect(self.launch)
# BUTTON FUNCTIONS / METHODS
def add_tab(self):
# PROFILE NAME
proName = self.proNameEdit.text()
# EMPTY PROFILE NAME CHECKER
if proName == "":
msg = QMessageBox()
msg.setWindowTitle("Error")
msg.setText("Error: Profile name cannot be blank.")
msg.setIcon(QMessageBox.Warning)
x = msg.exec_()
# PRE-EXISTING PROFILE CHECKER
elif proName in profiles:
msg = QMessageBox()
msg.setWindowTitle("Error")
msg.setText("Error: Sorry, that profile already exists.")
msg.setIcon(QMessageBox.Warning)
x = msg.exec_()
self.proNameEdit.clear()
else:
# CREATES NEW TAB
self.new_tab = qtw.QWidget()
self.tabWidget.addTab(self.new_tab, f"{proName}")
self.proNameEdit.clear()
# CREATES LISTWIDGET WITHIN TAB
self.newTab_listWidget = qtw.QListWidget(self.new_tab)
self.newTab_listWidget.setGeometry(qtc.QRect(12, 15, 310, 310))
try:
if self.tabWidget.indexOf(self.tut_tab) == 0:
self.tabWidget.removeTab(0)
except:
pass
i = self.tabWidget.indexOf(self.new_tab)
# SAVES TAB WITH EMPTY LIST AS KEY VALUE PAIR IN .JSON SAVE FILE
profiles[proName] = []
with open('save.json', 'w') as outfile:
json.dump(profiles, outfile)
# SETS NEW OBJECT NAMES FOR ITERATION PURPOSES
self.new_tab.setObjectName(f"{proName}")
self.newTab_listWidget.setObjectName(f"newTab_listWidget{i}")
self.tabWidget.setTabsClosable(True)
if len(profiles) > 2:
self.tabWidget.setUsesScrollButtons(True)
def add_app(self):
# LAUNCHES FILE EXPLORER, RETURNS TUPLE: (FILENAME, FILE TYPE SPECIFICATIONS)
fileName = QFileDialog.getOpenFileName(self, 'Open file', 'c:\\', 'executables (*.exe)')
# GATHERS CURRENT TAB/LIST FOR APPENDING THE APP
current_tab_name = self.tabWidget.tabText(self.tabWidget.currentIndex())
print("Current tab Name: ", current_tab_name)
current_tab_index = self.tabWidget.currentIndex()
print("Current tab index: ", current_tab_index)
self.current_list = self.tabWidget.findChild(QListWidget, f"newTab_listWidget{current_tab_index}")
print(self.current_list)
# APPENDS APP TO TAB LIST AND .JSON SAVE FILE
profiles[current_tab_name].append(fileName[0])
self.current_list.addItem(fileName[0])
print("Added to List")
with open('save.json', 'w') as outfile:
json.dump(profiles, outfile)
def remove_tab(self, index):
self.removed_tab = self.tabWidget.tabText(index)
self.removed_tab_list = self.tabWidget.findChild(QListWidget, f"newTab_listWidget{index}")
del profiles[self.removed_tab]
# REMOVES TAB/LISTWIDGET FROM GUI
self.tabWidget.removeTab(index)
self.removed_tab_list.setParent(None)
i = 0
for self.list in self.tabWidget.findChildren(QListWidget):
self.list.setObjectName(f"newTab_listWidget{i}")
i += 1
with open('save.json', 'w') as outfile:
json.dump(profiles, outfile)
def launch(self):
current_tab_name = self.tabWidget.tabText(self.tabWidget.currentIndex())
for app in profiles[current_tab_name]:
os.startfile(app)
if __name__ == '__main__':
app = qtw.QApplication(sys.argv)
win = tool_window()
win.show()
app.exec_()