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_kind.setCurrentIndex(dex)
self.icon_field.setCurrentIndex(self.icon_field.findData(icon_field_key)) self.icon_field.setCurrentIndex(self.icon_field.findData(icon_field_key))
if dialog_is_st_editor: self.setup_saved_template_editor(not dialog_is_st_editor, 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)
# Remove help icon on title bar # Remove help icon on title bar
icon = self.windowIcon() icon = self.windowIcon()
self.setWindowFlags(self.windowFlags()&(~Qt.WindowType.WindowContextHelpButtonHint)) self.setWindowFlags(self.windowFlags()&(~Qt.WindowType.WindowContextHelpButtonHint))
@ -407,6 +400,13 @@ class TemplateDialog(QDialog, Ui_TemplateDialog):
except Exception: except Exception:
pass 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): def set_mi(self, mi, fm):
''' '''
This sets the metadata for the test result books table. It doesn't reset This sets the metadata for the test result books table. It doesn't reset

View File

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

View File

@ -74,18 +74,66 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
</p> </p>
''') ''')
self.textBrowser.setHtml(help_text) 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 Here you can create, edit (replace), and delete stored templates used
in template processing. You use a stored template in another template as in template processing. You use a stored template in another template as
if it were a template function, for example 'some_name(arg1, arg2...)'. if it were a template function, for example 'some_name(arg1, arg2...)'.</p>
Stored templates must use General Program Mode -- they must begin with
<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 text '{0}'. You retrieve arguments passed to a stored template using
the '{1}()' template function, as in '{1}(var1, var2, ...)'. The passed the '{1}()' template function, as in '{1}(var1, var2, ...)'. The passed
arguments are copied to the named variables. See the template language arguments are copied to the named variables.</p>
tutorial for more information.
''') + '</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.setHtml(help_text.format('program:', 'arguments'))
self.st_textBrowser_showing = True
self.st_textBrowser.adjustSize() 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): def initialize(self):
try: try:
@ -308,6 +356,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
def st_build_function_names_box(self, scroll_to=''): def st_build_function_names_box(self, scroll_to=''):
self.te_name.blockSignals(True) self.te_name.blockSignals(True)
func_names = sorted(self.st_funcs) func_names = sorted(self.st_funcs)
self.te_name.setMinimumContentsLength(40)
self.te_name.clear() self.te_name.clear()
self.te_name.addItem('') self.te_name.addItem('')
self.te_name.addItems(func_names) self.te_name.addItems(func_names)

View File

@ -24,20 +24,21 @@
<string>&amp;Stored Templates</string> <string>&amp;Stored Templates</string>
</attribute> </attribute>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="2" stretch="0"> <item row="0" column="0">
<widget class="QTextBrowser" name="st_textBrowser"> <widget class="QPushButton" name="st_show_hide_help_button">
<property name="maximumSize"> <property name="text">
<size> <string>Hide help</string>
<width>16777215</width>
<height>75</height>
</size>
</property> </property>
</widget> </widget>
</item> </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"/> <widget class="EmbeddedTemplateDialog" name="template_editor"/>
</item> </item>
<item row="3" column="0"> <item row="2" column="0">
<layout class="QVBoxLayout" name="st_button_layout"> <layout class="QVBoxLayout" name="st_button_layout">
<item> <item>
<widget class="QPushButton" name="st_clear_button"> <widget class="QPushButton" name="st_clear_button">
@ -112,145 +113,144 @@
<string>&amp;Template Functions</string> <string>&amp;Template Functions</string>
</attribute> </attribute>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="1" column="0" colspan="2"> <item row="0" column="0" colspan="2">
<widget class="Line" name="line"> <widget class="Line" name="line">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="0"> <item row="1" column="0">
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QGridLayout" name="gridLayout_3">
<item> <item row="0" column="0">
<layout class="QGridLayout" name="gridLayout_3"> <widget class="QPushButton" name="show_hide_help_button">
<item row="0" column="0"> <property name="text">
<widget class="QLabel" name="label_2"> <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>
</property>
<property name="buddy">
<cstring>function_name</cstring>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="function_name">
<property name="toolTip">
<string>Enter the name of the function to create.</string>
</property>
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_3">
<property name="toolTip">
<string/>
</property>
<property name="text">
<string>Argument &amp;count:</string>
</property>
<property name="buddy">
<cstring>argument_count</cstring>
</property>
</widget>
</item>
<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>
</property>
<property name="minimum">
<number>-1</number>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QTextEdit" name="documentation"/>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>D&amp;ocumentation:</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="buddy">
<cstring>documentation</cstring>
</property>
</widget>
</item>
<item row="5" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="clear_button">
<property name="text"> <property name="text">
<string>F&amp;unction:</string> <string>Clear</string>
</property>
<property name="buddy">
<cstring>function_name</cstring>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item>
<widget class="QComboBox" name="function_name"> <widget class="QPushButton" name="delete_button">
<property name="toolTip">
<string>Enter the name of the function to create.</string>
</property>
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_3">
<property name="toolTip">
<string/>
</property>
<property name="text"> <property name="text">
<string>Argument &amp;count:</string> <string>Delete</string>
</property>
<property name="buddy">
<cstring>argument_count</cstring>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="1"> <item>
<widget class="QSpinBox" name="argument_count"> <widget class="QPushButton" name="replace_button">
<property name="toolTip">
<string>Set this to -1 if the function takes a variable number of arguments</string>
</property>
<property name="minimum">
<number>-1</number>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QTextEdit" name="documentation"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_4">
<property name="text"> <property name="text">
<string>D&amp;ocumentation:</string> <string>Replace</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="buddy">
<cstring>documentation</cstring>
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="1"> <item>
<layout class="QHBoxLayout" name="horizontalLayout_2"> <widget class="QPushButton" name="create_button">
<item> <property name="text">
<widget class="QPushButton" name="clear_button"> <string>C&amp;reate</string>
<property name="text"> </property>
<string>Clear</string> </widget>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="delete_button">
<property name="text">
<string>Delete</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="replace_button">
<property name="text">
<string>Replace</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="create_button">
<property name="text">
<string>C&amp;reate</string>
</property>
</widget>
</item>
</layout>
</item> </item>
</layout> </layout>
</item> </item>
<item> <item row="2" column="2">
<layout class="QVBoxLayout" name="horizontalLayout1"> <widget class="QLabel" name="label_4">
<item> <property name="text">
<widget class="QLabel" name="label_4"> <string>P&amp;rogram code (Follow Python indenting rules):</string>
<property name="text"> </property>
<string>P&amp;rogram code (Follow Python indenting rules):</string> <property name="buddy">
</property> <cstring>program</cstring>
<property name="buddy"> </property>
<cstring>program</cstring> </widget>
</property> </item>
</widget> <item row="3" column="2" rowspan="3">
</item> <widget class="QPlainTextEdit" name="program">
<item> <property name="minimumSize">
<widget class="QPlainTextEdit" name="program"> <size>
<property name="minimumSize"> <width>400</width>
<size> <height>0</height>
<width>400</width> </size>
<height>0</height> </property>
</size> <property name="documentTitle">
</property> <string notr="true"/>
<property name="documentTitle"> </property>
<string notr="true"/> <property name="tabStopWidth">
</property> <number>30</number>
<property name="tabStopWidth"> </property>
<number>30</number> </widget>
</property>
</widget>
</item>
</layout>
</item> </item>
</layout> </layout>
</item> </item>
<item row="0" column="0">
<widget class="QTextBrowser" name="textBrowser"/>
</item>
</layout> </layout>
</widget> </widget>
</widget> </widget>