-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
372 lines (311 loc) · 12.5 KB
/
main.py
File metadata and controls
372 lines (311 loc) · 12.5 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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
import asyncio
import os, sys
import time
from PyQt5 import uic, QtGui, QtCore
from PyQt5.QtWidgets import QApplication, QDialog, QMessageBox, QFileDialog, QSystemTrayIcon
from PyQt5.QtGui import QColor, QImageReader
from PyQt5.QtCore import QThread, pyqtSignal
import json
import shutil
from zipfile import ZipFile
import moviepy.editor as mp
global datas
datas = {}
def defaultThemeFolder() -> str:
"""returns path to opera's theme folder's default location"""
#
return fr"C:\Users\{os.getlogin()}\AppData\Roaming\Opera Software\Opera GX Stable\themes"
def setup():
path = ""
try:
os.mkdir(defaultThemeFolder())
path = defaultThemeFolder()
except FileExistsError:
path = defaultThemeFolder()
except:
path = getPath()
if path != "":
path = path+"\themes"
else:
os.system("cscript notif.vbs \"Couldn't fetch Opera GX profile directory automaticly, please specify it.")
app.exit()
quit()
config = open("assets\config.json", "w")
json.dump({"path":path, "infos":["", ""]}, config)
config.close()
class Setup(QDialog):
def __init__(self):
super(Setup, self).__init__()
uic.loadUi(r"assets\ui\getPath.ui", self)
self.setWindowIcon(app_icon)
print('ui loaded')
self.ok.clicked.connect(self.returnPath)
def seemsCorrect(self):
if ("Opera GX Stable" and "C:") in self.path.text():
#self.ok.setEnabled = True
print('ok')
return True
else:
#self.ok.setEnabled = False
return False
def returnPath(self):
if self.seemsCorrect():
global userPath
userPath = self.path.text()
self.close()
else:
print('Not ok')
msg = QMessageBox()
msg.setIcon(QMessageBox.Warning)
msg.setText("Invalid path")
msg.setInformativeText("The path you choosed doesn't match with an Opera GX folder")
msg.setWindowTitle("Error - Invalid path")
msg.setDetailedText("""So as to run ThemeMaker smoothly, you need to set a path to the Opera GX profile directory. This path will be stored on your local machine ONLY.
\n You can find this path by opening Opera GX, then typing opera://about in the search bar. Then copy the path named Profile.""")
msg.exec()
global userPath
userPath = ""
def getPath():
global userPath
print("test")
window = Setup()
window.exec()
del window
return userPath
class Updater(QThread):
updater = pyqtSignal()
def run(self):
while True:
self.updater.emit()
time.sleep(0.3)
class Credits(QDialog):
def __init__(self) -> None:
super(Credits, self).__init__()
uic.loadUi(fr'assets\ui\credits.ui', self)
self.setWindowIcon(app_icon)
self.ok.clicked.connect(self.close)
class mainWindow(QDialog):
currentTextColor = "ffffff"
currentShadowColor = "ffffff"
def __init__(self) -> None:
super(mainWindow, self).__init__()
uic.loadUi(fr'assets\ui\main.ui', self)
self.setWindowIcon(app_icon)
self.thread = Updater()
self.thread.updater.connect(self.updateGUI)
self.thread.start()
self.photoBrowse.clicked.connect(self.findPicture)
self.videoBrowse.clicked.connect(self.findVideo)
self.closeBtn.clicked.connect(app.exit)
self.credits.clicked.connect(self.seeCredits)
self.build.clicked.connect(self.nextStep)
self.build.setEnabled(False)
self.folder.clicked.connect(self.directory)
self.bug.clicked.connect(self.reportBug)
#get previous datas
try:
with open("assets\config.json", "r") as save:
datas = json.load(save)
datas = datas["infos"]
#attribuer les infos
self.themeName.setText(datas[0])
self.author.setText(datas[1])
self.version.setText(str(datas[2]))
self.url.setText(datas[3])
self.currentTextColor = datas[4]
self.currentShadowColor = datas[5]
except:
pass
self.textColor.setStyleSheet(f"background-color:#{self.currentTextColor};")
self.textColor.clicked.connect(self.changeTextColor)
self.shadowColor.setStyleSheet(f"background-color:#{self.currentShadowColor};")
self.shadowColor.clicked.connect(self.changeShadowColor)
def reportBug(self):
os.system("@start https://github.com/PetchouDev/ThemeMaker/issues/new")
def updateGUI(self):
version_ok = False
try :
int(self.version.text())
version_ok = True
except:
version_ok == False
if (self.author.text() == "") or (self.version.text() == "") or (not version_ok) or (self.themeName.text() == "") or (self.photoPath.text() == ""):
self.build.setEnabled(False)
else:
self.build.setEnabled(True)
def findPicture(self):
supportedFormats = QImageReader.supportedImageFormats()
text_filter = "Images ({})".format(" ".join(["*.{}".format(fo.data().decode()) for fo in supportedFormats]))
filename = QFileDialog.getOpenFileName(self, "Choose your main wallpaper", fr"C:\Users\{os.getlogin()}\Pictures", text_filter)
self.photoPath.setText(filename[0])
def findVideo(self):
text_filter = "Videos ({*.mov *.mp4 *.wmv *.avi *.avchd *.flv *.f4v *.swf *.mkv *.webm})"
filename = QFileDialog.getOpenFileName(self, "Choose your main wallpaper", fr"C:\Users\{os.getlogin()}\Videos", text_filter)
self.videoPath.setText(filename[0])
def seeCredits(self):
window = Credits()
window.exec()
del window
def nextStep(self):
global datas
datas["name"] = self.themeName.text()
datas["author"] = self.author.text()
datas["version"] = int(self.version.text())
datas["url"] = self.url.text()
datas["photo"] = self.photoPath.text()
datas["video"] = self.videoPath.text()
datas["tc"] = self.currentTextColor
datas["sc"] = self.currentShadowColor
with open("assets\config.json", "r") as file:
config = json.load(file)
config["infos"] = [datas["name"], datas["author"], datas["version"], datas["url"], datas["tc"], datas["sc"] ]
with open("assets\config.json", "w") as nexConfig:
json.dump(config, nexConfig)
self.close()
def directory(self):
with open("assets\config.json", "r") as saveFie:
temp = json.load(saveFie)
path = temp["path"]
del temp
print(path)
open("assets\showFolder.bat", "w").write(f'cd "{path}"\nstart . && exit')
os.system(f'@start assets\showFolder.bat')
def changeTextColor(self):
picker = ColorPicker(lightTheme=True, useAlpha=True)
result = picker.rgb2hex(picker.getColor())
self.currentTextColor = result
print(self.currentTextColor)
self.textColor.setStyleSheet(f"background-color:#{self.currentTextColor};")
def changeShadowColor(self):
picker = ColorPicker(lightTheme=True, useAlpha=True)
self.currentShadowColor = picker.rgb2hex(picker.getColor())
self.shadowColor.setStyleSheet(f"background-color:#{self.currentShadowColor};")
class maker(QThread):
updater = pyqtSignal(int, str)
error = pyqtSignal(str, str)
def run(self):
global datas
self.datas = datas
try:
asyncio.sleep(1)
self.updater.emit(0, "Creating temporary folder.")
try:
os.mkdir(r"assets\temp")
except:
pass
os.chdir(r"assets\temp")
time.sleep(1)
self.updater.emit(10, "Copying main wallpaper picture.")
separated = self.datas["photo"].split(".")
pictureFormat = separated[-1]
shutil.copyfile(self.datas["photo"], f"image.{pictureFormat}")
print('photo done !')
if self.datas["video"] == "":
self.updater.emit(40, "writing persona.ini file.")
else:
self.updater.emit(30, "Setting up video for theme (convertion to webm can take a few minutes).")
convert(self.datas["video"], "video.webm")
print('Video done !')
asyncio.sleep(1)
self.updater.emit(40, "writing persona.ini file")
open("persona.ini", "w").write(persona(self.datas["name"], self.datas["author"], self.datas["url"], self.datas["version"], pictureFormat, self.datas["video"], self.datas["tc"], self.datas["sc"]))
time.sleep(0.5)
self.updater.emit(50, "Building archive for theme.")
#shutil.make_archive(self.datas["name"], format='zip', root_dir='.')
files = os.listdir()
archive = ZipFile("archive.zip", "w")
print(os.listdir())
for file in files:
archive.write(file)
print(file+" added to package")
archive.close()
print('archive done')
with open("..\config.json", "r") as file:
config = json.load(file)
time.sleep(2)
self.updater.emit(85, "Moving theme to Opera GX themes folder.")
name = self.datas['name'].replace(" ", "-")
shutil.copyfile("archive.zip", config["path"]+f"\{name}.zip")
time.sleep(1)
self.updater.emit(95, "Clearing things up.")
for file in os.listdir():
os.remove(file)
print(file+" added to package")
time.sleep(1)
os.chdir("..\..\ ".replace(" ", ""))
try:
os.rmdir(r"assets\temp")
except:
pass
print("temporary folder removed successfully")
self.updater.emit(100, "All Done.")
except Exception as error:
self.error.emit("An error occured, please check your entries.", str(error))
class running(QDialog):
def __init__(self) -> None:
super(running, self).__init__()
uic.loadUi(r"assets\ui\running.ui", self)
self.setWindowIcon(app_icon)
self.progress.setValue(0)
self.task.setText("Wainting...")
self.maker = maker()
self.maker.error.connect(self.error)
self.maker.updater.connect(self.update)
self.maker.start()
def update(self, value, task):
self.progress.setValue(value)
self.task.setText(task)
if value == 100:
time.sleep(1)
msg = QMessageBox()
msg.setIcon(QMessageBox.Information)
msg.setText("Build complete")
msg.setInformativeText("Restart Opera GX then open quick configuration to apply it.")
msg.setWindowTitle("Complete")
msg.exec()
self.close()
def error(self, log, detailled):
msg = QMessageBox()
msg.setIcon(QMessageBox.Warning)
msg.setText("Entry error")
msg.setInformativeText(log)
msg.setWindowTitle("Error")
msg.setDetailedText(detailled)
msg.exec()
self.close()
def main():
while True:
window = mainWindow()
window.exec()
del window
global datas
if datas == {}:
app.exit()
quit()
window = running()
window.exec()
del window
if __name__ == '__main__':
if getattr(sys, 'frozen', False):
application_path = sys._MEIPASS
else:
application_path = os.path.dirname(os.path.abspath(__file__))
os.chdir(application_path)
from assets.tools import convert, persona
from assets.colorpicker import ColorPicker
app = QApplication([])
app.setApplicationName("ThemeMaker for OperaGX")
app_icon = QtGui.QIcon()
app_icon.addFile('assets\icon.png', QtCore.QSize(16,16))
app_icon.addFile('assets\icon.png', QtCore.QSize(24,24))
app_icon.addFile('assets\icon.png', QtCore.QSize(32,32))
app_icon.addFile('assets\icon.png', QtCore.QSize(48,48))
app_icon.addFile('assets\icon.png', QtCore.QSize(256,256))
app.setWindowIcon(app_icon)
try:
with open("assets\config.json", "r") as test:
pass
except:
setup()
main()
# button2.setStyleSheet("background-color:#ffffff;"