From 2d9ac6aa54f1dc7f0cae7a5faa8251c13e781cb4 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 3 Oct 2020 09:18:18 +0530 Subject: [PATCH] Basic cleanups for the python template function merge --- manual/template_lang.rst | 4 ++-- src/calibre/gui2/actions/show_stored_templates.py | 8 +------- src/calibre/gui2/preferences/template_functions.py | 6 +++--- src/calibre/utils/formatter.py | 6 +++--- 4 files changed, 9 insertions(+), 15 deletions(-) diff --git a/manual/template_lang.rst b/manual/template_lang.rst index 3a940231b0..896a541b90 100644 --- a/manual/template_lang.rst +++ b/manual/template_lang.rst @@ -509,8 +509,8 @@ The following program produces the same results as the original recipe, using on It would be possible to do the above with no custom columns by putting the program into the template box of the plugboard. However, to do so, all comments must be removed because the plugboard text box does not support multi-line editing. It is debatable whether the gain of not having the custom column is worth the vast increase in difficulty caused by the program being one giant line. -User-defined python template functions -------------------------------- +User-defined Python template functions +------------------------------------------ You can add your own python functions to the template processor. Such functions are written in Python, and can be used in any of the three template programming modes. The functions are added by going to guilabel`Preferences -> Advanced -> Template functions`. Instructions are shown in that dialog. diff --git a/src/calibre/gui2/actions/show_stored_templates.py b/src/calibre/gui2/actions/show_stored_templates.py index 33fe1f8d38..6c43e2b447 100644 --- a/src/calibre/gui2/actions/show_stored_templates.py +++ b/src/calibre/gui2/actions/show_stored_templates.py @@ -1,11 +1,6 @@ #!/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' - +# License: GPLv3 Copyright: 2020, Charles Haley from calibre.gui2.actions import InterfaceAction from calibre.gui2.preferences.main import Preferences @@ -27,4 +22,3 @@ class ShowTemplateFunctionsAction(InterfaceAction): d = Preferences(self.gui, initial_plugin=('Advanced', 'TemplateFunctions'), close_after_initial=True) d.exec_() - diff --git a/src/calibre/gui2/preferences/template_functions.py b/src/calibre/gui2/preferences/template_functions.py index 00957f4042..e8f8010dbd 100644 --- a/src/calibre/gui2/preferences/template_functions.py +++ b/src/calibre/gui2/preferences/template_functions.py @@ -345,7 +345,6 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): def commit(self): pref_value = [] for name, cls in iteritems(self.funcs): - print(name) if name not in self.builtins: pref_value.append(cls.to_pref()) for v in self.st_funcs.values(): @@ -359,6 +358,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): if __name__ == '__main__': - from PyQt5.Qt import QApplication - app = QApplication([]) + from calibre import Application + app = Application([]) test_widget('Advanced', 'TemplateFunctions') + del app diff --git a/src/calibre/utils/formatter.py b/src/calibre/utils/formatter.py index f58d0dd30c..865d93c8cd 100644 --- a/src/calibre/utils/formatter.py +++ b/src/calibre/utils/formatter.py @@ -307,7 +307,7 @@ class _Parser(object): if subprog is None: text = self.funcs[name].program_text if not text.startswith('program:'): - self.error((_('A stored template must begin with program:'))) + self.error(_('A stored template must begin with program:')) text = text[len('program:'):] subprog = _Parser().program(self, self.funcs, self.parent.lex_scanner.scan(text)) @@ -462,7 +462,7 @@ class _Interpreter(object): def do_node_call(self, prog, args=None): if args is None: - args = list() + args = [] for arg in prog.expression_list: # evaluate the expression (recursive call) args.append(self.expr(arg)) @@ -475,7 +475,7 @@ class _Interpreter(object): return val def do_node_arguments(self, prog): - for dex,arg in enumerate(prog.expression_list): + for dex, arg in enumerate(prog.expression_list): self.locals[arg.left] = self.locals.get('*arg_'+ str(dex), self.expr(arg.right)) return ''