Add a new tool to easily test templates. Go to Preferences->Toolbars to add the tool to one of the calibre toolbars. Fixes #1360550 [Shortcut to template editor](https://bugs.launchpad.net/calibre/+bug/1360550)

Merge branch 'master' of https://github.com/cbhaley/calibre
This commit is contained in:
Kovid Goyal 2014-08-24 13:53:21 +05:30
commit 03f19243bb
2 changed files with 51 additions and 1 deletions

View File

@ -834,6 +834,11 @@ class ActionQuickview(InterfaceActionBase):
actual_plugin = 'calibre.gui2.actions.show_quickview:ShowQuickviewAction'
description = _('Show a list of related books quickly')
class ActionTemplateTester(InterfaceActionBase):
name = 'Template Tester'
actual_plugin = 'calibre.gui2.actions.show_template_tester:ShowTemplateTesterAction'
description = _('Show an editor for testing templates')
class ActionSaveToDisk(InterfaceActionBase):
name = 'Save To Disk'
actual_plugin = 'calibre.gui2.actions.save_to_disk:SaveToDiskAction'
@ -969,7 +974,7 @@ plugins += [ActionAdd, ActionFetchAnnotations, ActionGenerateCatalog,
ActionAddToLibrary, ActionEditCollections, ActionMatchBooks, ActionChooseLibrary,
ActionCopyToLibrary, ActionTweakEpub, ActionUnpackBook, ActionNextMatch, ActionStore,
ActionPluginUpdater, ActionPickRandom, ActionEditToC, ActionSortBy,
ActionMarkBooks, ActionEmbed]
ActionMarkBooks, ActionEmbed, ActionTemplateTester]
# }}}

View File

@ -0,0 +1,45 @@
#!/usr/bin/env python
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
__license__ = 'GPL v3'
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en'
from calibre.gui2.actions import InterfaceAction
from calibre.gui2.dialogs.template_dialog import TemplateDialog
from calibre.gui2 import error_dialog
class ShowTemplateTesterAction(InterfaceAction):
name = 'Template tester'
action_spec = (_('Template tester'), 'debug.png', None, '')
dont_add_to = frozenset(['context-menu-device'])
action_type = 'current'
def genesis(self):
self.qaction.triggered.connect(self.show_template_editor)
def show_template_editor(self, *args):
view = self.gui.current_view()
if view is not self.gui.library_view:
return error_dialog(self.gui, _('No template tester available'),
_('Template tester is not available for books '
'on the device.')).exec_()
rows = view.selectionModel().selectedRows()
if not rows:
return error_dialog(self.gui, _('No books selected'),
_('A book must be selected'), show=True)
if len(rows) > 1:
return error_dialog(self.gui, _('Selected multiple books'),
_('Only one book can be selected'), show=True)
index = rows[0]
if index.isValid():
db = view.model().db
t = TemplateDialog(self.gui, _('Enter a template to test'),
mi=db.get_metadata(index.row(), index_is_id=False,
get_cover=False))
t.setWindowTitle(_('Template tester'))
t.exec_()