This commit is contained in:
Kovid Goyal 2021-04-11 20:45:56 +05:30
commit b74ca85fd6
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 245 additions and 171 deletions

View File

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

View File

@ -151,6 +151,8 @@
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<layout class="QHBoxLayout">
<item>
<widget class="QLabel" name="template_name_label">
<property name="text">
<string>Template &amp;name:</string>
@ -160,7 +162,7 @@
</property>
</widget>
</item>
<item row="0" column="1">
<item>
<widget class="QComboBox" name="template_name">
<property name="editable">
<bool>true</bool>
@ -170,7 +172,11 @@
</property>
</widget>
</item>
<item row="1" column="0">
</layout>
</item>
<item row="1" column="0" colspan="3">
<layout class="FlowLayout">
<item>
<widget class="QLabel">
<property name="text">
<string>T&amp;emplate:</string>
@ -178,13 +184,21 @@
<property name="buddy">
<cstring>textbox</cstring>
</property>
<property name="toolTip">
<string>The text of the template program goes into the box below</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="1" colspan="3">
<layout class="FlowLayout">
<item>
<widget class="QLabel">
<property name="text">
<string> </string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="break_box">
<property name="text">
@ -320,10 +334,12 @@ you the value as well as all the local variables&lt;/p&gt;</string>
</item>
</layout>
</item>
<item row="2" column="0" colspan="4">
<item row="2" column="0" colspan="3">
<widget class="CodeEditor" name="textbox">
<property name="toolTip">
<string>The template program text</string>
<string>&lt;p&gt;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:".&lt;/p&gt;</string>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
@ -346,7 +362,7 @@ you the value as well as all the local variables&lt;/p&gt;</string>
</property>
</widget>
</item>
<item row="3" column="1">
<item row="4" column="0" colspan="3">
<widget class="QTextEdit" name="new_doc">
<property name="toolTip">
<string>Documentation for the function being defined or edited</string>
@ -366,7 +382,7 @@ you the value as well as all the local variables&lt;/p&gt;</string>
</property>
</widget>
</item>
<item row="8" column="0" colspan="4">
<item row="8" column="0" colspan="3">
<widget class="QTableWidget" name="template_value">
</widget>
</item>
@ -519,7 +535,7 @@ you the value as well as all the local variables&lt;/p&gt;</string>
</property>
</widget>
</item>
<item row="24" column="0" colspan="2">
<item row="24" column="0" colspan="3">
<layout class="QHBoxLayout">
<item>
<widget class="QLabel" name="font_name_label">
@ -555,10 +571,6 @@ you the value as well as all the local variables&lt;/p&gt;</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="24" column="3">
<layout class="QHBoxLayout">
<item>
<widget class="QFrame" name="frame">
<property name="frameShape">
@ -605,6 +617,19 @@ you the value as well as all the local variables&lt;/p&gt;</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>10</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
@ -617,14 +642,14 @@ you the value as well as all the local variables&lt;/p&gt;</string>
</item>
</layout>
</item>
<item row="25" column="0" colspan="4">
<item row="25" column="0" colspan="3">
<widget class="QFrame">
<property name="frameShape">
<enum>QFrame::HLine</enum>
</property>
</widget>
</item>
<item row="30" column="0" colspan="4">
<item row="30" column="0" colspan="3">
<layout class="QGridLayout">
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="label">

View File

@ -74,18 +74,66 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
</p>
''')
self.textBrowser.setHtml(help_text)
help_text = '<p>' + _('''
self.textBrowser_showing = True
self.textBrowser.adjustSize()
self.show_hide_help_button.clicked.connect(self.show_hide_help)
help_text = _('''
<p>
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...)'.</p>
<p>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.
''') + '</p>'
arguments are copied to the named variables.</p>
<p>For example, this stored template checks if any items are in a
list, returning '1' if any are found and '' if not.</p>
<p>
Template name: items_in_list<br>
Template contents:<pre>
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</pre>
You call the stored template like this:<pre>
program: items_in_list($#genre, 'comics, foo')</pre>
See the template language tutorial for more information.</p>
</p>
''')
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)

View File

@ -24,20 +24,21 @@
<string>&amp;Stored Templates</string>
</attribute>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="2" stretch="0">
<widget class="QTextBrowser" name="st_textBrowser">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>75</height>
</size>
<item row="0" column="0">
<widget class="QPushButton" name="st_show_hide_help_button">
<property name="text">
<string>Hide help</string>
</property>
</widget>
</item>
<item row="3" column="1" stretch="1">
<item row="0" column="1" colspan="1" rowspan="2">
<widget class="QTextBrowser" name="st_textBrowser">
</widget>
</item>
<item row="2" column="1" stretch="1">
<widget class="EmbeddedTemplateDialog" name="template_editor"/>
</item>
<item row="3" column="0">
<item row="2" column="0">
<layout class="QVBoxLayout" name="st_button_layout">
<item>
<widget class="QPushButton" name="st_clear_button">
@ -112,18 +113,26 @@
<string>&amp;Template Functions</string>
</attribute>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0" colspan="2">
<item row="0" column="0" colspan="2">
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="2" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<item row="1" column="0">
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QPushButton" name="show_hide_help_button">
<property name="text">
<string>Hide help</string>
</property>
</widget>
</item>
<item row="0" column="1" colspan="2" rowspan="2">
<widget class="QTextBrowser" name="textBrowser"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>F&amp;unction:</string>
@ -133,7 +142,7 @@
</property>
</widget>
</item>
<item row="0" column="1">
<item row="2" column="1">
<widget class="QComboBox" name="function_name">
<property name="toolTip">
<string>Enter the name of the function to create.</string>
@ -143,7 +152,7 @@
</property>
</widget>
</item>
<item row="1" column="0">
<item row="3" column="0">
<widget class="QLabel" name="label_3">
<property name="toolTip">
<string/>
@ -156,7 +165,7 @@
</property>
</widget>
</item>
<item row="1" column="1">
<item row="3" column="1">
<widget class="QSpinBox" name="argument_count">
<property name="toolTip">
<string>Set this to -1 if the function takes a variable number of arguments</string>
@ -166,10 +175,10 @@
</property>
</widget>
</item>
<item row="2" column="1">
<item row="4" column="1">
<widget class="QTextEdit" name="documentation"/>
</item>
<item row="2" column="0">
<item row="4" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>D&amp;ocumentation:</string>
@ -182,7 +191,7 @@
</property>
</widget>
</item>
<item row="3" column="1">
<item row="5" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="clear_button">
@ -214,11 +223,7 @@
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="horizontalLayout1">
<item>
<item row="2" column="2">
<widget class="QLabel" name="label_4">
<property name="text">
<string>P&amp;rogram code (Follow Python indenting rules):</string>
@ -228,7 +233,7 @@
</property>
</widget>
</item>
<item>
<item row="3" column="2" rowspan="3">
<widget class="QPlainTextEdit" name="program">
<property name="minimumSize">
<size>
@ -247,11 +252,6 @@
</layout>
</item>
</layout>
</item>
<item row="0" column="0">
<widget class="QTextBrowser" name="textBrowser"/>
</item>
</layout>
</widget>
</widget>
</item>