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 @@ - - - Template &name: - - - template_name - - + + + + + Template &name: + + + template_name + + + + + + + true + + + The name of the callable template + + + + - - - - true - - - The name of the callable template - - - - + + + T&emplate: @@ -178,13 +184,21 @@ textbox + + The text of the template program goes into the box below + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - + + + + + + + + @@ -320,10 +334,12 @@ you the value as well as all the local variables</p> - + - The template program text + <p>The text of the template program goes in this box. + Don't forget that a General Program Mode template must begin with + the word "program:".</p> @@ -346,7 +362,7 @@ you the value as well as all the local variables</p> - + Documentation for the function being defined or edited @@ -366,7 +382,7 @@ you the value as well as all the local variables</p> - + @@ -519,7 +535,7 @@ you the value as well as all the local variables</p> - + @@ -555,10 +571,6 @@ you the value as well as all the local variables</p> - - - - @@ -605,6 +617,19 @@ you the value as well as all the local variables</p> + + + + Qt::Horizontal + + + + 10 + 0 + + + + @@ -617,14 +642,14 @@ you the value as well as all the local variables</p> - + QFrame::HLine - + diff --git a/src/calibre/gui2/preferences/template_functions.py b/src/calibre/gui2/preferences/template_functions.py index 43f8a871db..0c5fcfe036 100644 --- a/src/calibre/gui2/preferences/template_functions.py +++ b/src/calibre/gui2/preferences/template_functions.py @@ -74,18 +74,66 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):

''') self.textBrowser.setHtml(help_text) - help_text = '

' + _(''' + 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 @@ &Stored Templates - - - - - 16777215 - 75 - + + + + Hide help - + + + + + - + @@ -112,145 +113,144 @@ &Template Functions - + Qt::Horizontal - - - - - - + + + + + + Hide help + + + + + + + + + + F&unction: + + + function_name + + + + + + + Enter the name of the function to create. + + + true + + + + + + + + + + Argument &count: + + + argument_count + + + + + + + Set this to -1 if the function takes a variable number of arguments + + + -1 + + + + + + + + + + D&ocumentation: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + documentation + + + + + + + - F&unction: - - - function_name + Clear - - - - Enter the name of the function to create. - - - true - - - - - - - - + + - Argument &count: - - - argument_count + Delete - - - - Set this to -1 if the function takes a variable number of arguments - - - -1 - - - - - - - - + + - D&ocumentation: - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - documentation + Replace - - - - - - Clear - - - - - - - Delete - - - - - - - Replace - - - - - - - C&reate - - - - + + + + C&reate + + - - - - - - P&rogram code (Follow Python indenting rules): - - - program - - - - - - - - 400 - 0 - - - - - - - 30 - - - - + + + + P&rogram code (Follow Python indenting rules): + + + program + + + + + + + + 400 + 0 + + + + + + + 30 + + - - -