From 36e644a736c25f8819e1237a77e36df7c9e876a9 Mon Sep 17 00:00:00 2001 From: Faerbit Date: Wed, 17 Nov 2021 18:56:14 +0100 Subject: [PATCH] Support Qt6 --- src/fime/config.py | 5 ++++- src/fime/data.py | 5 ++++- src/fime/icons/__init__.py | 5 ++++- src/fime/import_task.py | 5 ++++- src/fime/main.py | 15 +++++++++++---- src/fime/report.py | 11 ++++++----- src/fime/task_completer.py | 11 ++++++----- src/fime/task_edit.py | 5 ++++- src/fime/util.py | 5 ++++- 9 files changed, 47 insertions(+), 20 deletions(-) diff --git a/src/fime/config.py b/src/fime/config.py index 193751c..534c725 100644 --- a/src/fime/config.py +++ b/src/fime/config.py @@ -1,7 +1,10 @@ from configparser import ConfigParser from pathlib import Path -from PySide2 import QtCore +try: + from PySide6 import QtCore +except ImportError: + from PySide2 import QtCore from fime.exceptions import FimeException diff --git a/src/fime/data.py b/src/fime/data.py index 6854454..dff5bec 100644 --- a/src/fime/data.py +++ b/src/fime/data.py @@ -7,7 +7,10 @@ from datetime import datetime, date, timedelta from threading import Thread, Event from typing import List -from PySide2 import QtCore +try: + from PySide6 import QtCore +except ImportError: + from PySide2 import QtCore data_dir_path = os.path.join(QtCore.QStandardPaths.writableLocation(QtCore.QStandardPaths.AppDataLocation), "fime") diff --git a/src/fime/icons/__init__.py b/src/fime/icons/__init__.py index c994718..2116539 100644 --- a/src/fime/icons/__init__.py +++ b/src/fime/icons/__init__.py @@ -3,7 +3,10 @@ # Created by: The Resource Compiler for Qt version 5.15.2 # WARNING! All changes made in this file will be lost! -from PySide2 import QtCore +try: + from PySide6 import QtCore +except ImportError: + from PySide2 import QtCore qt_resource_data = b"\ \x00\x00\x02\xdd\ diff --git a/src/fime/import_task.py b/src/fime/import_task.py index 1c0e6d4..61c9cd7 100644 --- a/src/fime/import_task.py +++ b/src/fime/import_task.py @@ -1,4 +1,7 @@ -from PySide2 import QtGui, QtWidgets +try: + from PySide6 import QtGui, QtWidgets +except ImportError: + from PySide2 import QtGui, QtWidgets from fime.task_completer import TaskCompleter from fime.util import get_icon diff --git a/src/fime/main.py b/src/fime/main.py index 24d35a3..899ac34 100755 --- a/src/fime/main.py +++ b/src/fime/main.py @@ -4,8 +4,12 @@ import signal import sys from functools import partial -from PySide2 import QtCore, QtWidgets -from PySide2.QtWidgets import QMessageBox +try: + from PySide6 import QtCore, QtWidgets + PYSIDE_6 = True +except ImportError: + from PySide2 import QtCore, QtWidgets + PYSIDE_6 = False # noinspection PyUnresolvedReferences import fime.icons @@ -128,7 +132,10 @@ class App: timer.start(500) signal.signal(signal.SIGTERM, self.sigterm_handler) signal.signal(signal.SIGINT, self.sigterm_handler) - self.app.exec_() + if PYSIDE_6: + self.app.exec() + else: + self.app.exec_() @QtCore.Slot() def report(self): @@ -151,7 +158,7 @@ def main(): app = App() app.run() except FimeException as e: - QMessageBox.critical(None, "Error", str(e), QMessageBox.Ok) + QtWidgets.QMessageBox.critical(None, "Error", str(e), QtWidgets.QMessageBox.Ok) if __name__ == "__main__": diff --git a/src/fime/report.py b/src/fime/report.py index cc4c2ec..1364c10 100644 --- a/src/fime/report.py +++ b/src/fime/report.py @@ -1,9 +1,10 @@ -from PySide2 import QtCore, QtGui, QtWidgets +try: + from PySide6 import QtCore, QtGui, QtWidgets +except ImportError: + from PySide2 import QtCore, QtGui, QtWidgets from datetime import datetime -from PySide2.QtWidgets import QHeaderView - from fime.data import Tasks from fime.util import get_screen_height, get_icon @@ -41,9 +42,9 @@ class Report(QtWidgets.QDialog): self.tableWidget.setItemDelegateForColumn(0, Report.TaskItemCompleter(self._tasks, self)) self.header = QtWidgets.QHeaderView(QtCore.Qt.Orientation.Horizontal) self.header.setMinimumSectionSize(1) - self.header.setSectionResizeMode(QHeaderView.ResizeToContents) + self.header.setSectionResizeMode(QtWidgets.QHeaderView.ResizeToContents) self.tableWidget.setHorizontalHeader(self.header) - self.header.setSectionResizeMode(self.header.logicalIndex(0), QHeaderView.Stretch) + self.header.setSectionResizeMode(self.header.logicalIndex(0), QtWidgets.QHeaderView.Stretch) self.previous_button = QtWidgets.QPushButton() self.previous_button.setText("Previous") diff --git a/src/fime/task_completer.py b/src/fime/task_completer.py index b720ba2..a1831d9 100644 --- a/src/fime/task_completer.py +++ b/src/fime/task_completer.py @@ -5,15 +5,16 @@ from functools import reduce from queue import Queue, Empty from urllib.parse import urlparse, parse_qs -from PySide2 import QtCore -from PySide2.QtCore import QTimer -from PySide2.QtWidgets import QCompleter +try: + from PySide6 import QtCore, QtWidgets +except ImportError: + from PySide2 import QtCore, QtWidgets from requests_futures.sessions import FuturesSession from fime.config import Config -class TaskCompleter(QCompleter): +class TaskCompleter(QtWidgets.QCompleter): def __init__(self, parent=None, *args, **kwargs): super().__init__([], parent, *args, **kwargs) self.setFilterMode(QtCore.Qt.MatchFlag.MatchContains) @@ -26,7 +27,7 @@ class TaskCompleter(QCompleter): self.response_text = "" self.model_data = set() self.escalate = False - self.update_timer = QTimer(self) + self.update_timer = QtCore.QTimer(self) self.update_timer.timeout.connect(self.process_response) self.update_timer.setInterval(250) self.queue = Queue() diff --git a/src/fime/task_edit.py b/src/fime/task_edit.py index f0d77d2..447b65d 100644 --- a/src/fime/task_edit.py +++ b/src/fime/task_edit.py @@ -1,4 +1,7 @@ -from PySide2 import QtCore, QtGui, QtWidgets +try: + from PySide6 import QtCore, QtGui, QtWidgets +except ImportError: + from PySide2 import QtCore, QtGui, QtWidgets from fime.util import get_icon diff --git a/src/fime/util.py b/src/fime/util.py index d38294b..a26a95c 100644 --- a/src/fime/util.py +++ b/src/fime/util.py @@ -1,4 +1,7 @@ -from PySide2 import QtGui +try: + from PySide6 import QtGui +except ImportError: + from PySide2 import QtGui def get_screen_height(qobject):