diff --git a/src/calibre/gui2/dialogs/template_dialog.py b/src/calibre/gui2/dialogs/template_dialog.py
index cc5a344375..8f597d53f2 100644
--- a/src/calibre/gui2/dialogs/template_dialog.py
+++ b/src/calibre/gui2/dialogs/template_dialog.py
@@ -299,14 +299,7 @@ class TemplateDialog(QDialog, Ui_TemplateDialog):
self.icon_kind.setCurrentIndex(dex)
self.icon_field.setCurrentIndex(self.icon_field.findData(icon_field_key))
- if dialog_is_st_editor:
- self.buttonBox.setVisible(False)
- else:
- self.new_doc_label.setVisible(False)
- self.new_doc.setVisible(False)
- self.template_name_label.setVisible(False)
- self.template_name.setVisible(False)
-
+ self.setup_saved_template_editor(not dialog_is_st_editor, dialog_is_st_editor)
# Remove help icon on title bar
icon = self.windowIcon()
self.setWindowFlags(self.windowFlags()&(~Qt.WindowType.WindowContextHelpButtonHint))
@@ -407,6 +400,13 @@ class TemplateDialog(QDialog, Ui_TemplateDialog):
except Exception:
pass
+ def setup_saved_template_editor(self, show_buttonbox, show_doc_and_name):
+ self.buttonBox.setVisible(show_buttonbox)
+ self.new_doc_label.setVisible(show_doc_and_name)
+ self.new_doc.setVisible(show_doc_and_name)
+ self.template_name_label.setVisible(show_doc_and_name)
+ self.template_name.setVisible(show_doc_and_name)
+
def set_mi(self, mi, fm):
'''
This sets the metadata for the test result books table. It doesn't reset
diff --git a/src/calibre/gui2/dialogs/template_dialog.ui b/src/calibre/gui2/dialogs/template_dialog.ui
index 6ad74354f2..2c3eb4b9f2 100644
--- a/src/calibre/gui2/dialogs/template_dialog.ui
+++ b/src/calibre/gui2/dialogs/template_dialog.ui
@@ -151,26 +151,32 @@
' + _(''' + self.textBrowser_showing = True + self.textBrowser.adjustSize() + self.show_hide_help_button.clicked.connect(self.show_hide_help) + help_text = _(''' +
Here you can create, edit (replace), and delete stored templates used in template processing. You use a stored template in another template as - if it were a template function, for example 'some_name(arg1, arg2...)'. - Stored templates must use General Program Mode -- they must begin with + if it were a template function, for example 'some_name(arg1, arg2...)'.
+ +Stored templates must use General Program Mode -- they must begin with the text '{0}'. You retrieve arguments passed to a stored template using the '{1}()' template function, as in '{1}(var1, var2, ...)'. The passed - arguments are copied to the named variables. See the template language - tutorial for more information. - ''') + '
' + arguments are copied to the named variables. + +For example, this stored template checks if any items are in a + list, returning '1' if any are found and '' if not.
+
+ Template name: items_in_list
+ Template contents:
+ program: + arguments(lst='No list argument given', items=''); + r = ''; + for l in items: + if str_in_list(lst, ',', l, '1', '') then + r = '1'; + break + fi + rof; + r+ You call the stored template like this:
+ program: items_in_list($#genre, 'comics, foo')+ See the template language tutorial for more information. + + ''') self.st_textBrowser.setHtml(help_text.format('program:', 'arguments')) + self.st_textBrowser_showing = True self.st_textBrowser.adjustSize() + self.st_show_hide_help_button.clicked.connect(self.st_show_hide_help) + + def st_show_hide_help(self): + if self.st_textBrowser_showing: + self.st_textBrowser_height = self.st_textBrowser.height() + self.st_textBrowser.setMaximumHeight(self.st_show_hide_help_button.height()) + self.st_textBrowser_showing = False + self.st_show_hide_help_button.setText(_('Show help')) + else: + self.st_textBrowser.setMaximumHeight(self.st_textBrowser_height) + self.st_textBrowser_showing = True + self.st_show_hide_help_button.setText(_('Hide help')) + + def show_hide_help(self): + if self.textBrowser_showing: + self.textBrowser_height = self.textBrowser.height() + self.textBrowser.setMaximumHeight(self.show_hide_help_button.height()) + self.textBrowser_showing = False + self.show_hide_help_button.setText(_('Show help')) + else: + self.textBrowser.setMaximumHeight(self.textBrowser_height) + self.textBrowser_showing = True + self.show_hide_help_button.setText(_('Hide help')) def initialize(self): try: @@ -308,6 +356,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): def st_build_function_names_box(self, scroll_to=''): self.te_name.blockSignals(True) func_names = sorted(self.st_funcs) + self.te_name.setMinimumContentsLength(40) self.te_name.clear() self.te_name.addItem('') self.te_name.addItems(func_names) diff --git a/src/calibre/gui2/preferences/template_functions.ui b/src/calibre/gui2/preferences/template_functions.ui index d8961fdfb4..9f3206affe 100644 --- a/src/calibre/gui2/preferences/template_functions.ui +++ b/src/calibre/gui2/preferences/template_functions.ui @@ -24,20 +24,21 @@