Fix #1026484 (External plugins can't have PluginWidget)

This commit is contained in:
Kovid Goyal 2012-07-27 17:01:04 +05:30
parent aeddc2f958
commit e2b1d3bc9d
3 changed files with 65 additions and 36 deletions

View File

@ -91,6 +91,37 @@ class DummyReporter(object):
def __call__(self, percent, msg=''): def __call__(self, percent, msg=''):
pass pass
def gui_configuration_widget(name, parent, get_option_by_name,
get_option_help, db, book_id, for_output=True):
import importlib
def widget_factory(cls):
return cls(parent, get_option_by_name,
get_option_help, db, book_id)
if for_output:
try:
output_widget = importlib.import_module(
'calibre.gui2.convert.'+name)
pw = output_widget.PluginWidget
pw.ICON = I('back.png')
pw.HELP = _('Options specific to the output format.')
return widget_factory(pw)
except ImportError:
pass
else:
try:
input_widget = importlib.import_module(
'calibre.gui2.convert.'+name)
pw = input_widget.PluginWidget
pw.ICON = I('forward.png')
pw.HELP = _('Options specific to the input format.')
return widget_factory(pw)
except ImportError:
pass
return None
class InputFormatPlugin(Plugin): class InputFormatPlugin(Plugin):
''' '''
InputFormatPlugins are responsible for converting a document into InputFormatPlugins are responsible for converting a document into
@ -225,6 +256,17 @@ class InputFormatPlugin(Plugin):
''' '''
pass pass
def gui_configuration_widget(self, parent, get_option_by_name,
get_option_help, db, book_id):
'''
Called to create the widget used for configuring this plugin in the
calibre GUI. The widget must be an instance of the PluginWidget class.
See the builting input plugins for examples.
'''
name = self.name.lower().replace(' ', '_')
return gui_configuration_widget(name, parent, get_option_by_name,
get_option_help, db, book_id, for_output=False)
class OutputFormatPlugin(Plugin): class OutputFormatPlugin(Plugin):
''' '''
@ -308,4 +350,16 @@ class OutputFormatPlugin(Plugin):
''' '''
pass pass
def gui_configuration_widget(self, parent, get_option_by_name,
get_option_help, db, book_id):
'''
Called to create the widget used for configuring this plugin in the
calibre GUI. The widget must be an instance of the PluginWidget class.
See the builtin output plugins for examples.
'''
name = self.name.lower().replace(' ', '_')
return gui_configuration_widget(name, parent, get_option_by_name,
get_option_help, db, book_id, for_output=True)

View File

@ -4,7 +4,7 @@ __license__ = 'GPL 3'
__copyright__ = '2009, John Schember <john@nachtimwald.com>' __copyright__ = '2009, John Schember <john@nachtimwald.com>'
__docformat__ = 'restructuredtext en' __docformat__ = 'restructuredtext en'
import shutil, importlib import shutil
from PyQt4.Qt import QString, SIGNAL from PyQt4.Qt import QString, SIGNAL
@ -86,17 +86,9 @@ class BulkConfig(Config):
sd = widget_factory(StructureDetectionWidget) sd = widget_factory(StructureDetectionWidget)
toc = widget_factory(TOCWidget) toc = widget_factory(TOCWidget)
output_widget = None output_widget = self.plumber.output_plugin.gui_configuration_widget(
name = self.plumber.output_plugin.name.lower().replace(' ', '_') self.stack, self.plumber.get_option_by_name,
try: self.plumber.get_option_help, self.db)
output_widget = importlib.import_module(
'calibre.gui2.convert.'+name)
pw = output_widget.PluginWidget
pw.ICON = I('back.png')
pw.HELP = _('Options specific to the output format.')
output_widget = widget_factory(pw)
except ImportError:
pass
while True: while True:
c = self.stack.currentWidget() c = self.stack.currentWidget()

View File

@ -6,7 +6,7 @@ __license__ = 'GPL v3'
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>' __copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en' __docformat__ = 'restructuredtext en'
import cPickle, shutil, importlib import cPickle, shutil
from PyQt4.Qt import QString, SIGNAL, QAbstractListModel, Qt, QVariant, QFont from PyQt4.Qt import QString, SIGNAL, QAbstractListModel, Qt, QVariant, QFont
@ -187,29 +187,12 @@ class Config(ResizableDialog, Ui_Dialog):
toc = widget_factory(TOCWidget) toc = widget_factory(TOCWidget)
debug = widget_factory(DebugWidget) debug = widget_factory(DebugWidget)
output_widget = None output_widget = self.plumber.output_plugin.gui_configuration_widget(
name = self.plumber.output_plugin.name.lower().replace(' ', '_') self.stack, self.plumber.get_option_by_name,
try: self.plumber.get_option_help, self.db, self.book_id)
output_widget = importlib.import_module( input_widget = self.plumber.input_plugin.gui_configuration_widget(
'calibre.gui2.convert.'+name) self.stack, self.plumber.get_option_by_name,
pw = output_widget.PluginWidget self.plumber.get_option_help, self.db, self.book_id)
pw.ICON = I('back.png')
pw.HELP = _('Options specific to the output format.')
output_widget = widget_factory(pw)
except ImportError:
pass
input_widget = None
name = self.plumber.input_plugin.name.lower().replace(' ', '_')
try:
input_widget = importlib.import_module(
'calibre.gui2.convert.'+name)
pw = input_widget.PluginWidget
pw.ICON = I('forward.png')
pw.HELP = _('Options specific to the input format.')
input_widget = widget_factory(pw)
except ImportError:
pass
while True: while True:
c = self.stack.currentWidget() c = self.stack.currentWidget()
if not c: break if not c: break