mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Plumbing for InterfaceAction plugins
This commit is contained in:
parent
e243aeeaff
commit
5d96982933
@ -351,3 +351,6 @@ class CatalogPlugin(Plugin):
|
||||
# Default implementation does nothing
|
||||
raise NotImplementedError('CatalogPlugin.generate_catalog() default '
|
||||
'method, should be overridden in subclass')
|
||||
|
||||
class InterfaceActionBase(Plugin):
|
||||
pass
|
||||
|
@ -6,7 +6,8 @@ import os, shutil, traceback, functools, sys, re
|
||||
from contextlib import closing
|
||||
|
||||
from calibre.customize import Plugin, CatalogPlugin, FileTypePlugin, \
|
||||
MetadataReaderPlugin, MetadataWriterPlugin
|
||||
MetadataReaderPlugin, MetadataWriterPlugin, \
|
||||
InterfaceActionBase as InterfaceAction
|
||||
from calibre.customize.conversion import InputFormatPlugin, OutputFormatPlugin
|
||||
from calibre.customize.profiles import InputProfile, OutputProfile
|
||||
from calibre.customize.builtins import plugins as builtin_plugins
|
||||
@ -19,7 +20,6 @@ from calibre.utils.config import make_config_dir, Config, ConfigProxy, \
|
||||
plugin_dir, OptionParser, prefs
|
||||
from calibre.ebooks.epub.fix import ePubFixer
|
||||
|
||||
|
||||
platform = 'linux'
|
||||
if iswindows:
|
||||
platform = 'windows'
|
||||
@ -246,6 +246,17 @@ def cover_sources():
|
||||
|
||||
# }}}
|
||||
|
||||
# Interface Actions # {{{
|
||||
|
||||
def interface_actions():
|
||||
customization = config['plugin_customization']
|
||||
for plugin in _initialized_plugins:
|
||||
if isinstance(plugin, InterfaceAction):
|
||||
if not is_disabled(plugin):
|
||||
plugin.site_customization = customization.get(plugin.name, '')
|
||||
yield plugin
|
||||
# }}}
|
||||
|
||||
# Metadata read/write {{{
|
||||
_metadata_readers = {}
|
||||
_metadata_writers = {}
|
||||
|
@ -244,14 +244,20 @@ def info_dialog(parent, title, msg, det_msg='', show=False):
|
||||
|
||||
|
||||
class Dispatcher(QObject):
|
||||
'''Convenience class to ensure that a function call always happens in the
|
||||
thread the receiver was created in.'''
|
||||
'''
|
||||
Convenience class to use Qt signals with arbitrary python callables.
|
||||
By default, ensures that a function call always happens in the
|
||||
thread this Dispatcher was created in.
|
||||
'''
|
||||
dispatch_signal = pyqtSignal(object, object)
|
||||
|
||||
def __init__(self, func):
|
||||
QObject.__init__(self)
|
||||
def __init__(self, func, queued=True, parent=None):
|
||||
QObject.__init__(self, parent)
|
||||
self.func = func
|
||||
self.dispatch_signal.connect(self.dispatch, type=Qt.QueuedConnection)
|
||||
typ = Qt.QueuedConnection
|
||||
if not queued:
|
||||
typ = Qt.AutoConnection if queued is None else Qt.DirectConnection
|
||||
self.dispatch_signal.connect(self.dispatch, type=typ)
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
self.dispatch_signal.emit(args, kwargs)
|
||||
|
@ -6,6 +6,23 @@ __copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
|
||||
from calibre.customize import InterfaceActionBase
|
||||
|
||||
class InterfaceAction(InterfaceActionBase):
|
||||
|
||||
supported_platforms = ['windows', 'osx', 'linux']
|
||||
author = 'Kovid Goyal'
|
||||
type = _('User Interface Action')
|
||||
|
||||
positions = frozenset([])
|
||||
separators = frozenset([])
|
||||
|
||||
def do_genesis(self, gui):
|
||||
self.gui = gui
|
||||
self.genesis()
|
||||
|
||||
# Subclassable methods {{{
|
||||
def genesis(self):
|
||||
raise NotImplementedError()
|
||||
# }}}
|
||||
|
||||
|
@ -17,12 +17,14 @@ from calibre.gui2.widgets import IMAGE_EXTENSIONS
|
||||
from calibre.ebooks import BOOK_EXTENSIONS
|
||||
from calibre.utils.filenames import ascii_filename
|
||||
from calibre.constants import preferred_encoding, filesystem_encoding
|
||||
from calibre.gui2.actions import InterfaceAction
|
||||
|
||||
class AddAction(InterfaceAction):
|
||||
|
||||
class AddAction(object):
|
||||
def genesis(self):
|
||||
self._add_filesystem_book = Dispatcher(self.__add_filesystem_book,
|
||||
parent=self.gui)
|
||||
|
||||
def __init__(self):
|
||||
self._add_filesystem_book = Dispatcher(self.__add_filesystem_book)
|
||||
|
||||
def add_recursive(self, single):
|
||||
root = choose_dir(self, 'recursive book import root dir dialog',
|
||||
|
@ -157,4 +157,11 @@ The base class for such devices is :class:`calibre.devices.usbms.driver.USBMS`.
|
||||
:members:
|
||||
:member-order: bysource
|
||||
|
||||
User Interface Actions
|
||||
--------------------------
|
||||
|
||||
.. autoclass:: calibre.gui2.actions.InterfaceAction
|
||||
:show-inheritance:
|
||||
:members:
|
||||
:member-order: bysource
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user