-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
armada_pipeline_installer.py
705 lines (580 loc) · 22.5 KB
/
armada_pipeline_installer.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
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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
"""
Module for prep asset popup.
"""
import os
import sys
import platform
import subprocess
import requests
import json
from Qt import QtCore
from Qt import QtWidgets
from Qt import QtGui
from core import definitions
from core import resource
from core import path_maker
from core.model import item_role
import utilsa
logging = utilsa.Logger('armada')
FULL, MOUNT, STRUCTURE = (1, 2, 3)
class ArmadaInstaller(QtWidgets.QDialog):
"""Downloads armada-pipeline release from GitHub repo
"""
# Signal vars
enter_pressed = QtCore.Signal(str)
enter_signal_str = "returnPressed"
esc_pressed = QtCore.Signal(str)
esc_signal_str = "escPressed"
download_complete = QtCore.Signal()
def __init__(self, setup=FULL):
"""
Args:
setup: What part of setup is the user entering into?
"""
super(ArmadaInstaller, self).__init__()
self.logger = logging.getLogger('menu.' + self.__class__.__name__)
self.logger.info('Setup starting...')
self.setup = setup
self.setObjectName('armada_Installer')
self.armada_root_path = definitions.ROOT_PATH
# self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
self.setWindowTitle('Armada Pipeline Installer')
self.setWindowIcon(resource.icon('armada_logo', 'png'))
self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
self.installEventFilter(self)
self.setStyleSheet(resource.style_sheet('setup'))
self.setFixedSize(1000, 500)
self.sizeHint()
# GUI ------------------------------
pixmap_banner = resource.pixmap(name='banner_setup', scope='help')
self.lbl_banner = QtWidgets.QLabel()
self.lbl_banner.setPixmap(pixmap_banner)
self.cb_style_sheet = """
QCheckBox::indicator:checked:disabled {{
image: url({0}/resources/icon/checkbox_unchecked.svg);
background: #29dff7;
}}
QCheckBox::indicator:unchecked:disabled{{
image: url({0}/resources/icon/checkbox_unchecked.svg);
}}
""".format(self.armada_root_path)
self.cb_s0_install = QtWidgets.QCheckBox('Install Armada Pipeline')
self.cb_s0_install.setStyleSheet(self.cb_style_sheet)
self.cb_s0_install.setEnabled(False)
self.cb_s1_download = QtWidgets.QCheckBox('Installing')
self.cb_s1_download.setStyleSheet(self.cb_style_sheet)
self.cb_s1_download.setEnabled(False)
self.cb_s2_complete = QtWidgets.QCheckBox('Installation Complete')
self.cb_s2_complete.setStyleSheet(self.cb_style_sheet)
self.cb_s2_complete.setEnabled(False)
self.lbl_title = QtWidgets.QLabel("Mount Point Setup")
# self.lbl_title.setSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.MinimumExpanding)
# self.lbl_title.setMinimumHeight(400)
self.lbl_title.setStyleSheet("""
QLabel {
font-size: 30px;
font-family: Roboto;
color: #FFFFFF;
}""")
# Mount point setup
self.lbl_install_dir = QtWidgets.QLabel()
self.lbl_install_dir.setText("Install to:")
self.lbl_install_dir.setStyleSheet(resource.style_sheet('setup'))
self.le_install_dir = QtWidgets.QLineEdit()
# Path defaults
if platform.system().lower() in ['windows']:
# install_dir = os.getenv('programdata').replace('\\', '/')
# install_dir = str(Path.home()).replace('\\', '/')
install_dir = "C:/Program Files"
elif platform.system().lower() in ['darwin']:
install_dir = "/Applications"
else:
raise
self.le_install_dir.setText(install_dir)
self.le_install_dir.setTextMargins(10, 5, 10, 5)
self.lbl_armada_ver = QtWidgets.QLabel()
self.lbl_armada_ver.setText("Armada Pipeline version:")
self.lbl_armada_ver.setStyleSheet(resource.style_sheet('setup'))
releases_url = 'https://api.github.com/repos/Armada-Pipeline/armada-pipeline/releases'
# header = {'Authorization': 'token ' + cred.token}
response = requests.get(releases_url)
json_data = json.loads(response.content)
self.armada_versions = []
for release in json_data:
if isinstance(release, str):
# self.armada_versions.append('v2020.09.02-beta')
self.armada_versions.append('v2020.09.15-beta')
break
elif release['target_commitish'] == 'master' and release['prerelease'] is False:
release_name = release['tag_name']
if release_name.startswith("v"):
self.armada_versions.append(release_name[1:])
else:
self.armada_versions.append(release_name)
self.cb_version_numbers = VersionsComboBox(self)
self.cb_version_numbers.addItems(self.armada_versions)
self.cb_version_numbers.setMinimumHeight(30)
self.cb_version_numbers.setStyleSheet(resource.style_sheet('setup'))
self.cb_version_numbers.setView(QtWidgets.QListView())
self.cb_version_numbers.view().window().setWindowFlags(QtCore.Qt.Popup | QtCore.Qt.FramelessWindowHint | QtCore.Qt.NoDropShadowWindowHint );
self.lbl_full_path = QtWidgets.QLabel()
self.lbl_full_path.setText("Full path:")
self.lbl_full_path.setStyleSheet(resource.style_sheet('setup'))
self.le_full_path = QtWidgets.QLabel()
serifFont = QtGui.QFont("Roboto", 10, QtGui.QFont.StyleItalic)
self.le_full_path.setFont(serifFont)
# self.le_full_path.setText('{0}/Armada Pipeline/armada_pipeline_{1}_win10'.format(self.le_install_dir.text(), self.armada_version))
self.le_full_path.setText('{0}/Armada Pipeline/'.format(self.le_install_dir.text()))
self.le_full_path.setWordWrap(True)
self.btn_install_browse = QtWidgets.QPushButton("Browse")
self.btn_install_browse.setMinimumWidth(100)
self.task_description = QtWidgets.QLabel()
self.progress_bar = QtWidgets.QProgressBar()
self.progress_bar.setMinimum(0)
self.progress_bar.setMaximum(100)
self.progress_bar.setAlignment(QtCore.Qt.AlignCenter)
self.btn_left = QtWidgets.QPushButton("Cancel")
btn_left_retain = self.btn_left.sizePolicy()
btn_left_retain.setRetainSizeWhenHidden(True)
self.btn_left.setSizePolicy(btn_left_retain)
self.btn_left.setStyleSheet("""
QPushButton{
background-color:#636363;
height: 30px;
}
QPushButton:hover{
background: #369593;
}
QPushButton:hover:pressed{
background: #2e7a78;
}
QPushButton:pressed{
background: #2a615f;
}
QPushButton:disabled{
background: #3b3b3b;
}
""")
self.btn_right = QtWidgets.QPushButton("Install")
self.btn_right.setStyleSheet("""
QPushButton{
background-color:#636363;
height: 30px;
border-style: solid;
border-width: 3px;
border-color: #369593;
}
QPushButton:hover{
background: #369593;
}
QPushButton:hover:pressed{
background: #2e7a78;
border-style: solid;
border-width: 3px;
border-color: #2e7a78;
}
QPushButton:pressed{
background: #2a615f;
}
QPushButton:disabled{
background: #3b3b3b;
border-style: solid;
border-width: 0px;
border-color: #4abdbb;
border-radius: 0px;
}
""")
self.btn_right.setDisabled(True)
self.lbl_description = QtWidgets.QTextBrowser()
self.lbl_description.setReadOnly(True)
self.lbl_description.setOpenExternalLinks(True)
self.lbl_description.setStyleSheet("""
QTextEdit {
background-color: #262626;
color: #FFFFFF;
font: 14px "Roboto-thin";
border: 0px;
}""")
# State machine ------------------
self.state_machine = QtCore.QStateMachine()
self.s0_install = QtCore.QState()
self.s1_download = QtCore.QState()
self.s2_complete = QtCore.QState()
# Entry point for setup
# Transitions
self.trans_s0_s1 = self.s0_install.addTransition(self.btn_right.clicked, self.s1_download)
self.trans_s1_s2 = self.s1_download.addTransition(self.btn_right.clicked, self.s2_complete)
# Add states
self.state_machine.addState(self.s0_install)
self.state_machine.addState(self.s1_download)
self.state_machine.addState(self.s2_complete)
self.state_machine.setInitialState(self.s0_install)
# Connections
self.s0_install.entered.connect(self.on_s0_install_entered)
self.s1_download.entered.connect(self.on_install_pressed)
self.s1_download.entered.connect(self.on_s1_download_entered)
self.s2_complete.entered.connect(self.on_s2_complete_entered)
# Properties
self.s0_install.assignProperty(self.btn_left, "text", "Cancel")
self.s0_install.assignProperty(self.btn_right, "text", "Install")
self.s1_download.assignProperty(self.btn_right, "text", "Next")
self.s2_complete.assignProperty(self.btn_right, "text", "Set Sail!")
self.state_machine.start()
# Layout ---------------------------
self.steps_layout = QtWidgets.QVBoxLayout()
self.steps_layout.addWidget(self.lbl_banner, 0, QtCore.Qt.AlignCenter | QtCore.Qt.AlignTop)
self.steps_layout.addWidget(self.cb_s0_install, 0, QtCore.Qt.AlignCenter)
self.steps_layout.addWidget(self.cb_s1_download, 0, QtCore.Qt.AlignCenter)
self.steps_layout.addWidget(self.cb_s2_complete, 0, QtCore.Qt.AlignCenter)
self.steps_layout.setContentsMargins(30, 30, 30, 100)
self.title_layout = QtWidgets.QHBoxLayout()
self.title_layout.addWidget(self.lbl_title)
# self.title_layout.setSizeConstraint(QtWidgets.QLayout.SetMinimumSize)
self.title_layout.setAlignment(QtCore.Qt.AlignCenter)
self.title_layout.setContentsMargins(20, 20, 20, 20)
self.armada_version_layout = QtWidgets.QHBoxLayout()
self.armada_version_layout.addWidget(self.lbl_armada_ver, 0, QtCore.Qt.AlignLeft)
self.armada_version_layout.addWidget(self.cb_version_numbers, 1, QtCore.Qt.AlignLeft)
self.armada_version_layout.setContentsMargins(0, 0, 0, 20)
# Mount point layout
self.install_dir_layout = QtWidgets.QHBoxLayout()
self.install_dir_layout.addWidget(self.lbl_install_dir, 0, QtCore.Qt.AlignLeft)
self.install_dir_layout.addWidget(self.le_install_dir, 1)
self.install_dir_layout.addWidget(self.btn_install_browse, 0, QtCore.Qt.AlignRight)
self.install_dir_layout.setAlignment(QtCore.Qt.AlignLeft)
self.full_path_layout = QtWidgets.QHBoxLayout()
self.full_path_layout.addWidget(self.lbl_full_path, 0, QtCore.Qt.AlignLeft)
self.full_path_layout.addWidget(self.le_full_path, 1)
self.full_path_layout.setContentsMargins(0, 20, 0, 20)
# Structure layout
self.description_layout = QtWidgets.QHBoxLayout()
self.description_layout.addWidget(self.lbl_description, 1, QtCore.Qt.AlignTop)
self.description_layout.setContentsMargins(0, 0, 0, 0)
self.button_layout = QtWidgets.QHBoxLayout()
self.button_layout.addWidget(self.btn_left)
self.button_layout.addWidget(self.btn_right)
self.button_layout.setAlignment(QtCore.Qt.AlignBottom)
self.button_layout.setContentsMargins(20, 20, 20, 20)
self.info_layout = QtWidgets.QVBoxLayout()
self.info_layout.addLayout(self.armada_version_layout)
self.info_layout.addLayout(self.description_layout)
self.info_layout.addLayout(self.install_dir_layout)
self.info_layout.addLayout(self.full_path_layout)
self.info_layout.setContentsMargins(30, 30, 30, 30)
self.user_layout = QtWidgets.QVBoxLayout()
self.user_layout.addLayout(self.title_layout)
self.user_layout.addLayout(self.info_layout)
self.user_layout.addWidget(self.task_description)
self.user_layout.addWidget(self.progress_bar)
self.user_layout.addLayout(self.button_layout, QtCore.Qt.AlignBottom)
self.main_layout = QtWidgets.QHBoxLayout()
self.main_layout.addLayout(self.steps_layout)
self.main_layout.addLayout(self.user_layout)
self.setLayout(self.main_layout)
# Connections
self.btn_install_browse.clicked.connect(self.on_browse_pressed)
self.le_install_dir.textChanged.connect(self.on_le_mount_text_changed)
self.esc_pressed.connect(self.on_cancel_pressed)
# Wait for user input
self.exec_()
def setProgress(self, value):
# print('progress value = {}'.format(value))
if value > 100:
value = 100
self.progress_bar.setValue(value)
def on_le_mount_text_changed(self, text):
"""
Remove banned characters from name string
"""
self.le_full_path.setText('{0}/Armada Pipeline'.format(self.le_install_dir.text()))
# Check if path exists
if os.path.exists(text):
self.btn_right.setEnabled(True)
else:
self.btn_right.setEnabled(False)
def on_browse_pressed(self):
self.file_dialog = QtWidgets.QFileDialog(self, directory=self.le_install_dir.text())
self.file_dialog.setFileMode(self.file_dialog.Directory)
path = self.file_dialog.getExistingDirectory(self, "Choose install directory")
if path == "":
pass
else:
self.le_install_dir.setText(path)
def on_s0_install_entered(self):
# Steps
self.cb_s0_style = """
QCheckBox::indicator:checked:disabled {{
image: url({0}/resources/icon/checkbox_unchecked.svg);
background: #29dff7;
}}
QCheckBox::indicator:unchecked:disabled{{
image: url({0}/resources/icon/checkbox_unchecked.svg);
}}
""".format(self.armada_root_path)
self.cb_s0_install.setChecked(True)
self.cb_s0_install.setStyleSheet(self.cb_s0_style)
self.cb_s2_complete.setChecked(False)
self.cb_s2_complete.setStyleSheet(self.cb_s0_style)
self.lbl_description.clear()
self.lbl_description.setHtml("""<p>Choose an installation directory:</p>""")
self.lbl_description.setFixedHeight(int(self.lbl_description.document().size().height()))
self.lbl_title.setText('Install Armada Pipeline')
try:
self.btn_right.clicked.disconnect(self.on_accept_pressed)
self.enter_pressed.disconnect(self.on_accept_pressed)
except:
pass
# S0
self.enter_pressed.connect(self.on_accept_pressed)
self.btn_left.clicked.connect(self.on_cancel_pressed)
# Global gui update
self.btn_right.setDisabled(False)
self.adjustSize()
def on_s1_download_entered(self):
# Steps
self.cb_s1_style = """
QCheckBox::indicator:checked:disabled {{
image: url({0}/resources/icon/checkbox_unchecked.svg);
background: #3693f6;
}}
QCheckBox::indicator:unchecked:disabled{{
image: url({0}/resources/icon/checkbox_unchecked.svg);
}}
""".format(self.armada_root_path)
self.cb_s1_download.setChecked(True)
self.cb_s1_download.setStyleSheet(self.cb_s1_style)
self.lbl_description.clear()
self.lbl_title.setText('Installing')
# Hide install path gui
self.lbl_install_dir.hide()
self.le_install_dir.hide()
self.btn_install_browse.hide()
self.lbl_full_path.hide()
self.le_full_path.hide()
self.install_dir_layout.setContentsMargins(0, 0, 0, 0)
self.lbl_armada_ver.hide()
self.cb_version_numbers.hide()
self.armada_version_layout.setContentsMargins(0, 0, 0, 0)
# S0
self.btn_left.hide()
self.adjustSize()
def on_s2_complete_entered(self):
# Steps
self.cb_s2_style = """
QCheckBox::indicator:checked:disabled {{
image: url({0}/resources/icon/checkbox_unchecked.svg);
background: #de6cff;
}}
QCheckBox::indicator:unchecked:disabled{{
image: url({0}/resources/icon/checkbox_unchecked.svg);
}}
""".format(self.armada_root_path)
self.cb_s2_complete.setChecked(True)
self.cb_s2_complete.setStyleSheet(self.cb_s2_style)
# Show mount gui
self.lbl_install_dir.hide()
self.le_install_dir.hide()
self.btn_install_browse.hide()
self.lbl_full_path.hide()
self.le_full_path.hide()
self.install_dir_layout.setContentsMargins(0, 0, 0, 0)
self.lbl_armada_ver.hide()
self.cb_version_numbers.hide()
self.armada_version_layout.setContentsMargins(0, 0, 0, 0)
self.lbl_description.clear()
self.lbl_description.setFixedHeight(int(self.lbl_description.document().size().toSize().width()))
self.lbl_description.setHtml("""
<p>You're ready to shove off! Bon voyage!<br>
</br>
<br></br>
<br></br>
Armada Pipeline v{0} was successfully installed in:</p>
<blockquote><i>{1}</i></blockquote>""".format(self.cb_version_numbers.currentText(), self.le_full_path.text()))
self.install_dir_layout.setContentsMargins(0, 0, 0, 0)
self.lbl_title.setText('Installation Complete')
self.progress_bar.hide()
self.task_description.hide()
# Global gui update
self.btn_right.setDisabled(False)
self.btn_right.clicked.connect(self.on_accept_pressed)
self.enter_pressed.connect(self.on_accept_pressed)
self.adjustSize()
def on_cancel_pressed(self):
"""Cancel button pressed
"""
import sys
sys.exit()
def on_install_pressed(self):
print('installing')
print(self.le_full_path.text())
# Make path
path_maker.make_dirs(self.le_full_path.text())
# Path defaults
if platform.system().lower() in ['windows']:
release_url = 'https://github.com/Armada-Pipeline/armada-pipeline/releases/download/v{0}/armada_pipeline_{0}_win10.zip'.format(self.cb_version_numbers.currentText())
os_type = 'win10'
elif platform.system().lower() in ['darwin']:
release_url = 'https://github.com/Armada-Pipeline/armada-pipeline/releases/download/v{0}/armada_pipeline_{0}_macos.zip'.format(self.cb_version_numbers.currentText())
os_type = 'macos'
else:
raise
save_path = '{0}/armada_pipeline_{1}.zip'.format(self.le_full_path.text(), os_type)
self.btn_left.setDisabled(True)
self.btn_right.setDisabled(True)
self.thread = DownloadThread(self, release_url, 'armada_pipeline.zip', save_path, self.le_full_path.text())
self.thread.update_gui.connect(self.on_update_gui)
self.thread.update_progress.connect(self.setProgress)
self.thread.set_extracted_dir.connect(self.on_set_extracted)
self.thread.start()
def on_set_extracted(self, str):
print('Extracted directory = {}'.format(str))
self.extracted_directory = str
self.btn_right.setDisabled(False)
def on_update_gui(self, text):
self.task_description.setText(text)
def on_accept_pressed(self):
"""Run Armada after installation
"""
install_dir = self.le_install_dir.text()
print(install_dir)
# from pyshortcuts import make_shortcut
#
# make_shortcut('/home/user/bin/myapp.py', name='MyApp',
# icon='/home/user/icons/myicon.ico', startmenu=True, desktop=True)
# Path defaults
if platform.system().lower() in ['windows']:
armada_exe = 'Armada Pipeline.exe'
elif platform.system().lower() in ['darwin']:
armada_exe = 'Armada Pipeline'
subprocess.Popen(os.path.join(self.extracted_directory, armada_exe))
self.close()
def keyPressEvent(self, event):
if event.key() == QtCore.Qt.Key_Return:
self.enter_pressed.emit(self.enter_signal_str)
return True
if event.key() == QtCore.Qt.Key_Escape:
self.esc_pressed.emit(self.esc_signal_str)
return True
else:
super(ArmadaInstaller, self).keyPressEvent(event)
def closeEvent(self, event):
self.deleteLater()
import urllib
import urllib.request
class DownloadThread(QtCore.QThread):
update_gui = QtCore.Signal(str)
update_progress = QtCore.Signal(float)
set_extracted_dir = QtCore.Signal(str)
def __init__(self, parent, url, tmp_file_name, save_path, le_full_path, ):
super(DownloadThread, self).__init__()
self.url = url
self.tmp_file_name = tmp_file_name
self.parent = parent
self.save_path = save_path
self.le_full_path = le_full_path
def run(self):
# Set the text to the current task
self.update_gui.emit("Gatherin' booty... (Downloading)")
# Download data
u = urllib.request.urlopen(self.url)
meta = u.info()
file_size = int(meta.get('Content-Length'))
params = meta.get('Content-Disposition')
filename = params.split('; filename=')[1]
f = open(self.save_path, 'wb')
downloaded_bytes = 0
block_size = 1024 * 8
while True:
buffer = u.read(block_size)
if not buffer:
break
f.write(buffer)
downloaded_bytes += block_size
self.update_progress.emit(float(downloaded_bytes) / file_size * 100)
f.close()
# unzip
self.update_gui.emit("Swabbin' the decks... (Finishing up)")
import zipfile
zf = zipfile.ZipFile(self.save_path)
uncompress_size = sum((file.file_size for file in zf.infolist()))
extracted_size = 0
if platform.system().lower() in ['windows']:
for file in zf.infolist():
extracted_size += file.file_size
percentage = extracted_size * 100 / uncompress_size
self.update_progress.emit(percentage)
zf.extract(file.filename, self.le_full_path)
elif platform.system().lower() in ['darwin']:
for file in zf.infolist():
extracted_size += file.file_size
percentage = extracted_size * 100 / uncompress_size
self.update_progress.emit(percentage)
f = os.path.join(self.le_full_path, file.filename)
zf.extract(file, self.le_full_path)
subprocess.call(['chmod', 'u+x', f])
zf.close()
# Rename unzipped folder
try:
os.rename(self.save_path.rpartition('.zip')[0], os.path.join(self.le_full_path, filename.rpartition('.zip')[0]))
self.set_extracted_dir.emit(os.path.join(self.le_full_path, filename.rpartition('.zip')[0]).replace('\\', '/'))
except FileExistsError as e:
os.remove(self.save_path)
os.remove(self.save_path.rpartition('.zip')[0])
raise FileExistsError('')
# Clean up by deleting zip file
os.remove(self.save_path)
self.update_gui.emit("Complete!")
return
class VersionsComboBox(QtWidgets.QComboBox):
def __init__(self, parent=None):
super(VersionsComboBox, self).__init__(parent)
def paintEvent(self, e: QtGui.QPaintEvent) -> None:
try:
rect_image = QtCore.Qt.QRect(
self.rect().left() + 6,
self.rect().top(),
self.rect().width() + 6,
self.rect().height()
)
painter = QtGui.QPainter()
painter.begin(self)
index_icon = self.currentData(item_role.ICON)
pixmap_icon = index_icon.pixmap(128, 128)
pixmap_icon_scaled = pixmap_icon.scaled(
rect_image.width(),
rect_image.height(),
QtCore.Qt.KeepAspectRatio,
QtCore.Qt.SmoothTransformation
)
QtWidgets.QApplication.style().drawItemPixmap(
painter,
rect_image,
QtCore.Qt.AlignLeft,
pixmap_icon_scaled
)
painter.end()
except AttributeError:
super(VersionsComboBox, self).paintEvent(e)
class ComboItem(QtGui.QStandardItem):
def __init__(self, data=None):
""":param item: str - Dir_Name.dirType
"""
super(ComboItem, self).__init__()
# Item meta data
self.item_name = data
self.item_icon = resource.icon(self.item_name, 'png')
def data(self, role):
if role == item_role.NAME:
return self.item_name
if role == item_role.ICON:
return self.item_icon
if __name__ == "__main__":
# Qt env vars
os.environ['QT_PREFERRED_BINDING'] = 'PySide2'
os.environ["QTWEBENGINE_CHROMIUM_FLAGS"] = "--enable-logging --log-level=3"
os.environ["QT_AUTO_SCREEN_SCALE_FACTOR"] = "1" # High dpi setting
# Run Armada launcher
app = QtWidgets.QApplication(sys.argv)
# QtGui.QFontDatabase.addApplicationFont('resources/fonts/Roboto/Roboto-Thin.ttf')
window = ArmadaInstaller()
sys.exit(app.exec_())