mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add a reference to the plugin object in the Tool class and also improve
documentation a little
This commit is contained in:
parent
8b6aae9068
commit
04e4c25a90
@ -196,12 +196,4 @@ Viewer plugins
|
|||||||
:members:
|
:members:
|
||||||
:member-order: bysource
|
:member-order: bysource
|
||||||
|
|
||||||
Edit Book plugins
|
|
||||||
--------------------
|
|
||||||
|
|
||||||
.. autoclass:: calibre.gui2.tweak_book.plugin.Tool
|
|
||||||
:show-inheritance:
|
|
||||||
:members:
|
|
||||||
:member-order: bysource
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -121,6 +121,15 @@ Working with the Table of Contents
|
|||||||
.. autofunction:: create_inline_toc
|
.. autofunction:: create_inline_toc
|
||||||
|
|
||||||
|
|
||||||
|
Edit Book Tool
|
||||||
|
--------------------
|
||||||
|
|
||||||
|
.. autoclass:: calibre.gui2.tweak_book.plugin.Tool
|
||||||
|
:show-inheritance:
|
||||||
|
:members:
|
||||||
|
:member-order: bysource
|
||||||
|
|
||||||
|
|
||||||
Controlling the editor's user interface
|
Controlling the editor's user interface
|
||||||
-----------------------------------------
|
-----------------------------------------
|
||||||
|
|
||||||
|
@ -39,6 +39,8 @@ class Plugin(object): # {{{
|
|||||||
Useful methods:
|
Useful methods:
|
||||||
|
|
||||||
* :meth:`temporary_file`
|
* :meth:`temporary_file`
|
||||||
|
* :meth:`__enter__`
|
||||||
|
* :meth:`load_resources`
|
||||||
|
|
||||||
'''
|
'''
|
||||||
#: List of platforms this plugin works on
|
#: List of platforms this plugin works on
|
||||||
@ -263,6 +265,12 @@ class Plugin(object): # {{{
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def __enter__(self, *args):
|
def __enter__(self, *args):
|
||||||
|
'''
|
||||||
|
Add this plugin to the python path so that it's contents become directly importable.
|
||||||
|
Useful when bundling large python libraries into the plugin. Use it like this::
|
||||||
|
with plugin:
|
||||||
|
import something
|
||||||
|
'''
|
||||||
if self.plugin_path is not None:
|
if self.plugin_path is not None:
|
||||||
from calibre.utils.zipfile import ZipFile
|
from calibre.utils.zipfile import ZipFile
|
||||||
zf = ZipFile(self.plugin_path)
|
zf = ZipFile(self.plugin_path)
|
||||||
@ -272,6 +280,7 @@ class Plugin(object): # {{{
|
|||||||
for ext in ('pyd', 'so', 'dll', 'dylib'):
|
for ext in ('pyd', 'so', 'dll', 'dylib'):
|
||||||
if ext in extensions:
|
if ext in extensions:
|
||||||
zip_safe = False
|
zip_safe = False
|
||||||
|
break
|
||||||
if zip_safe:
|
if zip_safe:
|
||||||
sys.path.insert(0, self.plugin_path)
|
sys.path.insert(0, self.plugin_path)
|
||||||
self.sys_insertion_path = self.plugin_path
|
self.sys_insertion_path = self.plugin_path
|
||||||
|
@ -17,6 +17,22 @@ from calibre.gui2.tweak_book.boss import get_boss
|
|||||||
|
|
||||||
class Tool(object):
|
class Tool(object):
|
||||||
|
|
||||||
|
'''
|
||||||
|
.. module:: calibre.gui2.tweak_book.plugin.Tool
|
||||||
|
|
||||||
|
The base class for individual tools in an Edit Book plugin. Useful members include:
|
||||||
|
|
||||||
|
* ``self.plugin``: A reference to the :class:`calibre.customize.Plugin` object to which this tool belongs.
|
||||||
|
* self. :attr:`boss`
|
||||||
|
* self. :attr:`gui`
|
||||||
|
|
||||||
|
Methods that must be overridden in sub classes:
|
||||||
|
|
||||||
|
* :meth:`create_action`
|
||||||
|
* :meth:`register_shortcut`
|
||||||
|
|
||||||
|
'''
|
||||||
|
|
||||||
#: Set this to a unique name it will be used as a key
|
#: Set this to a unique name it will be used as a key
|
||||||
name = None
|
name = None
|
||||||
|
|
||||||
@ -103,7 +119,9 @@ def load_plugin_tools(plugin):
|
|||||||
else:
|
else:
|
||||||
for x in vars(main).itervalues():
|
for x in vars(main).itervalues():
|
||||||
if isinstance(x, type) and x is not Tool and issubclass(x, Tool):
|
if isinstance(x, type) and x is not Tool and issubclass(x, Tool):
|
||||||
yield x()
|
ans = x()
|
||||||
|
ans.plugin = plugin
|
||||||
|
yield ans
|
||||||
|
|
||||||
def plugin_action_sid(plugin, tool, for_toolbar=True):
|
def plugin_action_sid(plugin, tool, for_toolbar=True):
|
||||||
return plugin.name + tool.name + ('toolbar' if for_toolbar else 'menu')
|
return plugin.name + tool.name + ('toolbar' if for_toolbar else 'menu')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user