home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- from __future__ import with_statement
- __license__ = 'GPL v3'
- __copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
- __docformat__ = 'restructuredtext en'
- import os
- import sys
- from PyQt4 import QtGui
- from PyQt4.Qt import QDialog, SIGNAL
- from calibre.customize.ui import config
- from calibre.gui2.dialogs.catalog_ui import Ui_Dialog
- from calibre.gui2 import dynamic
- from calibre.customize.ui import catalog_plugins
-
- class Catalog(QDialog, Ui_Dialog):
-
- def __init__(self, parent, dbspec, ids):
- import re
- import cStringIO
- info = prints
- import calibre
- compileUi = compileUi
- import PyQt4.uic
- QDialog.__init__(self, parent)
- self.setupUi(self)
- self.dbspec = dbspec
- self.ids = ids
- self.count.setText(unicode(self.count.text()).format(len(ids)))
- self.title.setText(dynamic.get('catalog_last_used_title', _('My Books')))
- self.fmts = []
- self.widgets = []
- builtin_plugins = plugins
- import calibre.customize.builtins
- for plugin in catalog_plugins():
- if plugin.name in config['disabled_plugins']:
- continue
-
- name = plugin.name.lower().replace(' ', '_')
- if type(plugin) in builtin_plugins:
-
- try:
- catalog_widget = __import__('calibre.gui2.catalog.' + name, fromlist = [
- 1])
- pw = catalog_widget.PluginWidget()
- pw.initialize(name)
- pw.ICON = I('forward.svg')
- self.widgets.append(pw)
- [ self.fmts.append([
- file_type.upper(),
- pw.sync_enabled,
- pw]) for file_type in plugin.file_types ]
- except ImportError:
- info('ImportError initializing %s' % name)
- continue
- except:
- None<EXCEPTION MATCH>ImportError
-
-
- None<EXCEPTION MATCH>ImportError
- form = os.path.join(plugin.resources_path, '%s.ui' % name)
- klass = os.path.join(plugin.resources_path, '%s.py' % name)
- compiled_form = os.path.join(plugin.resources_path, '%s_ui.py' % name)
- if os.path.exists(form) and os.path.exists(klass):
- if not os.path.exists(compiled_form):
- buf = cStringIO.StringIO()
- compileUi(form, buf)
- dat = buf.getvalue()
- dat = re.compile('QtGui.QApplication.translate\\(.+?,\\s+"(.+?)(?<!\\\\)",.+?\\)', re.DOTALL).sub('_("\\1")', dat)
- open(compiled_form, 'wb').write(dat)
-
-
- try:
- sys.path.insert(0, plugin.resources_path)
- catalog_widget = __import__(name, fromlist = [
- 1])
- pw = catalog_widget.PluginWidget()
- pw.initialize(name)
- pw.ICON = I('forward.svg')
- self.widgets.append(pw)
- [ self.fmts.append([
- file_type.upper(),
- pw.sync_enabled,
- pw]) for file_type in plugin.file_types ]
- except ImportError:
- info('ImportError with %s' % name)
- continue
- finally:
- sys.path.remove(plugin.resources_path)
-
- continue
- info('No dynamic tab resources found for %s' % name)
-
- self.widgets = sorted(self.widgets, cmp = (lambda x, y: cmp(x.TITLE, y.TITLE)))
- fmts = []([ x[0] for x in self.fmts ])
- self.sync_enabled_formats = []
- for fmt in self.fmts:
- if fmt[1]:
- self.sync_enabled_formats.append(fmt[0])
- continue
- []
-
- self.format.currentIndexChanged.connect(self.format_changed)
- self.format.addItems(fmts)
- pref = dynamic.get('catalog_preferred_format', 'CSV')
- idx = self.format.findText(pref)
- if idx > -1:
- self.format.setCurrentIndex(idx)
-
- if self.sync.isEnabled():
- self.sync.setChecked(dynamic.get('catalog_sync_to_device', True))
-
- self.format.currentIndexChanged.connect(self.show_plugin_tab)
- self.connect(self.buttonBox.button(QtGui.QDialogButtonBox.Apply), SIGNAL('clicked()'), self.apply)
- self.show_plugin_tab(None)
-
-
- def show_plugin_tab(self, idx):
- cf = unicode(self.format.currentText()).lower()
- while self.tabs.count() > 1:
- self.tabs.removeTab(1)
- for pw in self.widgets:
- if cf in pw.formats:
- self.tabs.addTab(pw, pw.TITLE)
- break
- continue
-
-
-
- def format_changed(self, idx):
- cf = unicode(self.format.currentText())
- if cf in self.sync_enabled_formats:
- self.sync.setEnabled(True)
- else:
- self.sync.setDisabled(True)
- self.sync.setChecked(False)
-
-
- def fmt_options(self):
- ans = { }
- if self.tabs.count() > 1:
- w = self.tabs.widget(1)
- ans = w.options()
-
- return ans
-
- fmt_options = property(fmt_options)
-
- def save_catalog_settings(self):
- self.catalog_format = unicode(self.format.currentText())
- dynamic.set('catalog_preferred_format', self.catalog_format)
- self.catalog_title = unicode(self.title.text())
- dynamic.set('catalog_last_used_title', self.catalog_title)
- self.catalog_sync = bool(self.sync.isChecked())
- dynamic.set('catalog_sync_to_device', self.catalog_sync)
-
-
- def apply(self):
- self.save_catalog_settings()
- if self.tabs.count() > 1:
- self.tabs.widget(1).options()
-
-
-
- def accept(self):
- self.save_catalog_settings()
- return QDialog.accept(self)
-
-
-