Skip to content

Commit

Permalink
New about dialog
Browse files Browse the repository at this point in the history
Add 'Check for updates' button.
  • Loading branch information
DavidoTek committed Oct 25, 2021
1 parent f12f15d commit 31b606b
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 2 deletions.
1 change: 1 addition & 0 deletions pupgui2/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

APP_NAME = 'ProtonUp-Qt'
APP_VERSION = '2.0.0'
APP_GHAPI_URL = 'https://api.github.com/repos/Davidotek/ProtonUp-qt/releases'
ABOUT_TEXT = QObject.tr('''\
GUI for installing/updating Wine/Proton based compatibility tools.
Expand Down
4 changes: 2 additions & 2 deletions pupgui2/pupgui2.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from constants import APP_NAME, APP_VERSION, ABOUT_TEXT, TEMP_DIR
import ctloader
from pupgui2installdialog import PupguiInstallDialog
from pupgui2aboutdialog import PupguiAboutDialog


class InstallWineThread(threading.Thread):
Expand Down Expand Up @@ -160,8 +161,7 @@ def btn_remove_selcted_clicked(self):
self.update_ui()

def btn_about_clicked(self):
QMessageBox.about(self.ui, 'About ' + APP_NAME + ' ' + APP_VERSION, ABOUT_TEXT)
QMessageBox.aboutQt(self.ui)
PupguiAboutDialog(self.pupgui2_base_dir, self.ui)

def btn_close_clicked(self):
self.ui.close()
Expand Down
69 changes: 69 additions & 0 deletions pupgui2/pupgui2aboutdialog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import os, requests, webbrowser

from PySide6.QtWidgets import *
from PySide6.QtCore import *
from PySide6.QtGui import *
from PySide6.QtUiTools import QUiLoader

from constants import APP_NAME, APP_VERSION, APP_GHAPI_URL, ABOUT_TEXT


class PupguiAboutDialog(QObject):

def __init__(self, pupgui2_base_dir, parent=None):
super(PupguiAboutDialog, self).__init__(parent)
self.pupgui2_base_dir = pupgui2_base_dir
self.parent = parent

self.load_ui()
self.setup_ui()
self.ui.show()

def load_ui(self):
ui_file_name = os.path.join(self.pupgui2_base_dir, 'ui/pupgui2_aboutdialog.ui')
ui_file = QFile(ui_file_name)
if not ui_file.open(QIODevice.ReadOnly):
print(f'Cannot open {ui_file_name}: {ui_file.errorString()}')
sys.exit(-1)
loader = QUiLoader()
self.ui = loader.load(ui_file, self.parent)
ui_file.close()

def setup_ui(self):
self.ui.setWindowTitle(APP_NAME + ' ' + APP_VERSION)
self.ui.setWindowIcon(QIcon.fromTheme('pupgui2'))

self.ui.lblAppIcon.setPixmap(QIcon.fromTheme('pupgui2').pixmap(QSize(96, 96)))
self.ui.lblAboutText.setText(ABOUT_TEXT)

self.ui.btnClose.clicked.connect(self.btn_close_clicked)
self.ui.btnAboutQt.clicked.connect(self.btn_aboutqt_clicked)
self.ui.btnCheckForUpdates.clicked.connect(self.btn_check_for_updates_clicked)

def btn_close_clicked(self):
self.ui.close()

def btn_aboutqt_clicked(self):
QMessageBox.aboutQt(self.parent)

def btn_check_for_updates_clicked(self):
releases = requests.get(APP_GHAPI_URL + '?per_page=1').json()
if len(releases) == 0:
return
newest_release = releases[0]
v_current = self.tag_name_to_version(APP_VERSION)
v_newest = self.tag_name_to_version(newest_release['tag_name'])
if (10000 * v_current[0] + 100 * v_current[1] + v_current[2]) < (10000 * v_newest[0] + 100 * v_newest[1] + v_newest[2]):
QMessageBox.information(self.ui, 'Update available',
self.tr('There is a newer version available.\nYou are running {APP_VERSION} but {newest_version} is available.')
.format(APP_VERSION='v' + APP_VERSION, newest_version=newest_release['tag_name']))
webbrowser.open(newest_release['html_url'])
else:
QMessageBox.information(self.ui, 'Up to date', self.tr('You are running the newest version!'))

def tag_name_to_version(self, tag_name : str):
tag_name = tag_name.replace('v', '')
vers = tag_name.split('.')
if len(vers) != 3:
return [0, 0, 0]
return vers
102 changes: 102 additions & 0 deletions share/pupgui2/ui/pupgui2_aboutdialog.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>395</width>
<height>154</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<property name="modal">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="lblAppIcon">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="lblAboutText">
<property name="text">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="btnCheckForUpdates">
<property name="text">
<string>Check for updates</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="btnAboutQt">
<property name="text">
<string>About Qt</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnClose">
<property name="text">
<string>Close</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

0 comments on commit 31b606b

Please sign in to comment.