home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1233 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  4.1 KB  |  101 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__ = '2008, Kovid Goyal kovid@kovidgoyal.net'
  7. __docformat__ = 'restructuredtext en'
  8. from PyQt4.QtGui import QDialog
  9. from calibre.gui2.dialogs.comicconf_ui import Ui_Dialog
  10. from calibre.ebooks.lrf.comic.convert_from import config, PROFILES
  11.  
  12. def set_conversion_defaults(window):
  13.     d = ComicConf(window)
  14.     d.exec_()
  15.  
  16.  
  17. def get_bulk_conversion_options(window):
  18.     d = ComicConf(window, config_defaults = config(None).as_string())
  19.     if d.exec_() == QDialog.Accepted:
  20.         return d.config.parse()
  21.  
  22.  
  23. def get_conversion_options(window, defaults, title, author):
  24.     if defaults is None:
  25.         defaults = config(None).as_string()
  26.     
  27.     defaults += '\ntitle=%s\nauthor=%s' % (repr(title), repr(author))
  28.     d = ComicConf(window, config_defaults = defaults, generic = False)
  29.     if d.exec_() == QDialog.Accepted:
  30.         return (d.config.parse(), d.config.src)
  31.     return (None, None)
  32.  
  33.  
  34. class ComicConf(QDialog, Ui_Dialog):
  35.     
  36.     def __init__(self, window, config_defaults = None, generic = True, title = _('Set defaults for conversion of comics (CBR/CBZ files)')):
  37.         QDialog.__init__(self, window)
  38.         Ui_Dialog.__init__(self)
  39.         self.setupUi(self)
  40.         self.setWindowTitle(title)
  41.         self.config = config(config_defaults)
  42.         opts = self.config.parse()
  43.         if generic:
  44.             for i in ('title', 'author'):
  45.                 getattr(self, 'opt_' + i).setVisible(False)
  46.                 getattr(self, i + '_label').setVisible(False)
  47.             
  48.         else:
  49.             title = opts.title
  50.             if not title:
  51.                 title = _('Unknown')
  52.             
  53.             self.setWindowTitle(_('Set options for converting %s') % title)
  54.             author = opts.author
  55.             self.opt_title.setText(title)
  56.             self.opt_author.setText(author)
  57.         self.opt_colors.setValue(opts.colors)
  58.         self.opt_profile.addItem(opts.profile)
  59.         for x in PROFILES.keys():
  60.             if x != opts.profile:
  61.                 self.opt_profile.addItem(x)
  62.                 continue
  63.         
  64.         self.opt_dont_normalize.setChecked(opts.dont_normalize)
  65.         self.opt_keep_aspect_ratio.setChecked(opts.keep_aspect_ratio)
  66.         self.opt_dont_sharpen.setChecked(opts.dont_sharpen)
  67.         self.opt_landscape.setChecked(opts.landscape)
  68.         self.opt_no_sort.setChecked(opts.no_sort)
  69.         self.opt_despeckle.setChecked(opts.despeckle)
  70.         self.opt_wide.setChecked(opts.wide)
  71.         self.opt_right2left.setChecked(opts.right2left)
  72.         for opt in self.config.option_set.preferences:
  73.             g = getattr(self, 'opt_' + opt.name, False)
  74.             if opt.help and g:
  75.                 g.setToolTip(opt.help)
  76.                 continue
  77.         
  78.  
  79.     
  80.     def accept(self):
  81.         for opt in self.config.option_set.preferences:
  82.             g = getattr(self, 'opt_' + opt.name, False)
  83.             if not g or not g.isVisible():
  84.                 continue
  85.             
  86.             if hasattr(g, 'isChecked'):
  87.                 val = bool(g.isChecked())
  88.             elif hasattr(g, 'value'):
  89.                 val = g.value()
  90.             elif hasattr(g, 'itemText'):
  91.                 val = unicode(g.itemText(g.currentIndex()))
  92.             elif hasattr(g, 'text'):
  93.                 val = unicode(g.text())
  94.             else:
  95.                 raise Exception('Bad coding')
  96.             hasattr(g, 'isChecked').config.set(opt.name, val)
  97.         
  98.         return QDialog.accept(self)
  99.  
  100.  
  101.