1
0
mirror of https://github.com/arsenetar/dupeguru.git synced 2026-02-09 06:11:38 +00:00

Next batch of qt6 upgrades

This commit is contained in:
2022-07-08 22:17:42 -05:00
parent 4d56bd3515
commit ec35c2df8f
9 changed files with 94 additions and 65 deletions

View File

@@ -6,36 +6,46 @@
# which should be included with this package. The terms are also available at
# http://www.gnu.org/licenses/gpl-3.0.html
from PyQt5.QtCore import Qt, QCoreApplication, QTimer
from PyQt5.QtGui import QPixmap, QFont
from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QSizePolicy, QHBoxLayout, QVBoxLayout, QLabel
from PyQt6.QtCore import Qt, QCoreApplication, QTimer
from PyQt6.QtGui import QPixmap, QFont, QShowEvent
from PyQt6.QtWidgets import QDialog, QDialogButtonBox, QSizePolicy, QHBoxLayout, QVBoxLayout, QLabel, QWidget
from core.util import check_for_update
from qt.util import move_to_screen_center
from hscommon.trans import trget
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from qt.app import DupeGuru
tr = trget("ui")
class AboutBox(QDialog):
def __init__(self, parent, app, **kwargs):
flags = Qt.CustomizeWindowHint | Qt.WindowTitleHint | Qt.WindowSystemMenuHint | Qt.MSWindowsFixedSizeDialogHint
def __init__(self, parent: QWidget, app: "DupeGuru", **kwargs) -> None:
flags = (
Qt.WindowType.CustomizeWindowHint
| Qt.WindowType.WindowTitleHint
| Qt.WindowType.WindowSystemMenuHint
| Qt.WindowType.MSWindowsFixedSizeDialogHint
)
super().__init__(parent, flags, **kwargs)
self.app = app
self._setupUi()
self.button_box.accepted.connect(self.accept)
self.button_box.rejected.connect(self.reject)
def _setupUi(self):
def _setupUi(self) -> None:
self.setWindowTitle(tr("About {}").format(QCoreApplication.instance().applicationName()))
size_policy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
size_policy = QSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Fixed)
self.setSizePolicy(size_policy)
main_layout = QHBoxLayout(self)
logo_label = QLabel()
logo_label.setPixmap(QPixmap(":/%s_big" % self.app.LOGO_NAME))
logo_label.setPixmap(QPixmap(f"images:{self.app.LOGO_NAME}_128.png"))
main_layout.addWidget(logo_label)
detail_layout = QVBoxLayout()
name_label = QLabel()
font = QFont()
font.setWeight(75)
@@ -43,26 +53,35 @@ class AboutBox(QDialog):
name_label.setFont(font)
name_label.setText(QCoreApplication.instance().applicationName())
detail_layout.addWidget(name_label)
version_label = QLabel()
version_label.setText(tr("Version {}").format(QCoreApplication.instance().applicationVersion()))
detail_layout.addWidget(version_label)
self.update_label = QLabel(tr("Checking for updates..."))
self.update_label.setTextInteractionFlags(Qt.TextBrowserInteraction)
self.update_label.setTextInteractionFlags(Qt.TextInteractionFlag.TextBrowserInteraction)
self.update_label.setOpenExternalLinks(True)
detail_layout.addWidget(self.update_label)
license_label = QLabel()
license_label.setText(tr("Licensed under GPLv3"))
detail_layout.addWidget(license_label)
spacer_label = QLabel()
spacer_label.setFont(font)
detail_layout.addWidget(spacer_label)
self.button_box = QDialogButtonBox()
self.button_box.setOrientation(Qt.Horizontal)
self.button_box.setStandardButtons(QDialogButtonBox.Ok)
detail_layout.addWidget(self.button_box)
button_box = QDialogButtonBox()
button_box.setOrientation(Qt.Orientation.Horizontal)
button_box.setStandardButtons(QDialogButtonBox.StandardButton.Ok)
detail_layout.addWidget(button_box)
main_layout.addLayout(detail_layout)
def _check_for_update(self):
button_box.accepted.connect(self.accept)
button_box.rejected.connect(self.reject)
def _check_for_update(self) -> None:
update = check_for_update(QCoreApplication.instance().applicationVersion(), include_prerelease=False)
if update is None:
self.update_label.setText(tr("No update available."))
@@ -71,7 +90,7 @@ class AboutBox(QDialog):
tr('New version {} available, download <a href="{}">here</a>.').format(update["version"], update["url"])
)
def showEvent(self, event):
def showEvent(self, event: QShowEvent) -> None:
self.update_label.setText(tr("Checking for updates..."))
# have to do this here as the frameGeometry is not correct until shown
move_to_screen_center(self)

