From 132d3b1d8e3f2e2d26687b5a4f9b2091ccc0c9a2 Mon Sep 17 00:00:00 2001 From: Greg Hope Date: Sat, 17 Jun 2023 18:42:47 +0100 Subject: [PATCH 1/3] PyQt6 compatibility --- .../gui_qt/console_widget.py | 8 +++--- plover_plugins_manager/gui_qt/info_browser.py | 10 +++---- plover_plugins_manager/gui_qt/manager.py | 28 +++++++++---------- .../gui_qt/resources/__init__.py | 0 plover_plugins_manager/gui_qt/run_dialog.py | 14 +++++----- setup.cfg | 2 +- 6 files changed, 31 insertions(+), 31 deletions(-) create mode 100644 plover_plugins_manager/gui_qt/resources/__init__.py diff --git a/plover_plugins_manager/gui_qt/console_widget.py b/plover_plugins_manager/gui_qt/console_widget.py index 721f393..a5a6b09 100644 --- a/plover_plugins_manager/gui_qt/console_widget.py +++ b/plover_plugins_manager/gui_qt/console_widget.py @@ -5,12 +5,12 @@ import sys import threading -from PyQt5.QtCore import ( +from PyQt6.QtCore import ( QVariant, pyqtSignal, ) -from PyQt5.QtGui import QFontDatabase, QFontMetrics -from PyQt5.QtWidgets import QWidget +from PyQt6.QtGui import QFontDatabase, QFontMetrics +from PyQt6.QtWidgets import QWidget from plover_plugins_manager.gui_qt.console_widget_ui import Ui_ConsoleWidget @@ -30,7 +30,7 @@ def __init__(self, popen=None): self._popen = subprocess.Popen if popen is None else popen self._proc = None self._thread = None - font = QFontDatabase.systemFont(QFontDatabase.FixedFont) + font = QFontDatabase.systemFont(QFontDatabase.SystemFont.FixedFont) metrics = QFontMetrics(font) self.output.setMinimumSize(80 * metrics.maxWidth(), 24 * metrics.height()) diff --git a/plover_plugins_manager/gui_qt/info_browser.py b/plover_plugins_manager/gui_qt/info_browser.py index bd4c80c..bb1f037 100644 --- a/plover_plugins_manager/gui_qt/info_browser.py +++ b/plover_plugins_manager/gui_qt/info_browser.py @@ -1,6 +1,6 @@ -from PyQt5.QtGui import QImage, QTextDocument -from PyQt5.QtWidgets import QTextBrowser -from PyQt5.QtCore import QUrl, pyqtSignal +from PyQt6.QtGui import QImage, QTextDocument +from PyQt6.QtWidgets import QTextBrowser +from PyQt6.QtCore import QUrl, pyqtSignal from plover_plugins_manager.requests import CachedSession, FuturesSession @@ -24,7 +24,7 @@ def loadResource(self, resource_type, resource_url): else: resource = None resource_url = resource_url.url() - if resource is None and resource_type == QTextDocument.ImageResource \ + if resource is None and resource_type == QTextDocument.ResourceType.ImageResource \ and resource_url not in self._images: future = self._futures_session.get(resource_url) future.add_done_callback(self._request_finished) @@ -78,7 +78,7 @@ def _update_image_resource(self, url, data): log.warning('could not load image from %s', url) return doc = self.document() - doc.addResource(QTextDocument.ImageResource, QUrl(url), image) + doc.addResource(QTextDocument.ResourceType.ImageResource, QUrl(url), image) for frag in self._iter_fragments(): fmt = frag.charFormat() if fmt.isImageFormat() and fmt.toImageFormat().name() == url: diff --git a/plover_plugins_manager/gui_qt/manager.py b/plover_plugins_manager/gui_qt/manager.py index 71d84a9..281dbe5 100644 --- a/plover_plugins_manager/gui_qt/manager.py +++ b/plover_plugins_manager/gui_qt/manager.py @@ -5,8 +5,8 @@ import os import sys -from PyQt5.QtCore import Qt, pyqtSignal -from PyQt5.QtWidgets import QDialog, QMessageBox, QTableWidgetItem +from PyQt6.QtCore import Qt, pyqtSignal +from PyQt6.QtWidgets import QDialog, QMessageBox, QTableWidgetItem from plover.gui_qt.tool import Tool @@ -38,7 +38,7 @@ def __init__(self, engine): self._engine = engine self.info = InfoBrowser() self.info_frame.layout().addWidget(self.info) - self.table.sortByColumn(1, Qt.AscendingOrder) + self.table.sortByColumn(1, Qt.SortOrder.AscendingOrder) self._packages_updated.connect(self._on_packages_updated) if self._packages is None: PluginsManager._packages = Registry() @@ -65,13 +65,13 @@ def _update_table(self): for row, state in enumerate(self._packages): for column, attr in enumerate('status name version summary'.split()): item = QTableWidgetItem(getattr(state, attr)) - item.setFlags(item.flags() & ~Qt.ItemIsEditable) + item.setFlags(item.flags() & ~Qt.ItemFlag.ItemIsEditable) self.table.setItem(row, column, item) self.table.resizeColumnsToContents() self.table.setSortingEnabled(True) def _get_state(self, row): - name = self.table.item(row, 1).data(Qt.DisplayRole) + name = self.table.item(row, 1).data(Qt.ItemDataRole.DisplayRole) return self._packages[name] def _get_selection(self): @@ -93,7 +93,7 @@ def _get_selection(self): @staticmethod def _run(args): dialog = RunDialog(args, popen=pip) - code = dialog.exec_() + code = dialog.exec() # dialog.destroy() return code @@ -157,22 +157,22 @@ def on_refresh(self): def on_install(self): packages = self._get_selection()[0] if QMessageBox.warning( - self, 'Install ' + ', '.join(packages), + self, 'Install ' + ', '.join(packages), 'Installing plugins is a security risk. ' 'A plugin can contain virus/malware. ' 'Only install it if you got it from a trusted source.' ' Are you sure you want to proceed?' , - buttons=QMessageBox.Yes | QMessageBox.No, - defaultButton=QMessageBox.No - ) != QMessageBox.Yes: + buttons=QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No, + defaultButton=QMessageBox.StandardButton.No + ) != QMessageBox.StandardButton.Yes: return code = self._run( ['install'] + [self._packages[name].latest.requirement for name in packages] ) - if code == QDialog.Accepted: + if code == QDialog.DialogCode.Accepted: for name in packages: state = self._packages[name] state.current = state.latest @@ -182,7 +182,7 @@ def on_install(self): def on_uninstall(self): packages = self._get_selection()[1] code = self._run(['uninstall', '-y'] + packages) - if code == QDialog.Accepted: + if code == QDialog.DialogCode.Accepted: for name in packages: state = self._packages[name] state.current = None @@ -191,8 +191,8 @@ def on_uninstall(self): if __name__ == '__main__': - from PyQt5.QtWidgets import QApplication + from PyQt6.QtWidgets import QApplication app = QApplication([]) dlg = PluginsManager(None) dlg.show() - app.exec_() + app.exec() diff --git a/plover_plugins_manager/gui_qt/resources/__init__.py b/plover_plugins_manager/gui_qt/resources/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/plover_plugins_manager/gui_qt/run_dialog.py b/plover_plugins_manager/gui_qt/run_dialog.py index 6a30ef7..c65ff04 100644 --- a/plover_plugins_manager/gui_qt/run_dialog.py +++ b/plover_plugins_manager/gui_qt/run_dialog.py @@ -1,5 +1,5 @@ -from PyQt5.QtWidgets import QDialogButtonBox, QDialog +from PyQt6.QtWidgets import QDialogButtonBox, QDialog from plover_plugins_manager.gui_qt.console_widget import ConsoleWidget from plover_plugins_manager.gui_qt.run_dialog_ui import Ui_RunDialog @@ -12,19 +12,19 @@ def __init__(self, run_args, popen=None): self.setupUi(self) self._console = ConsoleWidget(popen) self.layout().replaceWidget(self.console, self._console) - self.buttonBox.button(QDialogButtonBox.Close).setHidden(True) + self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setHidden(True) self._console.processFinished.connect(self.on_process_finished) self._console.run(run_args) self._successful = None def on_process_finished(self, returncode): self._successful = returncode == 0 - self.buttonBox.button(QDialogButtonBox.Cancel).setHidden(True) - self.buttonBox.button(QDialogButtonBox.Close).setHidden(False) + self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel).setHidden(True) + self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setHidden(False) def reject(self): if self._successful is not None: - super().done(getattr(QDialog, 'Accepted' + super().done(getattr(QDialog.DialogCode, 'Accepted' if self._successful else 'Rejected')) return @@ -33,8 +33,8 @@ def reject(self): if __name__ == '__main__': import sys - from PyQt5.QtWidgets import QApplication + from PyQt6.QtWidgets import QApplication app = QApplication([]) dlg = RunDialog(sys.argv[1:]) dlg.show() - app.exec_() + app.exec() diff --git a/setup.cfg b/setup.cfg index d48ad3b..28b7a5a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -31,7 +31,7 @@ python_requires = >=3.6 install_requires = pip pkginfo>=1.4.2 - plover[gui_qt]>=4.0.0.dev8 + plover[gui_qt] @ https://github.com/greghope667/plover/archive/pyqt6-migration.zip pygments readme-renderer[md] requests>=2.0.0 From b9c1a8ebf33edd9e7e5b17b9d487952d17017e40 Mon Sep 17 00:00:00 2001 From: Greg Hope Date: Tue, 27 Jun 2023 20:44:29 +0100 Subject: [PATCH 2/3] Add svg to include path --- MANIFEST.in | 4 ++-- plover_plugins_manager/gui_qt/manager.py | 2 +- plover_plugins_manager/gui_qt/resources/resources.qrc | 2 +- pyproject.toml | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/MANIFEST.in b/MANIFEST.in index b7d58e2..99cfae4 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -10,7 +10,7 @@ include test/plover_template_system-0.1.0-py3-none-any.whl include test/plover_template_system-0.2.0-py3-none-any.whl include tox.ini # UI. -exclude plover_plugins_manager/gui_qt/*_rc.py exclude plover_plugins_manager/gui_qt/*_ui.py include plover_plugins_manager/gui_qt/*.ui -recursive-include plover_plugins_manager/gui_qt/resources * +include plover_plugins_manager/gui_qt/resources/*.svg +include plover_plugins_manager/gui_qt/resources/*.qrc diff --git a/plover_plugins_manager/gui_qt/manager.py b/plover_plugins_manager/gui_qt/manager.py index 281dbe5..df8ac92 100644 --- a/plover_plugins_manager/gui_qt/manager.py +++ b/plover_plugins_manager/gui_qt/manager.py @@ -22,7 +22,7 @@ class PluginsManager(Tool, Ui_PluginsManager): TITLE = 'Plugins Manager' ROLE = 'plugins_manager' - ICON = ':/plugins_manager/icon.svg' + ICON = ('plover_plugins_manager.gui_qt.resources', ':/icon.svg') # We use a class instance so the state is persistent # accross different executions of the dialog when diff --git a/plover_plugins_manager/gui_qt/resources/resources.qrc b/plover_plugins_manager/gui_qt/resources/resources.qrc index d0e943e..312a096 100644 --- a/plover_plugins_manager/gui_qt/resources/resources.qrc +++ b/plover_plugins_manager/gui_qt/resources/resources.qrc @@ -1,5 +1,5 @@ - + icon.svg diff --git a/pyproject.toml b/pyproject.toml index e12f5b0..ef5f180 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [build-system] requires = [ - "plover[gui_qt]>=4.0.0.dev10", + "plover[gui_qt]@https://github.com/greghope667/plover/archive/pyqt6-migration.zip", "setuptools>=38.2.4", "wheel", ] From d5b47599b515abf1402ef779a3a084bfcc2d6085 Mon Sep 17 00:00:00 2001 From: Greg Hope Date: Mon, 10 Jul 2023 19:13:43 +0100 Subject: [PATCH 3/3] Hopefully add manifest files to source dist (Ignore the deprecation warnings for now) --- MANIFEST.in | 1 + setup.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/MANIFEST.in b/MANIFEST.in index 99cfae4..05b3285 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -14,3 +14,4 @@ exclude plover_plugins_manager/gui_qt/*_ui.py include plover_plugins_manager/gui_qt/*.ui include plover_plugins_manager/gui_qt/resources/*.svg include plover_plugins_manager/gui_qt/resources/*.qrc +include plover_plugins_manager/gui_qt/resources/__init__.py diff --git a/setup.py b/setup.py index 0ddbff2..2f8ecd0 100755 --- a/setup.py +++ b/setup.py @@ -14,4 +14,4 @@ 'develop': Develop, } -setup(cmdclass=cmdclass) +setup(cmdclass=cmdclass, include_package_data=True)