Manual de Calibre | Page 198

Manual de usuario de calibre, Publicación 2.73.0 Obtener recursos del archivo zip del complemento El sistema de carga de complementos de calibre tiene predefinidas un par de funciones que permiten obtener archivos desde el archivo zip del complemento de manera práctica. get_resources(nombre_o_lista_de_nombres) Esta función debe ejecutarse con una lista de rutas de acceso a archivos dentro del archivo zip. Por ejemplo, para acceder al archivo icon.png en la images del archivo zip, utilizaría: images/icon.png. Use siempre una barra inclinada a la derecha como separador de ruta, incluso en windows. Cuando se pasa un solo nombre, la función devolverá los bytes en bruto de ese archivo o None si el nombre no se encuentra en el archivo zip. Si se pasa más de un nombre, entonces devuelve un diccionario de mapeo de nombres a bytes. Si no se encuentra un nombre, no estará presente en el diccionario devuelto. get_icons(nombre_o_lista_de_nombres) Una envoltura práctica para get_resources() que crea objetos QIcon a partir de los bytes devueltos por get_resources. Si un nombre no se encuentra en el archivo zip, el QIcon correspondiente será nulo. Habilitar la configuración de usuario para el complemento Para permitir a los usuarios configurar el complemento, debe definir tres métodos en la clase base del complemento, is_customizable, config_widget y save_settings como se muestra a continuación: def is_customizable(self): ''' This method must return True to enable customization via Preferences->Plugins ''' return True def config_widget(self): ''' Implement this method and :meth:`save_settings` in your plugin to use a custom configuration dialog. This method, if implemented, must return a QWidget. The widget can have an optional method validate() that takes no arguments and is called immediately after the user clicks OK. Changes are applied if and only if the method returns True. If for some reason you cannot perform the configuration at this time, return a tuple of two strings (message, details), these will be displayed as a warning dialog to the user and the process will be aborted. The base class implementation of this method raises NotImplementedError so by default no user configuration is possible. ''' # It is important to put this import statement here rather than at the # top of the module as importing the config class will also cause the # GUI libraries to be loaded, which we do not want when using calibre # from the command line from calibre_plugins.interface_demo.config import ConfigWidget return ConfigWidget() def save_settings(self, config_widget): ''' 194 Capítulo 1. Secciones