From 60a346f565319af3df056af11708d785d2f06ce5 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 10 Jul 2014 11:27:10 +0530 Subject: [PATCH] More work on edit book plugin interface --- src/calibre/customize/__init__.py | 4 ++- src/calibre/gui2/tweak_book/boss.py | 6 ++++ src/calibre/gui2/tweak_book/plugin.py | 41 +++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 src/calibre/gui2/tweak_book/plugin.py diff --git a/src/calibre/customize/__init__.py b/src/calibre/customize/__init__.py index cbb3d9c64f..e2b8582af7 100644 --- a/src/calibre/customize/__init__.py +++ b/src/calibre/customize/__init__.py @@ -743,6 +743,8 @@ class ViewerPlugin(Plugin): # {{{ # }}} class EditBookToolPlugin(Plugin): # {{{ - pass + + minimum_calibre_version = (1, 45, 0) + # }}} diff --git a/src/calibre/gui2/tweak_book/boss.py b/src/calibre/gui2/tweak_book/boss.py index 3a32a5a528..b29dfaaf8f 100644 --- a/src/calibre/gui2/tweak_book/boss.py +++ b/src/calibre/gui2/tweak_book/boss.py @@ -70,9 +70,14 @@ def in_thread_job(func): return func(*args, **kwargs) return ans +_boss = None +def get_boss(): + return _boss + class Boss(QObject): def __init__(self, parent, notify=None): + global _boss QObject.__init__(self, parent) self.global_undo = GlobalUndoHistory() self.container_count = 0 @@ -82,6 +87,7 @@ class Boss(QObject): self.doing_terminal_save = False self.ignore_preview_to_editor_sync = False setup_cssutils_serialization() + _boss = self def __call__(self, gui): self.gui = gui diff --git a/src/calibre/gui2/tweak_book/plugin.py b/src/calibre/gui2/tweak_book/plugin.py new file mode 100644 index 0000000000..35a54143d5 --- /dev/null +++ b/src/calibre/gui2/tweak_book/plugin.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python +# vim:fileencoding=utf-8 +from __future__ import (unicode_literals, division, absolute_import, + print_function) + +__license__ = 'GPL v3' +__copyright__ = '2014, Kovid Goyal ' + +from calibre.gui2.tweak_book.boss import get_boss + +class Tool(object): + + #: Set this to a unique name it will be used as a key + name = None + + #: If True the user can choose to place this tool in the plugins toolbar + allowed_in_toolbar = True + + #: If True the user can choose to place this tool in the plugins menu + allowed_in_menu = True + + @property + def boss(self): + ' The :class:`calibre.gui2.tweak_book.boss.Boss` object. Used to control the user interface. ' + return get_boss() + + @property + def gui(self): + ' The main window of the user interface ' + return self.boss.gui + + def create_action(self, for_toolbar=True): + ''' + Create a QAction that will be added to either the plugins toolbar or + the plugins menu depending on ``for_toolbar``. For example:: + + def create_action(self, for_toolbar): + ac = QAction( + ''' + raise NotImplementedError() +