Support Qt6

This commit is contained in:
Fabian 2021-11-17 18:56:14 +01:00
parent 75bac84888
commit 36e644a736
9 changed files with 47 additions and 20 deletions

View File

@ -1,6 +1,9 @@
from configparser import ConfigParser from configparser import ConfigParser
from pathlib import Path from pathlib import Path
try:
from PySide6 import QtCore
except ImportError:
from PySide2 import QtCore from PySide2 import QtCore
from fime.exceptions import FimeException from fime.exceptions import FimeException

View File

@ -7,6 +7,9 @@ from datetime import datetime, date, timedelta
from threading import Thread, Event from threading import Thread, Event
from typing import List from typing import List
try:
from PySide6 import QtCore
except ImportError:
from PySide2 import QtCore from PySide2 import QtCore
data_dir_path = os.path.join(QtCore.QStandardPaths.writableLocation(QtCore.QStandardPaths.AppDataLocation), data_dir_path = os.path.join(QtCore.QStandardPaths.writableLocation(QtCore.QStandardPaths.AppDataLocation),

View File

@ -3,6 +3,9 @@
# Created by: The Resource Compiler for Qt version 5.15.2 # Created by: The Resource Compiler for Qt version 5.15.2
# WARNING! All changes made in this file will be lost! # WARNING! All changes made in this file will be lost!
try:
from PySide6 import QtCore
except ImportError:
from PySide2 import QtCore from PySide2 import QtCore
qt_resource_data = b"\ qt_resource_data = b"\

View File

@ -1,3 +1,6 @@
try:
from PySide6 import QtGui, QtWidgets
except ImportError:
from PySide2 import QtGui, QtWidgets from PySide2 import QtGui, QtWidgets
from fime.task_completer import TaskCompleter from fime.task_completer import TaskCompleter

View File

@ -4,8 +4,12 @@ import signal
import sys import sys
from functools import partial from functools import partial
try:
from PySide6 import QtCore, QtWidgets
PYSIDE_6 = True
except ImportError:
from PySide2 import QtCore, QtWidgets from PySide2 import QtCore, QtWidgets
from PySide2.QtWidgets import QMessageBox PYSIDE_6 = False
# noinspection PyUnresolvedReferences # noinspection PyUnresolvedReferences
import fime.icons import fime.icons
@ -128,6 +132,9 @@ class App:
timer.start(500) timer.start(500)
signal.signal(signal.SIGTERM, self.sigterm_handler) signal.signal(signal.SIGTERM, self.sigterm_handler)
signal.signal(signal.SIGINT, self.sigterm_handler) signal.signal(signal.SIGINT, self.sigterm_handler)
if PYSIDE_6:
self.app.exec()
else:
self.app.exec_() self.app.exec_()
@QtCore.Slot() @QtCore.Slot()
@ -151,7 +158,7 @@ def main():
app = App() app = App()
app.run() app.run()
except FimeException as e: 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__": if __name__ == "__main__":

View File

@ -1,9 +1,10 @@
try:
from PySide6 import QtCore, QtGui, QtWidgets
except ImportError:
from PySide2 import QtCore, QtGui, QtWidgets from PySide2 import QtCore, QtGui, QtWidgets
from datetime import datetime from datetime import datetime
from PySide2.QtWidgets import QHeaderView
from fime.data import Tasks from fime.data import Tasks
from fime.util import get_screen_height, get_icon 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.tableWidget.setItemDelegateForColumn(0, Report.TaskItemCompleter(self._tasks, self))
self.header = QtWidgets.QHeaderView(QtCore.Qt.Orientation.Horizontal) self.header = QtWidgets.QHeaderView(QtCore.Qt.Orientation.Horizontal)
self.header.setMinimumSectionSize(1) self.header.setMinimumSectionSize(1)
self.header.setSectionResizeMode(QHeaderView.ResizeToContents) self.header.setSectionResizeMode(QtWidgets.QHeaderView.ResizeToContents)
self.tableWidget.setHorizontalHeader(self.header) 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 = QtWidgets.QPushButton()
self.previous_button.setText("Previous") self.previous_button.setText("Previous")

View File

@ -5,15 +5,16 @@ from functools import reduce
from queue import Queue, Empty from queue import Queue, Empty
from urllib.parse import urlparse, parse_qs from urllib.parse import urlparse, parse_qs
from PySide2 import QtCore try:
from PySide2.QtCore import QTimer from PySide6 import QtCore, QtWidgets
from PySide2.QtWidgets import QCompleter except ImportError:
from PySide2 import QtCore, QtWidgets
from requests_futures.sessions import FuturesSession from requests_futures.sessions import FuturesSession
from fime.config import Config from fime.config import Config
class TaskCompleter(QCompleter): class TaskCompleter(QtWidgets.QCompleter):
def __init__(self, parent=None, *args, **kwargs): def __init__(self, parent=None, *args, **kwargs):
super().__init__([], parent, *args, **kwargs) super().__init__([], parent, *args, **kwargs)
self.setFilterMode(QtCore.Qt.MatchFlag.MatchContains) self.setFilterMode(QtCore.Qt.MatchFlag.MatchContains)
@ -26,7 +27,7 @@ class TaskCompleter(QCompleter):
self.response_text = "" self.response_text = ""
self.model_data = set() self.model_data = set()
self.escalate = False 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.timeout.connect(self.process_response)
self.update_timer.setInterval(250) self.update_timer.setInterval(250)
self.queue = Queue() self.queue = Queue()

View File

@ -1,3 +1,6 @@
try:
from PySide6 import QtCore, QtGui, QtWidgets
except ImportError:
from PySide2 import QtCore, QtGui, QtWidgets from PySide2 import QtCore, QtGui, QtWidgets
from fime.util import get_icon from fime.util import get_icon

View File

@ -1,3 +1,6 @@
try:
from PySide6 import QtGui
except ImportError:
from PySide2 import QtGui from PySide2 import QtGui