Fix Python2 bugs in GUI code

This commit is contained in:
Florian Bach 2022-10-09 10:56:44 +02:00
parent 69329fe09a
commit 7e9153e294
3 changed files with 35 additions and 9 deletions

View File

@ -9,7 +9,13 @@
from calibre.gui2.actions import InterfaceAction from calibre.gui2.actions import InterfaceAction
from calibre.gui2.actions import menu_action_unique_name 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@@ #@@CALIBRE_COMPAT_CODE@@
@ -61,13 +67,19 @@ class ActualACSMInputGUIExtension(InterfaceAction):
# Text, icon, tooltip, keyboard shortcut # Text, icon, tooltip, keyboard shortcut
def genesis(self): def genesis(self):
print("Genesis!") print("ACSM Input: GUI Plugin Genesis!")
self.menu = QMenu(self.gui) self.menu = QMenu(self.gui)
self.rebuild_menus() self.rebuild_menus()
self.qaction.setMenu(self.menu) self.qaction.setMenu(self.menu)
try:
# Py3
icon = get_icons('acsm_logo_2.png', "ACSM Input Plugin") 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.setIcon(icon)
#self.qaction.triggered.connect(self.trigger_config_dialog) #self.qaction.triggered.connect(self.trigger_config_dialog)

View File

@ -5,7 +5,10 @@
# #
from calibre.customize import InterfaceActionBase # type: ignore 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" type = "File type"
# Just so that the GUI extension shows up at the same place as the actual ACSM Input plugin. # Just so that the GUI extension shows up at the same place as the actual ACSM Input plugin.
try:
installation_type = PluginInstallationType.EXTERNAL installation_type = PluginInstallationType.EXTERNAL
# Mark this as user-installed so it shows up in the plugin list by default. # 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" actual_plugin = "calibre_plugins.deacsm.gui_main:ActualACSMInputGUIExtension"

View File

@ -10,7 +10,10 @@
from calibre.customize import InterfaceActionBase # type: ignore from calibre.customize import InterfaceActionBase # type: ignore
from calibre.customize import PluginInstallationType try:
from calibre.customize import PluginInstallationType
except:
pass
class DeACSMMigrationPlugin(InterfaceActionBase): class DeACSMMigrationPlugin(InterfaceActionBase):
@ -28,8 +31,12 @@ class DeACSMMigrationPlugin(InterfaceActionBase):
type = "File type" type = "File type"
# Just so that the GUI extension shows up at the same place as the actual ACSM Input plugin. # Just so that the GUI extension shows up at the same place as the actual ACSM Input plugin.
try:
installation_type = PluginInstallationType.EXTERNAL installation_type = PluginInstallationType.EXTERNAL
# Mark this as user-installed so it shows up in the plugin list by default. # 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" actual_plugin = "calibre_plugins.deacsm.migration:ActualMigrationPlugin"