mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
cleanups
This commit is contained in:
parent
03c5a395f3
commit
8f97e09d0b
@ -16,11 +16,11 @@ class PluginWidget(QWidget,Ui_Form):
|
|||||||
HELP = _('Options specific to')+' <formats> '+_('output')
|
HELP = _('Options specific to')+' <formats> '+_('output')
|
||||||
# Indicates whether this plugin wants its output synced to the connected device
|
# Indicates whether this plugin wants its output synced to the connected device
|
||||||
sync_enabled = False
|
sync_enabled = False
|
||||||
|
|
||||||
def initialize(self):
|
def initialize(self):
|
||||||
QWidget.__init__(self)
|
QWidget.__init__(self)
|
||||||
self.setupUi(self)
|
self.setupUi(self)
|
||||||
|
|
||||||
def options(self):
|
def options(self):
|
||||||
# Return a dictionary with options for this Widget
|
# Return a dictionary with options for this Widget
|
||||||
return {}
|
return {}
|
||||||
|
@ -4,14 +4,12 @@ __license__ = 'GPL 3'
|
|||||||
__copyright__ = '2009, John Schember <john@nachtimwald.com>'
|
__copyright__ = '2009, John Schember <john@nachtimwald.com>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import os
|
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
|
||||||
from calibre.customize.conversion import OptionRecommendation, DummyReporter
|
from calibre.customize.conversion import OptionRecommendation, DummyReporter
|
||||||
from calibre.ebooks.conversion.plumber import Plumber
|
from calibre.ebooks.conversion.plumber import Plumber
|
||||||
from calibre.customize.ui import plugin_for_catalog_format
|
from calibre.customize.ui import plugin_for_catalog_format
|
||||||
from calibre.utils.logging import Log
|
from calibre.utils.logging import Log
|
||||||
from calibre.gui2 import choose_dir, Application
|
|
||||||
|
|
||||||
def gui_convert(input, output, recommendations, notification=DummyReporter(),
|
def gui_convert(input, output, recommendations, notification=DummyReporter(),
|
||||||
abort_after_input_dump=False, log=None):
|
abort_after_input_dump=False, log=None):
|
||||||
@ -36,7 +34,7 @@ def gui_catalog(fmt, title, dbspec, ids, out_file_name, fmt_options,
|
|||||||
db = LibraryDatabase2(dbpath)
|
db = LibraryDatabase2(dbpath)
|
||||||
else: # To be implemented in the future
|
else: # To be implemented in the future
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Create a minimal OptionParser that we can append to
|
# Create a minimal OptionParser that we can append to
|
||||||
parser = OptionParser()
|
parser = OptionParser()
|
||||||
args = []
|
args = []
|
||||||
@ -56,8 +54,8 @@ def gui_catalog(fmt, title, dbspec, ids, out_file_name, fmt_options,
|
|||||||
plugin = plugin_for_catalog_format(fmt)
|
plugin = plugin_for_catalog_format(fmt)
|
||||||
plugin.run(out_file_name, opts, db)
|
plugin.run(out_file_name, opts, db)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,15 +6,14 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import os, shutil, sys, tempfile
|
import os, sys
|
||||||
|
|
||||||
from PyQt4.Qt import QDialog, QWidget
|
from PyQt4.Qt import QDialog
|
||||||
|
|
||||||
from calibre.customize.ui import config
|
from calibre.customize.ui import config
|
||||||
from calibre.gui2.dialogs.catalog_ui import Ui_Dialog
|
from calibre.gui2.dialogs.catalog_ui import Ui_Dialog
|
||||||
from calibre.gui2 import gprefs, dynamic
|
from calibre.gui2 import dynamic
|
||||||
from calibre.customize.ui import available_catalog_formats, catalog_plugins
|
from calibre.customize.ui import catalog_plugins
|
||||||
from calibre.gui2.catalog.catalog_csv_xml import PluginWidget
|
|
||||||
|
|
||||||
class Catalog(QDialog, Ui_Dialog):
|
class Catalog(QDialog, Ui_Dialog):
|
||||||
''' Catalog Dialog builder'''
|
''' Catalog Dialog builder'''
|
||||||
@ -23,11 +22,10 @@ class Catalog(QDialog, Ui_Dialog):
|
|||||||
def __init__(self, parent, dbspec, ids):
|
def __init__(self, parent, dbspec, ids):
|
||||||
import re, cStringIO
|
import re, cStringIO
|
||||||
from calibre import prints as info
|
from calibre import prints as info
|
||||||
from calibre.gui2 import dynamic
|
|
||||||
from PyQt4.uic import compileUi
|
from PyQt4.uic import compileUi
|
||||||
|
|
||||||
QDialog.__init__(self, parent)
|
QDialog.__init__(self, parent)
|
||||||
|
|
||||||
# Run the dialog setup generated from catalog.ui
|
# Run the dialog setup generated from catalog.ui
|
||||||
self.setupUi(self)
|
self.setupUi(self)
|
||||||
self.dbspec, self.ids = dbspec, ids
|
self.dbspec, self.ids = dbspec, ids
|
||||||
@ -43,25 +41,24 @@ class Catalog(QDialog, Ui_Dialog):
|
|||||||
# This code models #69 in calibre/gui2/dialogs/config/__init__.py
|
# This code models #69 in calibre/gui2/dialogs/config/__init__.py
|
||||||
|
|
||||||
self.fmts = []
|
self.fmts = []
|
||||||
|
|
||||||
from calibre.customize.builtins import plugins as builtin_plugins
|
from calibre.customize.builtins import plugins as builtin_plugins
|
||||||
from calibre.customize import CatalogPlugin
|
|
||||||
|
|
||||||
for plugin in catalog_plugins():
|
for plugin in catalog_plugins():
|
||||||
if plugin.name in config['disabled_plugins']:
|
if plugin.name in config['disabled_plugins']:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
name = plugin.name.lower().replace(' ', '_')
|
name = plugin.name.lower().replace(' ', '_')
|
||||||
if type(plugin) in builtin_plugins:
|
if type(plugin) in builtin_plugins:
|
||||||
#info("Adding widget for builtin Catalog plugin %s" % plugin.name)
|
#info("Adding widget for builtin Catalog plugin %s" % plugin.name)
|
||||||
try:
|
try:
|
||||||
catalog_widget = __import__('calibre.gui2.catalog.'+name,
|
catalog_widget = __import__('calibre.gui2.catalog.'+name,
|
||||||
fromlist=[1])
|
fromlist=[1])
|
||||||
pw = catalog_widget.PluginWidget()
|
pw = catalog_widget.PluginWidget()
|
||||||
pw.initialize(name)
|
pw.initialize(name)
|
||||||
pw.ICON = I('forward.svg')
|
pw.ICON = I('forward.svg')
|
||||||
self.widgets.append(pw)
|
self.widgets.append(pw)
|
||||||
[self.fmts.append([file_type.upper(), pw.sync_enabled,pw]) for file_type in plugin.file_types]
|
[self.fmts.append([file_type.upper(), pw.sync_enabled,pw]) for file_type in plugin.file_types]
|
||||||
except ImportError:
|
except ImportError:
|
||||||
info("ImportError with %s" % name)
|
info("ImportError with %s" % name)
|
||||||
continue
|
continue
|
||||||
@ -73,38 +70,38 @@ class Catalog(QDialog, Ui_Dialog):
|
|||||||
|
|
||||||
if os.path.exists(form) and os.path.exists(klass):
|
if os.path.exists(form) and os.path.exists(klass):
|
||||||
#info("Adding widget for user-installed Catalog plugin %s" % plugin.name)
|
#info("Adding widget for user-installed Catalog plugin %s" % plugin.name)
|
||||||
|
|
||||||
# Compile the .ui form provided in plugin.zip
|
# Compile the .ui form provided in plugin.zip
|
||||||
if not os.path.exists(compiled_form):
|
if not os.path.exists(compiled_form):
|
||||||
# info('\tCompiling form', form)
|
# info('\tCompiling form', form)
|
||||||
buf = cStringIO.StringIO()
|
buf = cStringIO.StringIO()
|
||||||
compileUi(form, buf)
|
compileUi(form, buf)
|
||||||
dat = buf.getvalue()
|
dat = buf.getvalue()
|
||||||
dat = re.compile(r'QtGui.QApplication.translate\(.+?,\s+"(.+?)(?<!\\)",.+?\)',
|
dat = re.compile(r'QtGui.QApplication.translate\(.+?,\s+"(.+?)(?<!\\)",.+?\)',
|
||||||
re.DOTALL).sub(r'_("\1")', dat)
|
re.DOTALL).sub(r'_("\1")', dat)
|
||||||
open(compiled_form, 'wb').write(dat)
|
open(compiled_form, 'wb').write(dat)
|
||||||
|
|
||||||
# Import the dynamic PluginWidget() from .py file provided in plugin.zip
|
# Import the dynamic PluginWidget() from .py file provided in plugin.zip
|
||||||
try:
|
try:
|
||||||
sys.path.insert(0, plugin.resources_path)
|
sys.path.insert(0, plugin.resources_path)
|
||||||
catalog_widget = __import__(name, fromlist=[1])
|
catalog_widget = __import__(name, fromlist=[1])
|
||||||
pw = catalog_widget.PluginWidget()
|
pw = catalog_widget.PluginWidget()
|
||||||
pw.initialize(name)
|
pw.initialize(name)
|
||||||
pw.ICON = I('forward.svg')
|
pw.ICON = I('forward.svg')
|
||||||
self.widgets.append(pw)
|
self.widgets.append(pw)
|
||||||
[self.fmts.append([file_type.upper(), pw.sync_enabled,pw]) for file_type in plugin.file_types]
|
[self.fmts.append([file_type.upper(), pw.sync_enabled,pw]) for file_type in plugin.file_types]
|
||||||
except ImportError:
|
except ImportError:
|
||||||
info("ImportError with %s" % name)
|
info("ImportError with %s" % name)
|
||||||
continue
|
continue
|
||||||
finally:
|
finally:
|
||||||
sys.path.remove(plugin.resources_path)
|
sys.path.remove(plugin.resources_path)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
info("No dynamic tab resources found for %s" % name)
|
info("No dynamic tab resources found for %s" % name)
|
||||||
|
|
||||||
self.widgets = sorted(self.widgets, key=lambda x:(x.TITLE, x.TITLE))
|
self.widgets = sorted(self.widgets, key=lambda x:(x.TITLE, x.TITLE))
|
||||||
for pw in self.widgets:
|
for pw in self.widgets:
|
||||||
page = self.tabs.addTab(pw,pw.TITLE)
|
self.tabs.addTab(pw,pw.TITLE)
|
||||||
|
|
||||||
# Generate a sorted list of installed catalog formats/sync_enabled pairs
|
# Generate a sorted list of installed catalog formats/sync_enabled pairs
|
||||||
fmts = sorted([x[0] for x in self.fmts])
|
fmts = sorted([x[0] for x in self.fmts])
|
||||||
@ -127,7 +124,7 @@ class Catalog(QDialog, Ui_Dialog):
|
|||||||
|
|
||||||
if self.sync.isEnabled():
|
if self.sync.isEnabled():
|
||||||
self.sync.setChecked(dynamic.get('catalog_sync_to_device', True))
|
self.sync.setChecked(dynamic.get('catalog_sync_to_device', True))
|
||||||
|
|
||||||
def format_changed(self, idx):
|
def format_changed(self, idx):
|
||||||
cf = unicode(self.format.currentText())
|
cf = unicode(self.format.currentText())
|
||||||
if cf in self.sync_enabled_formats:
|
if cf in self.sync_enabled_formats:
|
||||||
|
@ -9,7 +9,7 @@ __docformat__ = 'restructuredtext en'
|
|||||||
|
|
||||||
'''The main GUI'''
|
'''The main GUI'''
|
||||||
|
|
||||||
import atexit, os, shutil, sys, tempfile, textwrap, collections, time
|
import os, shutil, sys, textwrap, collections, time
|
||||||
from xml.parsers.expat import ExpatError
|
from xml.parsers.expat import ExpatError
|
||||||
from Queue import Queue, Empty
|
from Queue import Queue, Empty
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
@ -1359,7 +1359,7 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
|
|||||||
|
|
||||||
############################### Generate catalog ###########################
|
############################### Generate catalog ###########################
|
||||||
|
|
||||||
def generate_catalog(self):
|
def generate_catalog(self):
|
||||||
rows = self.library_view.selectionModel().selectedRows()
|
rows = self.library_view.selectionModel().selectedRows()
|
||||||
if not rows or len(rows) < 2:
|
if not rows or len(rows) < 2:
|
||||||
rows = xrange(self.library_view.model().rowCount(QModelIndex()))
|
rows = xrange(self.library_view.model().rowCount(QModelIndex()))
|
||||||
@ -1375,7 +1375,7 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
|
|||||||
ret = generate_catalog(self, dbspec, ids)
|
ret = generate_catalog(self, dbspec, ids)
|
||||||
if ret is None:
|
if ret is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
func, args, desc, out, sync, title = ret
|
func, args, desc, out, sync, title = ret
|
||||||
|
|
||||||
fmt = os.path.splitext(out)[1][1:].upper()
|
fmt = os.path.splitext(out)[1][1:].upper()
|
||||||
@ -1384,7 +1384,7 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
|
|||||||
description=desc)
|
description=desc)
|
||||||
job.catalog_file_path = out
|
job.catalog_file_path = out
|
||||||
job.fmt = fmt
|
job.fmt = fmt
|
||||||
job.catalog_sync, job.catalog_title = sync, title
|
job.catalog_sync, job.catalog_title = sync, title
|
||||||
self.status_bar.showMessage(_('Generating %s catalog...')%fmt)
|
self.status_bar.showMessage(_('Generating %s catalog...')%fmt)
|
||||||
|
|
||||||
def catalog_generated(self, job):
|
def catalog_generated(self, job):
|
||||||
@ -1399,12 +1399,12 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
|
|||||||
self.status_bar.showMessage(_('Catalog generated.'), 3000)
|
self.status_bar.showMessage(_('Catalog generated.'), 3000)
|
||||||
self.sync_catalogs()
|
self.sync_catalogs()
|
||||||
if job.fmt in ['CSV','XML']:
|
if job.fmt in ['CSV','XML']:
|
||||||
export_dir = choose_dir(self, 'Export Catalog Directory',
|
export_dir = choose_dir(self, 'Export Catalog Directory',
|
||||||
'Select destination for %s.%s' % (job.catalog_title, job.fmt.lower()))
|
'Select destination for %s.%s' % (job.catalog_title, job.fmt.lower()))
|
||||||
if export_dir:
|
if export_dir:
|
||||||
destination = os.path.join(export_dir, '%s.%s' % (job.catalog_title, job.fmt.lower()))
|
destination = os.path.join(export_dir, '%s.%s' % (job.catalog_title, job.fmt.lower()))
|
||||||
shutil.copyfile(job.catalog_file_path, destination)
|
shutil.copyfile(job.catalog_file_path, destination)
|
||||||
|
|
||||||
############################### Fetch news #################################
|
############################### Fetch news #################################
|
||||||
|
|
||||||
def download_scheduled_recipe(self, arg):
|
def download_scheduled_recipe(self, arg):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user