More work on edit book plugin interface

This commit is contained in:
Kovid Goyal 2014-07-10 11:27:10 +05:30
parent cc05dee17e
commit 60a346f565
3 changed files with 50 additions and 1 deletions

View File

@ -743,6 +743,8 @@ class ViewerPlugin(Plugin): # {{{
# }}} # }}}
class EditBookToolPlugin(Plugin): # {{{ class EditBookToolPlugin(Plugin): # {{{
pass
minimum_calibre_version = (1, 45, 0)
# }}} # }}}

View File

@ -70,9 +70,14 @@ def in_thread_job(func):
return func(*args, **kwargs) return func(*args, **kwargs)
return ans return ans
_boss = None
def get_boss():
return _boss
class Boss(QObject): class Boss(QObject):
def __init__(self, parent, notify=None): def __init__(self, parent, notify=None):
global _boss
QObject.__init__(self, parent) QObject.__init__(self, parent)
self.global_undo = GlobalUndoHistory() self.global_undo = GlobalUndoHistory()
self.container_count = 0 self.container_count = 0
@ -82,6 +87,7 @@ class Boss(QObject):
self.doing_terminal_save = False self.doing_terminal_save = False
self.ignore_preview_to_editor_sync = False self.ignore_preview_to_editor_sync = False
setup_cssutils_serialization() setup_cssutils_serialization()
_boss = self
def __call__(self, gui): def __call__(self, gui):
self.gui = gui self.gui = gui

View File

@ -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 <kovid at kovidgoyal.net>'
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()