home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 January / maximum-cd-2011-01.iso / DiscContents / calibre-0.7.26.msi / file_1355 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-10-31  |  3.3 KB  |  65 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. from __future__ import with_statement
  5. __license__ = 'GPL v3'
  6. __copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
  7. __docformat__ = 'restructuredtext en'
  8. from PyQt4.Qt import QWidget, pyqtSignal
  9. from calibre.gui2 import error_dialog
  10. from calibre.gui2.preferences.save_template_ui import Ui_Form
  11. from calibre.library.save_to_disk import FORMAT_ARG_DESCS, preprocess_template
  12. from calibre.utils.formatter import validation_formatter
  13.  
  14. class SaveTemplate(QWidget, Ui_Form):
  15.     changed_signal = pyqtSignal()
  16.     
  17.     def __init__(self, *args):
  18.         QWidget.__init__(self, *args)
  19.         Ui_Form.__init__(self)
  20.         self.setupUi(self)
  21.  
  22.     
  23.     def initialize(self, name, default, help):
  24.         variables = sorted(FORMAT_ARG_DESCS.keys())
  25.         rows = []
  26.         for var in variables:
  27.             rows.append(u'<tr><td>%s</td><td> </td><td>%s</td></tr>' % (var, FORMAT_ARG_DESCS[var]))
  28.         
  29.         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 "#")')))
  30.         table = u'<table>%s</table>' % u'\n'.join(rows)
  31.         self.template_variables.setText(table)
  32.         self.opt_template.initialize(name + '_template_history', default, help)
  33.         self.opt_template.editTextChanged.connect(self.changed)
  34.         self.opt_template.currentIndexChanged.connect(self.changed)
  35.         self.option_name = name
  36.  
  37.     
  38.     def changed(self, *args):
  39.         self.changed_signal.emit()
  40.  
  41.     
  42.     def validate(self):
  43.         tmpl = preprocess_template(self.opt_template.text())
  44.         
  45.         try:
  46.             validation_formatter.validate(tmpl)
  47.         except Exception:
  48.             err = None
  49.             error_dialog(self, _('Invalid template'), '<p>' + _('The template %s is invalid:') % tmpl + '<br>' + str(err), show = True)
  50.             return False
  51.  
  52.         return True
  53.  
  54.     
  55.     def set_value(self, val):
  56.         self.opt_template.set_value(val)
  57.  
  58.     
  59.     def save_settings(self, config, name):
  60.         val = unicode(self.opt_template.text())
  61.         config.set(name, val)
  62.         self.opt_template.save_history(self.option_name + '_template_history')
  63.  
  64.  
  65.