mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Merge from trunk
This commit is contained in:
commit
83ab121a65
@ -80,6 +80,100 @@ class Plugin(object): # {{{
|
|||||||
'''
|
'''
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def config_widget(self):
|
||||||
|
'''
|
||||||
|
Implement this method and :meth:`save_settings` in your plugin to
|
||||||
|
use a custom configuration dialog, rather then relying on the simple
|
||||||
|
string based default customization.
|
||||||
|
|
||||||
|
This method, if implemented, must return a QWidget. The widget can have
|
||||||
|
an optional method validate() that takes no arguments and is called
|
||||||
|
immediately after the user clicks OK. Changes are applied if and only
|
||||||
|
if the method returns True.
|
||||||
|
'''
|
||||||
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
def save_settings(self, config_widget):
|
||||||
|
'''
|
||||||
|
Save the settings specified by the user with config_widget.
|
||||||
|
|
||||||
|
:param config_widget: The widget returned by :meth:`config_widget`.
|
||||||
|
|
||||||
|
'''
|
||||||
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
def do_user_config(self, parent=None):
|
||||||
|
'''
|
||||||
|
This method shows a configuration dialog for this plugin. It returns
|
||||||
|
True if the user clicks OK, False otherwise. The changes are
|
||||||
|
automatically applied.
|
||||||
|
'''
|
||||||
|
from PyQt4.Qt import QDialog, QDialogButtonBox, QVBoxLayout, \
|
||||||
|
QLabel, Qt, QLineEdit
|
||||||
|
from calibre.gui2 import gprefs
|
||||||
|
|
||||||
|
prefname = 'plugin config dialog:'+self.type + ':' + self.name
|
||||||
|
geom = gprefs.get(prefname, None)
|
||||||
|
|
||||||
|
config_dialog = QDialog(parent)
|
||||||
|
button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
|
||||||
|
v = QVBoxLayout(config_dialog)
|
||||||
|
|
||||||
|
def size_dialog():
|
||||||
|
if geom is None:
|
||||||
|
config_dialog.resize(config_dialog.sizeHint())
|
||||||
|
else:
|
||||||
|
config_dialog.restoreGeometry(geom)
|
||||||
|
|
||||||
|
button_box.accepted.connect(config_dialog.accept)
|
||||||
|
button_box.rejected.connect(config_dialog.reject)
|
||||||
|
config_dialog.setWindowTitle(_('Customize') + ' ' + self.name)
|
||||||
|
try:
|
||||||
|
config_widget = self.config_widget()
|
||||||
|
except NotImplementedError:
|
||||||
|
config_widget = None
|
||||||
|
|
||||||
|
if config_widget is not None:
|
||||||
|
v.addWidget(config_widget)
|
||||||
|
v.addWidget(button_box)
|
||||||
|
size_dialog()
|
||||||
|
config_dialog.exec_()
|
||||||
|
|
||||||
|
if config_dialog.result() == QDialog.Accepted:
|
||||||
|
if hasattr(config_widget, 'validate'):
|
||||||
|
if config_widget.validate():
|
||||||
|
self.save_settings(config_widget)
|
||||||
|
else:
|
||||||
|
self.save_settings(config_widget)
|
||||||
|
else:
|
||||||
|
from calibre.customize.ui import plugin_customization, \
|
||||||
|
customize_plugin
|
||||||
|
help_text = self.customization_help(gui=True)
|
||||||
|
help_text = QLabel(help_text, config_dialog)
|
||||||
|
help_text.setWordWrap(True)
|
||||||
|
help_text.setTextInteractionFlags(Qt.LinksAccessibleByMouse
|
||||||
|
| Qt.LinksAccessibleByKeyboard)
|
||||||
|
help_text.setOpenExternalLinks(True)
|
||||||
|
v.addWidget(help_text)
|
||||||
|
sc = plugin_customization(self)
|
||||||
|
if not sc:
|
||||||
|
sc = ''
|
||||||
|
sc = sc.strip()
|
||||||
|
sc = QLineEdit(sc, config_dialog)
|
||||||
|
v.addWidget(sc)
|
||||||
|
v.addWidget(button_box)
|
||||||
|
size_dialog()
|
||||||
|
config_dialog.exec_()
|
||||||
|
|
||||||
|
if config_dialog.result() == QDialog.Accepted:
|
||||||
|
sc = unicode(sc.text()).strip()
|
||||||
|
customize_plugin(self, sc)
|
||||||
|
|
||||||
|
geom = bytearray(config_dialog.saveGeometry())
|
||||||
|
gprefs[prefname] = geom
|
||||||
|
|
||||||
|
return config_dialog.result()
|
||||||
|
|
||||||
def load_resources(self, names):
|
def load_resources(self, names):
|
||||||
'''
|
'''
|
||||||
If this plugin comes in a ZIP file (user added plugin), this method
|
If this plugin comes in a ZIP file (user added plugin), this method
|
||||||
|
@ -259,7 +259,7 @@ class EEEREADER(USBMS):
|
|||||||
PRODUCT_ID = [0x178f]
|
PRODUCT_ID = [0x178f]
|
||||||
BCD = [0x0319]
|
BCD = [0x0319]
|
||||||
|
|
||||||
EBOOK_DIR_MAIN = 'Books'
|
EBOOK_DIR_MAIN = EBOOK_DIR_CARD_A = 'Book'
|
||||||
|
|
||||||
VENDOR_NAME = 'LINUX'
|
VENDOR_NAME = 'LINUX'
|
||||||
WINDOWS_MAIN_MEM = WINDOWS_CARD_A_MEM = 'FILE-STOR_GADGET'
|
WINDOWS_MAIN_MEM = WINDOWS_CARD_A_MEM = 'FILE-STOR_GADGET'
|
||||||
|
@ -17,10 +17,10 @@ BASE_URL = 'http://isbndb.com/api/books.xml?access_key=%(key)s&page_number=1&res
|
|||||||
class ISBNDBError(Exception):
|
class ISBNDBError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def fetch_metadata(url, max=100, timeout=5.):
|
def fetch_metadata(url, max=3, timeout=5.):
|
||||||
books = []
|
books = []
|
||||||
page_number = 1
|
page_number = 1
|
||||||
total_results = sys.maxint
|
total_results = 31
|
||||||
br = browser()
|
br = browser()
|
||||||
while len(books) < total_results and max > 0:
|
while len(books) < total_results and max > 0:
|
||||||
try:
|
try:
|
||||||
|
@ -18,7 +18,6 @@ class xISBN(object):
|
|||||||
self._data = []
|
self._data = []
|
||||||
self._map = {}
|
self._map = {}
|
||||||
|
|
||||||
self.br = browser()
|
|
||||||
self.isbn_pat = re.compile(r'[^0-9X]', re.IGNORECASE)
|
self.isbn_pat = re.compile(r'[^0-9X]', re.IGNORECASE)
|
||||||
|
|
||||||
def purify(self, isbn):
|
def purify(self, isbn):
|
||||||
@ -26,7 +25,7 @@ class xISBN(object):
|
|||||||
|
|
||||||
def fetch_data(self, isbn):
|
def fetch_data(self, isbn):
|
||||||
url = self.QUERY%isbn
|
url = self.QUERY%isbn
|
||||||
data = self.br.open_novisit(url).read()
|
data = browser().open_novisit(url).read()
|
||||||
data = json.loads(data)
|
data = json.loads(data)
|
||||||
if data.get('stat', None) != 'ok':
|
if data.get('stat', None) != 'ok':
|
||||||
return []
|
return []
|
||||||
|
@ -103,7 +103,7 @@ class CoverManager(object):
|
|||||||
from calibre.ebooks import calibre_cover
|
from calibre.ebooks import calibre_cover
|
||||||
img_data = calibre_cover(title, authors_to_string(authors),
|
img_data = calibre_cover(title, authors_to_string(authors),
|
||||||
series_string=series_string)
|
series_string=series_string)
|
||||||
id, href = self.oeb.manifest.generate('cover_image',
|
id, href = self.oeb.manifest.generate('cover',
|
||||||
'cover_image.jpg')
|
'cover_image.jpg')
|
||||||
item = self.oeb.manifest.add(id, href, guess_type('t.jpg')[0],
|
item = self.oeb.manifest.add(id, href, guess_type('t.jpg')[0],
|
||||||
data=img_data)
|
data=img_data)
|
||||||
|
@ -8,13 +8,12 @@ __docformat__ = 'restructuredtext en'
|
|||||||
import textwrap, os
|
import textwrap, os
|
||||||
|
|
||||||
from PyQt4.Qt import Qt, QModelIndex, QAbstractItemModel, QVariant, QIcon, \
|
from PyQt4.Qt import Qt, QModelIndex, QAbstractItemModel, QVariant, QIcon, \
|
||||||
QBrush, QDialog, QDialogButtonBox, QVBoxLayout, QLabel, QLineEdit
|
QBrush
|
||||||
|
|
||||||
from calibre.gui2.preferences import ConfigWidgetBase, test_widget
|
from calibre.gui2.preferences import ConfigWidgetBase, test_widget
|
||||||
from calibre.gui2.preferences.plugins_ui import Ui_Form
|
from calibre.gui2.preferences.plugins_ui import Ui_Form
|
||||||
from calibre.customize.ui import initialized_plugins, is_disabled, enable_plugin, \
|
from calibre.customize.ui import initialized_plugins, is_disabled, enable_plugin, \
|
||||||
disable_plugin, customize_plugin, \
|
disable_plugin, plugin_customization, add_plugin, \
|
||||||
plugin_customization, add_plugin, \
|
|
||||||
remove_plugin
|
remove_plugin
|
||||||
from calibre.gui2 import NONE, error_dialog, info_dialog, choose_files
|
from calibre.gui2 import NONE, error_dialog, info_dialog, choose_files
|
||||||
|
|
||||||
@ -189,49 +188,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
|||||||
_('Plugin: %s does not need customization')%plugin.name).exec_()
|
_('Plugin: %s does not need customization')%plugin.name).exec_()
|
||||||
return
|
return
|
||||||
self.changed_signal.emit()
|
self.changed_signal.emit()
|
||||||
|
if plugin.do_user_config():
|
||||||
config_dialog = QDialog(self)
|
|
||||||
button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
|
|
||||||
v = QVBoxLayout(config_dialog)
|
|
||||||
|
|
||||||
button_box.accepted.connect(config_dialog.accept)
|
|
||||||
button_box.rejected.connect(config_dialog.reject)
|
|
||||||
config_dialog.setWindowTitle(_('Customize') + ' ' + plugin.name)
|
|
||||||
|
|
||||||
if hasattr(plugin, 'config_widget'):
|
|
||||||
config_widget = plugin.config_widget()
|
|
||||||
v.addWidget(config_widget)
|
|
||||||
v.addWidget(button_box)
|
|
||||||
config_dialog.exec_()
|
|
||||||
|
|
||||||
if config_dialog.result() == QDialog.Accepted:
|
|
||||||
if hasattr(config_widget, 'validate'):
|
|
||||||
if config_widget.validate():
|
|
||||||
plugin.save_settings(config_widget)
|
|
||||||
else:
|
|
||||||
plugin.save_settings(config_widget)
|
|
||||||
self._plugin_model.refresh_plugin(plugin)
|
|
||||||
else:
|
|
||||||
help_text = plugin.customization_help(gui=True)
|
|
||||||
help_text = QLabel(help_text, config_dialog)
|
|
||||||
help_text.setWordWrap(True)
|
|
||||||
help_text.setTextInteractionFlags(Qt.LinksAccessibleByMouse
|
|
||||||
| Qt.LinksAccessibleByKeyboard)
|
|
||||||
help_text.setOpenExternalLinks(True)
|
|
||||||
v.addWidget(help_text)
|
|
||||||
sc = plugin_customization(plugin)
|
|
||||||
if not sc:
|
|
||||||
sc = ''
|
|
||||||
sc = sc.strip()
|
|
||||||
sc = QLineEdit(sc, config_dialog)
|
|
||||||
v.addWidget(sc)
|
|
||||||
v.addWidget(button_box)
|
|
||||||
config_dialog.exec_()
|
|
||||||
|
|
||||||
if config_dialog.result() == QDialog.Accepted:
|
|
||||||
sc = unicode(sc.text()).strip()
|
|
||||||
customize_plugin(plugin, sc)
|
|
||||||
|
|
||||||
self._plugin_model.refresh_plugin(plugin)
|
self._plugin_model.refresh_plugin(plugin)
|
||||||
elif op == 'remove':
|
elif op == 'remove':
|
||||||
if remove_plugin(plugin):
|
if remove_plugin(plugin):
|
||||||
|
@ -101,7 +101,19 @@ def html_to_lxml(raw):
|
|||||||
root = html.fragment_fromstring(raw)
|
root = html.fragment_fromstring(raw)
|
||||||
root.set('xmlns', "http://www.w3.org/1999/xhtml")
|
root.set('xmlns', "http://www.w3.org/1999/xhtml")
|
||||||
raw = etree.tostring(root, encoding=None)
|
raw = etree.tostring(root, encoding=None)
|
||||||
|
try:
|
||||||
return etree.fromstring(raw)
|
return etree.fromstring(raw)
|
||||||
|
except:
|
||||||
|
for x in root.iterdescendants():
|
||||||
|
remove = []
|
||||||
|
for attr in x.attrib:
|
||||||
|
if ':' in attr:
|
||||||
|
remove.append(attr)
|
||||||
|
for a in remove:
|
||||||
|
del x.attrib[a]
|
||||||
|
raw = etree.tostring(root, encoding=None)
|
||||||
|
return etree.fromstring(raw)
|
||||||
|
|
||||||
|
|
||||||
def CATALOG_ENTRY(item, item_kind, base_href, version, updated,
|
def CATALOG_ENTRY(item, item_kind, base_href, version, updated,
|
||||||
ignore_count=False, add_kind=False):
|
ignore_count=False, add_kind=False):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user