Basic cleanups for the python template function merge

This commit is contained in:
Kovid Goyal 2020-10-03 09:18:18 +05:30
parent 7e577735ba
commit 2d9ac6aa54
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 9 additions and 15 deletions

View File

@ -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.

View File

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

View File

@ -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

View File

@ -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 ''