mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix broken LIT Output. Fixes #769334 (Error converting from [any] to Lit)
This commit is contained in:
parent
267a02a49e
commit
ae85da399a
@ -1,75 +0,0 @@
|
||||
'''
|
||||
Device profiles.
|
||||
'''
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2008, Marshall T. Vandegrift <llasram@gmail.com>'
|
||||
|
||||
from itertools import izip
|
||||
|
||||
FONT_SIZES = [('xx-small', 1),
|
||||
('x-small', None),
|
||||
('small', 2),
|
||||
('medium', 3),
|
||||
('large', 4),
|
||||
('x-large', 5),
|
||||
('xx-large', 6),
|
||||
(None, 7)]
|
||||
|
||||
|
||||
class Profile(object):
|
||||
def __init__(self, width, height, dpi, fbase, fsizes):
|
||||
self.width = (float(width) / dpi) * 72.
|
||||
self.height = (float(height) / dpi) * 72.
|
||||
self.dpi = float(dpi)
|
||||
self.fbase = float(fbase)
|
||||
self.fsizes = []
|
||||
for (name, num), size in izip(FONT_SIZES, fsizes):
|
||||
self.fsizes.append((name, num, float(size)))
|
||||
self.fnames = dict((name, sz) for name, _, sz in self.fsizes if name)
|
||||
self.fnums = dict((num, sz) for _, num, sz in self.fsizes if num)
|
||||
|
||||
|
||||
PROFILES = {
|
||||
'PRS505':
|
||||
Profile(width=584, height=754, dpi=168.451, fbase=12,
|
||||
fsizes=[7.5, 9, 10, 12, 15.5, 20, 22, 24]),
|
||||
|
||||
'MSReader':
|
||||
Profile(width=480, height=652, dpi=96, fbase=13,
|
||||
fsizes=[10, 11, 13, 16, 18, 20, 22, 26]),
|
||||
|
||||
# Not really, but let's pretend
|
||||
'Mobipocket':
|
||||
Profile(width=600, height=800, dpi=96, fbase=18,
|
||||
fsizes=[14, 14, 16, 18, 20, 22, 24, 26]),
|
||||
|
||||
# No clue on usable screen size; DPI should be good
|
||||
'HanlinV3':
|
||||
Profile(width=584, height=754, dpi=168.451, fbase=16,
|
||||
fsizes=[12, 12, 14, 16, 18, 20, 22, 24]),
|
||||
|
||||
'CybookG3':
|
||||
Profile(width=600, height=800, dpi=168.451, fbase=16,
|
||||
fsizes=[12, 12, 14, 16, 18, 20, 22, 24]),
|
||||
|
||||
'Kindle':
|
||||
Profile(width=525, height=640, dpi=168.451, fbase=16,
|
||||
fsizes=[12, 12, 14, 16, 18, 20, 22, 24]),
|
||||
|
||||
'Browser':
|
||||
Profile(width=800, height=600, dpi=100.0, fbase=12,
|
||||
fsizes=[5, 7, 9, 12, 13.5, 17, 20, 22, 24])
|
||||
}
|
||||
|
||||
|
||||
class Context(object):
|
||||
PROFILES = PROFILES
|
||||
|
||||
def __init__(self, source, dest):
|
||||
if source in PROFILES:
|
||||
source = PROFILES[source]
|
||||
if dest in PROFILES:
|
||||
dest = PROFILES[dest]
|
||||
self.source = source
|
||||
self.dest = dest
|
@ -21,7 +21,6 @@ from calibre import force_unicode
|
||||
from calibre.ebooks import unit_convert
|
||||
from calibre.ebooks.oeb.base import XHTML, XHTML_NS, CSS_MIME, OEB_STYLES
|
||||
from calibre.ebooks.oeb.base import XPNSMAP, xpath, urlnormalize
|
||||
from calibre.ebooks.oeb.profile import PROFILES
|
||||
|
||||
cssutils.log.setLevel(logging.WARN)
|
||||
|
||||
@ -123,10 +122,10 @@ class CSSSelector(etree.XPath):
|
||||
class Stylizer(object):
|
||||
STYLESHEETS = WeakKeyDictionary()
|
||||
|
||||
def __init__(self, tree, path, oeb, opts, profile=PROFILES['PRS505'],
|
||||
def __init__(self, tree, path, oeb, opts, profile=None,
|
||||
extra_css='', user_css=''):
|
||||
self.oeb, self.opts = oeb, opts
|
||||
self.profile = profile
|
||||
self.profile = opts.input_profile
|
||||
self.logger = oeb.logger
|
||||
item = oeb.manifest.hrefs[path]
|
||||
basename = os.path.basename(path)
|
||||
|
@ -27,13 +27,13 @@ from calibre.gui2.store.web_store_dialog import WebStoreDialog
|
||||
from calibre.utils.icu import sort_key
|
||||
|
||||
class MobileReadStore(BasicStoreConfig, StorePlugin):
|
||||
|
||||
|
||||
def genesis(self):
|
||||
self.rlock = RLock()
|
||||
|
||||
|
||||
def open(self, parent=None, detail_item=None, external=False):
|
||||
url = 'http://www.mobileread.com/'
|
||||
|
||||
|
||||
if external or self.config.get('open_external', False):
|
||||
open_url(QUrl(detail_item if detail_item else url))
|
||||
else:
|
||||
@ -68,7 +68,7 @@ class MobileReadStore(BasicStoreConfig, StorePlugin):
|
||||
ratio += s.ratio()
|
||||
if ratio > 0:
|
||||
matches.append((ratio, x))
|
||||
|
||||
|
||||
# Move the best scorers to head of list.
|
||||
matches = heapq.nlargest(max_results, matches)
|
||||
for score, book in matches:
|
||||
@ -79,21 +79,21 @@ class MobileReadStore(BasicStoreConfig, StorePlugin):
|
||||
def update_book_list(self, timeout=10):
|
||||
with self.rlock:
|
||||
url = 'http://www.mobileread.com/forums/ebooks.php?do=getlist&type=html'
|
||||
|
||||
|
||||
last_download = self.config.get('last_download', None)
|
||||
# Don't update the book list if our cache is less than one week old.
|
||||
if last_download and (time.time() - last_download) < 604800:
|
||||
return
|
||||
|
||||
|
||||
# Download the book list HTML file from MobileRead.
|
||||
br = browser()
|
||||
raw_data = None
|
||||
with closing(br.open(url, timeout=timeout)) as f:
|
||||
raw_data = f.read()
|
||||
|
||||
|
||||
if not raw_data:
|
||||
return
|
||||
|
||||
|
||||
# Turn books listed in the HTML file into SearchResults's.
|
||||
books = []
|
||||
try:
|
||||
@ -103,7 +103,7 @@ class MobileReadStore(BasicStoreConfig, StorePlugin):
|
||||
book.detail_item = ''.join(book_data.xpath('.//a/@href'))
|
||||
book.formats = ''.join(book_data.xpath('.//i/text()'))
|
||||
book.formats = book.formats.strip()
|
||||
|
||||
|
||||
text = ''.join(book_data.xpath('.//a/text()'))
|
||||
if ':' in text:
|
||||
book.author, q, text = text.partition(':')
|
||||
@ -112,7 +112,7 @@ class MobileReadStore(BasicStoreConfig, StorePlugin):
|
||||
books.append(book)
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
# Save the book list and it's create time.
|
||||
if books:
|
||||
self.config['last_download'] = time.time()
|
||||
@ -121,7 +121,7 @@ class MobileReadStore(BasicStoreConfig, StorePlugin):
|
||||
def get_book_list(self, timeout=10):
|
||||
self.update_book_list(timeout=timeout)
|
||||
return self.deseralize_books(self.config.get('book_list', []))
|
||||
|
||||
|
||||
def seralize_books(self, books):
|
||||
sbooks = []
|
||||
for b in books:
|
||||
@ -132,7 +132,7 @@ class MobileReadStore(BasicStoreConfig, StorePlugin):
|
||||
data['formats'] = b.formats
|
||||
sbooks.append(data)
|
||||
return sbooks
|
||||
|
||||
|
||||
def deseralize_books(self, sbooks):
|
||||
books = []
|
||||
for s in sbooks:
|
||||
@ -146,13 +146,13 @@ class MobileReadStore(BasicStoreConfig, StorePlugin):
|
||||
|
||||
|
||||
class MobeReadStoreDialog(QDialog, Ui_Dialog):
|
||||
|
||||
|
||||
def __init__(self, plugin, *args):
|
||||
QDialog.__init__(self, *args)
|
||||
self.setupUi(self)
|
||||
|
||||
self.plugin = plugin
|
||||
|
||||
|
||||
self.model = BooksModel()
|
||||
self.results_view.setModel(self.model)
|
||||
self.results_view.model().set_books(self.plugin.get_book_list())
|
||||
@ -162,14 +162,14 @@ class MobeReadStoreDialog(QDialog, Ui_Dialog):
|
||||
self.search_query.textChanged.connect(self.model.set_filter)
|
||||
self.results_view.model().total_changed.connect(self.total.setText)
|
||||
self.finished.connect(self.dialog_closed)
|
||||
|
||||
|
||||
self.restore_state()
|
||||
|
||||
|
||||
def open_store(self, index):
|
||||
result = self.results_view.model().get_book(index)
|
||||
if result:
|
||||
self.plugin.open(self, result.detail_item)
|
||||
|
||||
|
||||
def restore_state(self):
|
||||
geometry = self.plugin.config.get('dialog_geometry', None)
|
||||
if geometry:
|
||||
@ -184,7 +184,7 @@ class MobeReadStoreDialog(QDialog, Ui_Dialog):
|
||||
else:
|
||||
for i in xrange(self.results_view.model().columnCount()):
|
||||
self.results_view.resizeColumnToContents(i)
|
||||
|
||||
|
||||
self.results_view.model().sort_col = self.plugin.config.get('dialog_sort_col', 0)
|
||||
self.results_view.model().sort_order = self.plugin.config.get('dialog_sort_order', Qt.AscendingOrder)
|
||||
self.results_view.model().sort(self.results_view.model().sort_col, self.results_view.model().sort_order)
|
||||
@ -201,7 +201,7 @@ class MobeReadStoreDialog(QDialog, Ui_Dialog):
|
||||
|
||||
|
||||
class BooksModel(QAbstractItemModel):
|
||||
|
||||
|
||||
total_changed = pyqtSignal(unicode)
|
||||
|
||||
HEADERS = [_('Title'), _('Author(s)'), _('Format')]
|
||||
@ -217,7 +217,7 @@ class BooksModel(QAbstractItemModel):
|
||||
def set_books(self, books):
|
||||
self.books = books
|
||||
self.all_books = books
|
||||
|
||||
|
||||
self.sort(self.sort_col, self.sort_order)
|
||||
|
||||
def get_book(self, index):
|
||||
@ -226,11 +226,11 @@ class BooksModel(QAbstractItemModel):
|
||||
return self.books[row]
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
def set_filter(self, filter):
|
||||
#self.layoutAboutToBeChanged.emit()
|
||||
self.beginResetModel()
|
||||
|
||||
|
||||
self.filter = unicode(filter)
|
||||
self.books = []
|
||||
if self.filter:
|
||||
@ -253,7 +253,7 @@ class BooksModel(QAbstractItemModel):
|
||||
|
||||
self.endResetModel()
|
||||
#self.layoutChanged.emit()
|
||||
|
||||
|
||||
def index(self, row, column, parent=QModelIndex()):
|
||||
return self.createIndex(row, column)
|
||||
|
||||
@ -267,7 +267,7 @@ class BooksModel(QAbstractItemModel):
|
||||
|
||||
def columnCount(self, *args):
|
||||
return len(self.HEADERS)
|
||||
|
||||
|
||||
def headerData(self, section, orientation, role):
|
||||
if role != Qt.DisplayRole:
|
||||
return NONE
|
||||
@ -307,7 +307,7 @@ class BooksModel(QAbstractItemModel):
|
||||
|
||||
if not self.books:
|
||||
return
|
||||
descending = order == Qt.DescendingOrder
|
||||
descending = order == Qt.DescendingOrder
|
||||
self.books.sort(None,
|
||||
lambda x: sort_key(unicode(self.data_as_text(x, col))),
|
||||
descending)
|
||||
|
Loading…
x
Reference in New Issue
Block a user