From 7e9153e294d3a0ba7e922cb9d7cfeff7755bcdf9 Mon Sep 17 00:00:00 2001 From: Florian Bach Date: Sun, 9 Oct 2022 10:56:44 +0200 Subject: [PATCH] Fix Python2 bugs in GUI code --- calibre-plugin/gui_main.py | 18 +++++++++++++++--- calibre-plugin/gui_main_wrapper.py | 13 ++++++++++--- migration_plugin/__init__.py | 13 ++++++++++--- 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/calibre-plugin/gui_main.py b/calibre-plugin/gui_main.py index 998847d..c7a259a 100644 --- a/calibre-plugin/gui_main.py +++ b/calibre-plugin/gui_main.py @@ -9,7 +9,13 @@ from calibre.gui2.actions import InterfaceAction from calibre.gui2.actions import menu_action_unique_name -from PyQt5.QtGui import QMenu, QToolButton +try: + from PyQt5.QtGui import QMenu, QToolButton +except ImportError: + try: + from PyQt5.QtWidgets import QMenu, QToolButton + except ImportError: + from PyQt4.Qt import QMenu, QToolButton #@@CALIBRE_COMPAT_CODE@@ @@ -61,13 +67,19 @@ class ActualACSMInputGUIExtension(InterfaceAction): # Text, icon, tooltip, keyboard shortcut def genesis(self): - print("Genesis!") + print("ACSM Input: GUI Plugin Genesis!") self.menu = QMenu(self.gui) self.rebuild_menus() self.qaction.setMenu(self.menu) - icon = get_icons('acsm_logo_2.png', "ACSM Input Plugin") + try: + # Py3 + icon = get_icons('acsm_logo_2.png', "ACSM Input Plugin") + except TypeError: + # Py2 + icon = get_icons('acsm_logo_2.png') + self.qaction.setIcon(icon) #self.qaction.triggered.connect(self.trigger_config_dialog) diff --git a/calibre-plugin/gui_main_wrapper.py b/calibre-plugin/gui_main_wrapper.py index 0a1a89d..e3b1400 100644 --- a/calibre-plugin/gui_main_wrapper.py +++ b/calibre-plugin/gui_main_wrapper.py @@ -5,7 +5,10 @@ # from calibre.customize import InterfaceActionBase # type: ignore -from calibre.customize import PluginInstallationType +try: + from calibre.customize import PluginInstallationType +except: + pass @@ -25,8 +28,12 @@ class ACSMInputGUIExtension(InterfaceActionBase): type = "File type" # Just so that the GUI extension shows up at the same place as the actual ACSM Input plugin. - installation_type = PluginInstallationType.EXTERNAL - # Mark this as user-installed so it shows up in the plugin list by default. + try: + installation_type = PluginInstallationType.EXTERNAL + # Mark this as user-installed so it shows up in the plugin list by default. + except: + # Setting the Installation type doesn't always work on Calibre 4 and below. + pass actual_plugin = "calibre_plugins.deacsm.gui_main:ActualACSMInputGUIExtension" diff --git a/migration_plugin/__init__.py b/migration_plugin/__init__.py index bfa5a77..522007c 100644 --- a/migration_plugin/__init__.py +++ b/migration_plugin/__init__.py @@ -10,7 +10,10 @@ from calibre.customize import InterfaceActionBase # type: ignore -from calibre.customize import PluginInstallationType +try: + from calibre.customize import PluginInstallationType +except: + pass class DeACSMMigrationPlugin(InterfaceActionBase): @@ -28,8 +31,12 @@ class DeACSMMigrationPlugin(InterfaceActionBase): type = "File type" # Just so that the GUI extension shows up at the same place as the actual ACSM Input plugin. - installation_type = PluginInstallationType.EXTERNAL - # Mark this as user-installed so it shows up in the plugin list by default. + try: + installation_type = PluginInstallationType.EXTERNAL + # Mark this as user-installed so it shows up in the plugin list by default. + except: + # Setting the Installation type doesn't always work on Calibre 4 and below. + pass actual_plugin = "calibre_plugins.deacsm.migration:ActualMigrationPlugin"