-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_dialog.py
More file actions
100 lines (78 loc) · 2.94 KB
/
update_dialog.py
File metadata and controls
100 lines (78 loc) · 2.94 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
"""
Update confirmation dialog for SPVideoCoursesPlayer.
Shows available update info, changelog, and action buttons.
"""
from PyQt6.QtWidgets import (
QDialog, QVBoxLayout, QHBoxLayout, QLabel, QPushButton, QTextEdit
)
from PyQt6.QtCore import Qt
from PyQt6.QtGui import QFont
from translator import tr
class UpdateDialog(QDialog):
"""Dialog shown when a new app version is available."""
# Result codes
UPDATE_NOW = 1
SKIP_VERSION = 2
LATER = 0
def __init__(self, parent=None, update_info: dict = None):
super().__init__(parent)
self.update_info = update_info or {}
self.result_action = self.LATER
self.setWindowTitle(tr('updater.title'))
self.setMinimumWidth(500)
self.setMinimumHeight(350)
self.setup_ui()
def setup_ui(self):
layout = QVBoxLayout(self)
layout.setSpacing(12)
# Title
title = QLabel(tr('updater.available', version=self.update_info.get('latest', '?')))
title_font = QFont()
title_font.setPointSize(12)
title_font.setBold(True)
title.setFont(title_font)
layout.addWidget(title)
# Version info
current_label = QLabel(tr('updater.current_version', version=self.update_info.get('current', '?')))
layout.addWidget(current_label)
new_label = QLabel(tr('updater.new_version', version=self.update_info.get('latest', '?')))
new_font = QFont()
new_font.setBold(True)
new_label.setFont(new_font)
layout.addWidget(new_label)
# Changelog
changelog_title = QLabel(tr('updater.changelog'))
layout.addWidget(changelog_title)
self.changelog_text = QTextEdit()
self.changelog_text.setReadOnly(True)
changelog_content = self.update_info.get('changelog', '')
if changelog_content:
self.changelog_text.setMarkdown(changelog_content)
else:
self.changelog_text.setPlainText("—")
layout.addWidget(self.changelog_text, 1)
# Buttons
btn_layout = QHBoxLayout()
btn_layout.setSpacing(8)
skip_btn = QPushButton(tr('updater.skip_version'))
skip_btn.clicked.connect(self._on_skip)
btn_layout.addWidget(skip_btn)
btn_layout.addStretch()
later_btn = QPushButton(tr('updater.later'))
later_btn.clicked.connect(self._on_later)
btn_layout.addWidget(later_btn)
update_btn = QPushButton(tr('updater.update_now'))
update_btn.setDefault(True)
update_btn.setObjectName("updateNowBtn")
update_btn.clicked.connect(self._on_update)
btn_layout.addWidget(update_btn)
layout.addLayout(btn_layout)
def _on_update(self):
self.result_action = self.UPDATE_NOW
self.accept()
def _on_skip(self):
self.result_action = self.SKIP_VERSION
self.reject()
def _on_later(self):
self.result_action = self.LATER
self.reject()