From 44f6c0a1f5101da9154f4b4a4482453f2d19f9cd Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 21 Jan 2010 17:25:59 -0700 Subject: [PATCH] more cleanups --- src/calibre/customize/__init__.py | 20 +++++++------- src/calibre/gui2/catalog/catalog_csv_xml.py | 14 +++++----- .../gui2/catalog/catalog_tab_template.py | 26 ------------------- 3 files changed, 17 insertions(+), 43 deletions(-) delete mode 100644 src/calibre/gui2/catalog/catalog_tab_template.py diff --git a/src/calibre/customize/__init__.py b/src/calibre/customize/__init__.py index 5ab9ac6d1c..5f35a38e12 100644 --- a/src/calibre/customize/__init__.py +++ b/src/calibre/customize/__init__.py @@ -2,7 +2,7 @@ from __future__ import with_statement __license__ = 'GPL v3' __copyright__ = '2008, Kovid Goyal ' -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. diff --git a/src/calibre/gui2/catalog/catalog_csv_xml.py b/src/calibre/gui2/catalog/catalog_csv_xml.py index f20a97ce2f..b44f2d4c6a 100644 --- a/src/calibre/gui2/catalog/catalog_csv_xml.py +++ b/src/calibre/gui2/catalog/catalog_csv_xml.py @@ -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']} \ No newline at end of file + return {'fields':['all']} diff --git a/src/calibre/gui2/catalog/catalog_tab_template.py b/src/calibre/gui2/catalog/catalog_tab_template.py deleted file mode 100644 index c8429ca078..0000000000 --- a/src/calibre/gui2/catalog/catalog_tab_template.py +++ /dev/null @@ -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 ' -__docformat__ = 'restructuredtext en' - - -from import Ui_Form -from PyQt4.Qt import QDialog, QWidget - -class PluginWidget(QWidget,Ui_Form): - - TITLE = _(' Output') - HELP = _('Options specific to')+' '+_('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 {}