diff --git a/src/calibre/customize/builtins.py b/src/calibre/customize/builtins.py index 97c4c7f0af..6abf7b4808 100644 --- a/src/calibre/customize/builtins.py +++ b/src/calibre/customize/builtins.py @@ -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] # }}} diff --git a/src/calibre/gui2/actions/show_template_tester.py b/src/calibre/gui2/actions/show_template_tester.py new file mode 100644 index 0000000000..7a2e4d9f53 --- /dev/null +++ b/src/calibre/gui2/actions/show_template_tester.py @@ -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 ' +__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_() \ No newline at end of file