Manual de usuario de calibre, Publicación 2.73.0
if ac is not None: ac. apply _ settings()
La única característica notable es el campo actual _ plugin. Puesto que calibre posee tanto una interfaz gráfica como de línea de órdenes, los complementos con interfaz gráfica como éste no cargan ninguna biblioteca gráfica en __ init __. py. El campo actual _ plugin se encargad de esto, informando a calibre de que el complemento real se encuentra en otro archivo dentro del archivo zip, que sólo se cargará en un contexto de interfaz gráfica.
Recuerde que para que esto funcione, debe tener un archivo plugin-import-name-some _ name. txt en el archivo zip del complemento, como se discutió anteriormente.
También hay un par de métodos para permitir la configuración por parte del usuario del complemento. Éstos se discuten más adelante.
ui. py
Veamos ahora ui. py, que define la interfaz gráfica del complemento. El código fuente está explícitamente comentado y se explica por sí mismo:
# The class that all interface action plugins must inherit from from calibre. gui2. actions import InterfaceAction from calibre _ plugins. interface _ demo. main import DemoDialog
class InterfacePlugin( InterfaceAction): name = ' Interface Plugin Demo '
# Declare the main action associated with this plugin # The keyboard shortcut can be None if you dont want to use a keyboard # shortcut. Remember that currently calibre has no central management for # keyboard shortcuts, so try to use an unusual / unused shortcut. action _ spec =(' Interface Plugin Demo ', None,
' Run the Interface Plugin Demo ', ' Ctrl + Shift + F1 ')
def genesis( self): # This method is called once per plugin, do initial setup here
# Set the icon for this interface action # The get _ icons function is a builtin function defined for all your # plugin code. It loads icons from the plugin zip file. It returns # QIcon objects, if you want the actual data, use the analogous # get _ resources builtin function. # # Note that if you are loading more than one icon, for performance, you # should pass a list of names to get _ icons. In this case, get _ icons # will return a dictionary mapping names to QIcons. Names that # are not found in the zip file will result in null QIcons. icon = get _ icons(' images / icon. png ')
# The qaction is automatically created from the action _ spec defined # above self. qaction. setIcon( icon) self. qaction. triggered. connect( self. show _ dialog)
def show _ dialog( self):
190 Capítulo 1. Secciones