more cleanups

This commit is contained in:
Kovid Goyal 2010-01-21 17:25:59 -07:00
parent 8f97e09d0b
commit 44f6c0a1f5
3 changed files with 17 additions and 43 deletions

View File

@ -2,7 +2,7 @@ from __future__ import with_statement
__license__ = 'GPL v3'
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
import atexit, os, shutil, sys, tempfile, zipfile
import os, sys, zipfile
from calibre.constants import numeric_version
from calibre.ptempfile import PersistentTemporaryFile
@ -226,7 +226,7 @@ class MetadataWriterPlugin(Plugin):
'''
pass
class CatalogPlugin(Plugin):
'''
A plugin that implements a catalog generator.
@ -251,7 +251,7 @@ class CatalogPlugin(Plugin):
#: '%default' + "'"))]
cli_options = []
def search_sort_db(self, db, opts):
@ -262,7 +262,7 @@ class CatalogPlugin(Plugin):
if opts.sort_by:
# 2nd arg = ascending
db.sort(opts.sort_by, True)
return db.get_data_as_dict(ids=opts.ids)
def get_output_fields(self, opts):
@ -289,29 +289,29 @@ class CatalogPlugin(Plugin):
'''
If plugin is not a built-in, copy the plugin's .ui and .py files from
the zip file to $TMPDIR.
Tab will be dynamically generated and added to the Catalog Options dialog in
Tab will be dynamically generated and added to the Catalog Options dialog in
calibre.gui2.dialogs.catalog.py:Catalog
'''
from calibre.customize.builtins import plugins as builtin_plugins
from calibre.customize.ui import config
from calibre.ptempfile import PersistentTemporaryDirectory
if not type(self) in builtin_plugins and \
not self.name in config['disabled_plugins']:
files_to_copy = ["%s.%s" % (self.name.lower(),ext) for ext in ["ui","py"]]
resources = zipfile.ZipFile(self.plugin_path,'r')
if self.resources_path is None:
self.resources_path = PersistentTemporaryDirectory('_plugin_resources', prefix='')
for file in files_to_copy:
try:
resources.extract(file, self.resources_path)
except:
print " customize:__init__.initialize(): %s not found in %s" % (file, os.path.basename(self.plugin_path))
continue
resources.close()
resources.close()
def run(self, path_to_output, opts, db, ids):
'''
Run the plugin. Must be implemented in subclasses.

View File

@ -9,20 +9,20 @@ __docformat__ = 'restructuredtext en'
from calibre.gui2 import gprefs
from calibre.gui2.catalog.catalog_csv_xml_ui import Ui_Form
from PyQt4.Qt import QDialog, QWidget, SIGNAL
from PyQt4.Qt import QWidget
class PluginWidget(QWidget,Ui_Form):
TITLE = _('CSV/XML Output')
HELP = _('Options specific to')+' CSV/XML '+_('output')
sync_enabled = False
def initialize(self, name):
QWidget.__init__(self)
self.setupUi(self)
self.name = name
# Restore the activated fields from last use
for x in range(self.db_fields.count()):
for x in range(self.db_fields.count()):
pref = '%s_db_fields_%s' % (self.name, self.db_fields.item(x).text())
activated = gprefs[pref] if pref in gprefs else False
self.db_fields.item(x).setSelected(activated)
@ -31,10 +31,10 @@ class PluginWidget(QWidget,Ui_Form):
# Save the currently activated fields
for x in range(self.db_fields.count()):
pref = '%s_db_fields_%s' % (self.name, self.db_fields.item(x).text())
gprefs[pref] = self.db_fields.item(x).isSelected()
# Return a dictionary with current options for this widget
gprefs[pref] = self.db_fields.item(x).isSelected()
# Return a dictionary with current options for this widget
if len(self.db_fields.selectedItems()):
return {'fields':[str(item.text()) for item in self.db_fields.selectedItems()]}
else:
return {'fields':['all']}
return {'fields':['all']}

View File

@ -1,26 +0,0 @@
#!/usr/bin/env python
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
from __future__ import with_statement
__license__ = 'GPL v3'
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en'
from <basename> import Ui_Form
from PyQt4.Qt import QDialog, QWidget
class PluginWidget(QWidget,Ui_Form):
TITLE = _('<formats> Output')
HELP = _('Options specific to')+' <formats> '+_('output')
# Indicates whether this plugin wants its output synced to the connected device
sync_enabled = False
def initialize(self):
QWidget.__init__(self)
self.setupUi(self)
def options(self):
# Return a dictionary with options for this Widget
return {}