-
Notifications
You must be signed in to change notification settings - Fork 24
/
updater.py
77 lines (66 loc) · 3.18 KB
/
updater.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
import os
from pathlib import Path
import subprocess
import sys
from PySide6 import QtGui
from PySide6.QtGui import QIcon
from PySide6.QtWidgets import QApplication, QMainWindow, QLabel, QGridLayout, QWidget, QListWidget, QPushButton, QPlainTextEdit
from Module.resources import resource_path
from UI import theme
from UI.GithubInfo.releaseInfo import GithubReleaseInfo, KH2RandomizerGithubReleases
class KH2RandoUpdater(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("KH2 Randomizer Seed Generator Updater")
self.setWindowIcon(QIcon(resource_path("Module/icon.png")))
releases = KH2RandomizerGithubReleases()
self.updates = releases.get_update_infos()
grid = QGridLayout()
if len(self.updates)==0:
label = QLabel("No new updates. You are up to date.")
grid.addWidget(label,0,0)
else:
# loop through updates, putting most up to date at the top
self.update_list_widget = QListWidget(self)
self.patch_notes = QPlainTextEdit(self)
for update_info in self.updates:
self.update_list_widget.addItem(str(update_info.version))
self.update_list_widget.itemSelectionChanged.connect(self.update_patch_notes)
self.update_list_widget.setCurrentRow(0)
download_button = QPushButton("Download Selected Update")
download_button.clicked.connect(self.download_selected_update)
grid.addWidget(self.update_list_widget, 0, 0)
grid.addWidget(self.patch_notes, 0, 1)
grid.addWidget(download_button, 1, 0)
widget = QWidget()
widget.setLayout(grid)
self.setCentralWidget(widget)
def update_patch_notes(self):
for index in self.update_list_widget.selectedIndexes():
self.patch_notes.setPlainText(self.updates[index.row()].notes)
def download_selected_update(self):
for index in self.update_list_widget.selectedIndexes():
update_info : GithubReleaseInfo = self.updates[index.row()]
result = update_info.download_release()
if result:
process = subprocess.Popen("KH2.Randomizer.exe")
sys.exit()
if __name__=="__main__":
app = QApplication([])
QtGui.QFontDatabase.addApplicationFont(resource_path('static/KHMenu.otf'))
window = KH2RandoUpdater()
stylesheet = app.styleSheet()
with open(resource_path('UI/stylesheet.css')) as file:
css_resources = {
"background-primary": theme.BackgroundPrimary,
"background-dark": theme.BackgroundDark,
"link-color": theme.LinkColor,
"selection-color": theme.SelectionColor,
"selection-border-color": theme.SelectionBorderColor,
"ability-on": Path(resource_path("static/icons/misc/ability-on.png")).as_posix(),
"down-arrow": Path(resource_path("static/icons/misc/arrow-down.png")).as_posix(),
"up-arrow": Path(resource_path("static/icons/misc/arrow-up.png")).as_posix(),
}
app.setStyleSheet((stylesheet + file.read().format(**os.environ)) % css_resources)
window.show()
sys.exit(app.exec())