home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1246 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  2.5 KB  |  56 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
  9. from calibre.gui2 import error_dialog
  10. from calibre.gui2.dialogs.config.save_template_ui import Ui_Form
  11. from calibre.library.save_to_disk import FORMAT_ARG_DESCS, preprocess_template
  12.  
  13. class SaveTemplate(QWidget, Ui_Form):
  14.     
  15.     def __init__(self, *args):
  16.         QWidget.__init__(self, *args)
  17.         Ui_Form.__init__(self)
  18.         self.setupUi(self)
  19.  
  20.     
  21.     def initialize(self, name, default, help):
  22.         variables = sorted(FORMAT_ARG_DESCS.keys())
  23.         rows = []
  24.         for var in variables:
  25.             rows.append(u'<tr><td>%s</td><td>%s</td></tr>' % (var, FORMAT_ARG_DESCS[var]))
  26.         
  27.         table = u'<table>%s</table>' % u'\n'.join(rows)
  28.         self.template_variables.setText(table)
  29.         self.opt_template.initialize(name + '_template_history', default, help)
  30.         self.option_name = name
  31.  
  32.     
  33.     def validate(self):
  34.         tmpl = preprocess_template(self.opt_template.text())
  35.         fa = { }
  36.         for x in FORMAT_ARG_DESCS.keys():
  37.             fa[x] = 'random long string'
  38.         
  39.         
  40.         try:
  41.             tmpl.format(**fa)
  42.         except Exception:
  43.             err = None
  44.             error_dialog(self, _('Invalid template'), '<p>' + _('The template %s is invalid:') % tmpl + '<br>' + str(err), show = True)
  45.             return False
  46.  
  47.         return True
  48.  
  49.     
  50.     def save_settings(self, config, name):
  51.         val = unicode(self.opt_template.text())
  52.         config.set(name, val)
  53.         self.opt_template.save_history(self.option_name + '_template_history')
  54.  
  55.  
  56.