View File

@@ -11,8 +11,8 @@ import sys
import os
import platform
from PyQt5.QtCore import Qt, QCoreApplication, QSize
from PyQt5.QtWidgets import (
from PyQt6.QtCore import Qt, QCoreApplication, QSize
from PyQt6.QtWidgets import (
QDialog,
QVBoxLayout,
QHBoxLayout,
@@ -30,7 +30,7 @@ tr = trget("ui")
class ErrorReportDialog(QDialog):
def __init__(self, parent, github_url, error, **kwargs):
flags = Qt.CustomizeWindowHint | Qt.WindowTitleHint | Qt.WindowSystemMenuHint
flags = Qt.WindowType.CustomizeWindowHint | Qt.WindowType.WindowTitleHint | Qt.WindowType.WindowSystemMenuHint
super().__init__(parent, flags, **kwargs)
self._setupUi()
name = QCoreApplication.applicationName()
@@ -40,23 +40,23 @@ class ErrorReportDialog(QDialog):
)
# Under windows, we end up with an error report without linesep if we don't mangle it
error_text = error_text.replace("\n", os.linesep)
self.errorTextEdit.setPlainText(error_text)
self.error_text_edit.setPlainText(error_text)
self.github_url = github_url
self.sendButton.clicked.connect(self.goToGithub)
self.dontSendButton.clicked.connect(self.reject)
def _setupUi(self):
self.setWindowTitle(tr("Error Report"))
self.resize(553, 349)
self.verticalLayout = QVBoxLayout(self)
self.label = QLabel(self)
self.label.setText(tr("Something went wrong. How about reporting the error?"))
self.label.setWordWrap(True)
self.verticalLayout.addWidget(self.label)
self.errorTextEdit = QPlainTextEdit(self)
self.errorTextEdit.setReadOnly(True)
self.verticalLayout.addWidget(self.errorTextEdit)
main_layout = QVBoxLayout(self)
title_label = QLabel(self)
title_label.setText(tr("Something went wrong. How about reporting the error?"))
title_label.setWordWrap(True)
main_layout.addWidget(title_label)
self.error_text_edit = QPlainTextEdit(self)
self.error_text_edit.setReadOnly(True)
main_layout.addWidget(self.error_text_edit)
msg = tr(
"Error reports should be reported as Github issues. You can copy the error traceback "
"above and paste it in a new issue.\n\nPlease make sure to run a search for any already "
@@ -67,21 +67,28 @@ class ErrorReportDialog(QDialog):
"Although the application should continue to run after this error, it may be in an "
"unstable state, so it is recommended that you restart the application."
)
self.label2 = QLabel(msg)
self.label2.setWordWrap(True)
self.verticalLayout.addWidget(self.label2)
self.horizontalLayout = QHBoxLayout()
self.horizontalLayout.addItem(horizontal_spacer())
self.dontSendButton = QPushButton(self)
self.dontSendButton.setText(tr("Close"))
self.dontSendButton.setMinimumSize(QSize(110, 0))
self.horizontalLayout.addWidget(self.dontSendButton)
self.sendButton = QPushButton(self)
self.sendButton.setText(tr("Go to Github"))
self.sendButton.setMinimumSize(QSize(110, 0))
self.sendButton.setDefault(True)
self.horizontalLayout.addWidget(self.sendButton)
self.verticalLayout.addLayout(self.horizontalLayout)
instructions_label = QLabel(msg)
instructions_label.setWordWrap(True)
main_layout.addWidget(instructions_label)
button_layout = QHBoxLayout()
button_layout.addItem(horizontal_spacer())
close_button = QPushButton(self)
close_button.setText(tr("Close"))
close_button.setMinimumSize(QSize(110, 0))
button_layout.addWidget(close_button)
report_button = QPushButton(self)
report_button.setText(tr("Go to Github"))
report_button.setMinimumSize(QSize(110, 0))
report_button.setDefault(True)
button_layout.addWidget(report_button)
main_layout.addLayout(button_layout)
report_button.clicked.connect(self.goToGithub)
close_button.clicked.connect(self.reject)
def goToGithub(self):
open_url(self.github_url)
@@ -91,6 +98,6 @@ def install_excepthook(github_url):
def my_excepthook(exctype, value, tb):
s = "".join(traceback.format_exception(exctype, value, tb))
dialog = ErrorReportDialog(None, github_url, s)
dialog.exec_()
dialog.exec()
sys.excepthook = my_excepthook