home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1227 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  6.1 KB  |  171 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__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
  7. __docformat__ = 'restructuredtext en'
  8. import os
  9. import sys
  10. from PyQt4 import QtGui
  11. from PyQt4.Qt import QDialog, SIGNAL
  12. from calibre.customize.ui import config
  13. from calibre.gui2.dialogs.catalog_ui import Ui_Dialog
  14. from calibre.gui2 import dynamic
  15. from calibre.customize.ui import catalog_plugins
  16.  
  17. class Catalog(QDialog, Ui_Dialog):
  18.     
  19.     def __init__(self, parent, dbspec, ids):
  20.         import re
  21.         import cStringIO
  22.         info = prints
  23.         import calibre
  24.         compileUi = compileUi
  25.         import PyQt4.uic
  26.         QDialog.__init__(self, parent)
  27.         self.setupUi(self)
  28.         self.dbspec = dbspec
  29.         self.ids = ids
  30.         self.count.setText(unicode(self.count.text()).format(len(ids)))
  31.         self.title.setText(dynamic.get('catalog_last_used_title', _('My Books')))
  32.         self.fmts = []
  33.         self.widgets = []
  34.         builtin_plugins = plugins
  35.         import calibre.customize.builtins
  36.         for plugin in catalog_plugins():
  37.             if plugin.name in config['disabled_plugins']:
  38.                 continue
  39.             
  40.             name = plugin.name.lower().replace(' ', '_')
  41.             if type(plugin) in builtin_plugins:
  42.                 
  43.                 try:
  44.                     catalog_widget = __import__('calibre.gui2.catalog.' + name, fromlist = [
  45.                         1])
  46.                     pw = catalog_widget.PluginWidget()
  47.                     pw.initialize(name)
  48.                     pw.ICON = I('forward.svg')
  49.                     self.widgets.append(pw)
  50.                     [ self.fmts.append([
  51.                         file_type.upper(),
  52.                         pw.sync_enabled,
  53.                         pw]) for file_type in plugin.file_types ]
  54.                 except ImportError:
  55.                     info('ImportError initializing %s' % name)
  56.                     continue
  57.                 except:
  58.                     None<EXCEPTION MATCH>ImportError
  59.                 
  60.  
  61.             None<EXCEPTION MATCH>ImportError
  62.             form = os.path.join(plugin.resources_path, '%s.ui' % name)
  63.             klass = os.path.join(plugin.resources_path, '%s.py' % name)
  64.             compiled_form = os.path.join(plugin.resources_path, '%s_ui.py' % name)
  65.             if os.path.exists(form) and os.path.exists(klass):
  66.                 if not os.path.exists(compiled_form):
  67.                     buf = cStringIO.StringIO()
  68.                     compileUi(form, buf)
  69.                     dat = buf.getvalue()
  70.                     dat = re.compile('QtGui.QApplication.translate\\(.+?,\\s+"(.+?)(?<!\\\\)",.+?\\)', re.DOTALL).sub('_("\\1")', dat)
  71.                     open(compiled_form, 'wb').write(dat)
  72.                 
  73.                 
  74.                 try:
  75.                     sys.path.insert(0, plugin.resources_path)
  76.                     catalog_widget = __import__(name, fromlist = [
  77.                         1])
  78.                     pw = catalog_widget.PluginWidget()
  79.                     pw.initialize(name)
  80.                     pw.ICON = I('forward.svg')
  81.                     self.widgets.append(pw)
  82.                     [ self.fmts.append([
  83.                         file_type.upper(),
  84.                         pw.sync_enabled,
  85.                         pw]) for file_type in plugin.file_types ]
  86.                 except ImportError:
  87.                     info('ImportError with %s' % name)
  88.                     continue
  89.                 finally:
  90.                     sys.path.remove(plugin.resources_path)
  91.  
  92.                 continue
  93.             info('No dynamic tab resources found for %s' % name)
  94.         
  95.         self.widgets = sorted(self.widgets, cmp = (lambda x, y: cmp(x.TITLE, y.TITLE)))
  96.         fmts = []([ x[0] for x in self.fmts ])
  97.         self.sync_enabled_formats = []
  98.         for fmt in self.fmts:
  99.             if fmt[1]:
  100.                 self.sync_enabled_formats.append(fmt[0])
  101.                 continue
  102.             []
  103.         
  104.         self.format.currentIndexChanged.connect(self.format_changed)
  105.         self.format.addItems(fmts)
  106.         pref = dynamic.get('catalog_preferred_format', 'CSV')
  107.         idx = self.format.findText(pref)
  108.         if idx > -1:
  109.             self.format.setCurrentIndex(idx)
  110.         
  111.         if self.sync.isEnabled():
  112.             self.sync.setChecked(dynamic.get('catalog_sync_to_device', True))
  113.         
  114.         self.format.currentIndexChanged.connect(self.show_plugin_tab)
  115.         self.connect(self.buttonBox.button(QtGui.QDialogButtonBox.Apply), SIGNAL('clicked()'), self.apply)
  116.         self.show_plugin_tab(None)
  117.  
  118.     
  119.     def show_plugin_tab(self, idx):
  120.         cf = unicode(self.format.currentText()).lower()
  121.         while self.tabs.count() > 1:
  122.             self.tabs.removeTab(1)
  123.         for pw in self.widgets:
  124.             if cf in pw.formats:
  125.                 self.tabs.addTab(pw, pw.TITLE)
  126.                 break
  127.                 continue
  128.         
  129.  
  130.     
  131.     def format_changed(self, idx):
  132.         cf = unicode(self.format.currentText())
  133.         if cf in self.sync_enabled_formats:
  134.             self.sync.setEnabled(True)
  135.         else:
  136.             self.sync.setDisabled(True)
  137.             self.sync.setChecked(False)
  138.  
  139.     
  140.     def fmt_options(self):
  141.         ans = { }
  142.         if self.tabs.count() > 1:
  143.             w = self.tabs.widget(1)
  144.             ans = w.options()
  145.         
  146.         return ans
  147.  
  148.     fmt_options = property(fmt_options)
  149.     
  150.     def save_catalog_settings(self):
  151.         self.catalog_format = unicode(self.format.currentText())
  152.         dynamic.set('catalog_preferred_format', self.catalog_format)
  153.         self.catalog_title = unicode(self.title.text())
  154.         dynamic.set('catalog_last_used_title', self.catalog_title)
  155.         self.catalog_sync = bool(self.sync.isChecked())
  156.         dynamic.set('catalog_sync_to_device', self.catalog_sync)
  157.  
  158.     
  159.     def apply(self):
  160.         self.save_catalog_settings()
  161.         if self.tabs.count() > 1:
  162.             self.tabs.widget(1).options()
  163.         
  164.  
  165.     
  166.     def accept(self):
  167.         self.save_catalog_settings()
  168.         return QDialog.accept(self)
  169.  
  170.  
  171.