mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
1) Re-enable syntactic validation of save templates.
2) fix row numbering on send_to_device preferences ui template.
This commit is contained in:
parent
e1dd08acef
commit
4645138a67
@ -8,8 +8,10 @@ __docformat__ = 'restructuredtext en'
|
|||||||
|
|
||||||
from PyQt4.Qt import QWidget, pyqtSignal
|
from PyQt4.Qt import QWidget, pyqtSignal
|
||||||
|
|
||||||
|
from calibre.gui2 import error_dialog
|
||||||
from calibre.gui2.preferences.save_template_ui import Ui_Form
|
from calibre.gui2.preferences.save_template_ui import Ui_Form
|
||||||
from calibre.library.save_to_disk import FORMAT_ARG_DESCS
|
from calibre.library.save_to_disk import FORMAT_ARG_DESCS, preprocess_template,\
|
||||||
|
safe_format
|
||||||
|
|
||||||
class SaveTemplate(QWidget, Ui_Form):
|
class SaveTemplate(QWidget, Ui_Form):
|
||||||
|
|
||||||
@ -24,8 +26,11 @@ class SaveTemplate(QWidget, Ui_Form):
|
|||||||
variables = sorted(FORMAT_ARG_DESCS.keys())
|
variables = sorted(FORMAT_ARG_DESCS.keys())
|
||||||
rows = []
|
rows = []
|
||||||
for var in variables:
|
for var in variables:
|
||||||
rows.append(u'<tr><td>%s</td><td>%s</td></tr>'%
|
rows.append(u'<tr><td>%s</td><td> </td><td>%s</td></tr>'%
|
||||||
(var, FORMAT_ARG_DESCS[var]))
|
(var, FORMAT_ARG_DESCS[var]))
|
||||||
|
rows.append(u'<tr><td>%s </td><td> </td><td>%s</td></tr>'%(
|
||||||
|
_('Any custom field'),
|
||||||
|
_('The lookup name of any custom field. These names begin with "#")')))
|
||||||
table = u'<table>%s</table>'%(u'\n'.join(rows))
|
table = u'<table>%s</table>'%(u'\n'.join(rows))
|
||||||
self.template_variables.setText(table)
|
self.template_variables.setText(table)
|
||||||
|
|
||||||
@ -39,21 +44,21 @@ class SaveTemplate(QWidget, Ui_Form):
|
|||||||
self.changed_signal.emit()
|
self.changed_signal.emit()
|
||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
# TODO: NEWMETA: I haven't figured out how to get the custom columns
|
'''
|
||||||
# into here, so for the moment make all templates valid.
|
Do a syntax check on the format string. Doing a semantic check
|
||||||
|
(verifying that the fields exist) is not useful in the presence of
|
||||||
|
custom fields, because they may or may not exist.
|
||||||
|
'''
|
||||||
|
tmpl = preprocess_template(self.opt_template.text())
|
||||||
|
fa = {}
|
||||||
|
try:
|
||||||
|
safe_format(tmpl, fa)
|
||||||
|
except Exception, err:
|
||||||
|
error_dialog(self, _('Invalid template'),
|
||||||
|
'<p>'+_('The template %s is invalid:')%tmpl + \
|
||||||
|
'<br>'+str(err), show=True)
|
||||||
|
return False
|
||||||
return True
|
return True
|
||||||
# tmpl = preprocess_template(self.opt_template.text())
|
|
||||||
# fa = {}
|
|
||||||
# for x in FORMAT_ARG_DESCS.keys():
|
|
||||||
# fa[x]='random long string'
|
|
||||||
# try:
|
|
||||||
# tmpl.format(**fa)
|
|
||||||
# except Exception, err:
|
|
||||||
# error_dialog(self, _('Invalid template'),
|
|
||||||
# '<p>'+_('The template %s is invalid:')%tmpl + \
|
|
||||||
# '<br>'+str(err), show=True)
|
|
||||||
# return False
|
|
||||||
# return True
|
|
||||||
|
|
||||||
def set_value(self, val):
|
def set_value(self, val):
|
||||||
self.opt_template.set_value(val)
|
self.opt_template.set_value(val)
|
||||||
|
@ -103,7 +103,7 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="3" column="0" colspan="3">
|
<item row="4" column="0" colspan="3">
|
||||||
<widget class="SaveTemplate" name="send_template" native="true"/>
|
<widget class="SaveTemplate" name="send_template" native="true"/>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user