mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
pep8 and misc fixes
This commit is contained in:
parent
5b76089839
commit
6ad22b392b
@ -106,6 +106,7 @@ class FormatsList(MutableBase, MutableSequence):
|
|||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
|
||||||
# Lazy metadata getters {{{
|
# Lazy metadata getters {{{
|
||||||
ga = object.__getattribute__
|
ga = object.__getattribute__
|
||||||
sa = object.__setattr__
|
sa = object.__setattr__
|
||||||
@ -223,6 +224,7 @@ def has_cover_getter(dbref, book_id, cache):
|
|||||||
cache['has_cover'] = ret = _('Yes') if db.field_for('cover', book_id, default_value=False) else ''
|
cache['has_cover'] = ret = _('Yes') if db.field_for('cover', book_id, default_value=False) else ''
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
fmt_custom = lambda x:list(x) if isinstance(x, tuple) else x
|
fmt_custom = lambda x:list(x) if isinstance(x, tuple) else x
|
||||||
|
|
||||||
|
|
||||||
@ -276,6 +278,7 @@ def user_categories_getter(proxy_metadata):
|
|||||||
ret = cache['user_categories'] = db.user_categories_for_books((book_id,), {book_id:proxy_metadata})[book_id]
|
ret = cache['user_categories'] = db.user_categories_for_books((book_id,), {book_id:proxy_metadata})[book_id]
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
getters = {
|
getters = {
|
||||||
'title':simple_getter('title', _('Unknown')),
|
'title':simple_getter('title', _('Unknown')),
|
||||||
'title_sort':simple_getter('sort', _('Unknown')),
|
'title_sort':simple_getter('sort', _('Unknown')),
|
||||||
|
@ -10,6 +10,7 @@ import os, re
|
|||||||
|
|
||||||
from polyglot.builtins import unicode_type
|
from polyglot.builtins import unicode_type
|
||||||
|
|
||||||
|
|
||||||
def node_mountpoint(node):
|
def node_mountpoint(node):
|
||||||
|
|
||||||
def de_mangle(raw):
|
def de_mangle(raw):
|
||||||
|
@ -59,11 +59,11 @@ def build_template_regexp(template):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
template = template.rpartition('/')[2]
|
template = template.rpartition('/')[2]
|
||||||
return re.compile(re.sub('{([^}]*)}', f, template) + '([_\d]*$)')
|
return re.compile(re.sub('{([^}]*)}', f, template) + r'([_\d]*$)')
|
||||||
except:
|
except:
|
||||||
prints(u'Failed to parse template: %r'%template)
|
prints(u'Failed to parse template: %r'%template)
|
||||||
template = u'{title} - {authors}'
|
template = u'{title} - {authors}'
|
||||||
return re.compile(re.sub('{([^}]*)}', f, template) + '([_\d]*$)')
|
return re.compile(re.sub('{([^}]*)}', f, template) + r'([_\d]*$)')
|
||||||
|
|
||||||
|
|
||||||
def create_upload_path(mdata, fname, template, sanitize,
|
def create_upload_path(mdata, fname, template, sanitize,
|
||||||
|
@ -61,6 +61,7 @@ def substitute_entites(raw):
|
|||||||
from calibre import xml_entity_to_unicode
|
from calibre import xml_entity_to_unicode
|
||||||
return ENTITY_PATTERN.sub(xml_entity_to_unicode, raw)
|
return ENTITY_PATTERN.sub(xml_entity_to_unicode, raw)
|
||||||
|
|
||||||
|
|
||||||
_CHARSET_ALIASES = {"macintosh" : "mac-roman",
|
_CHARSET_ALIASES = {"macintosh" : "mac-roman",
|
||||||
"x-sjis" : "shift-jis"}
|
"x-sjis" : "shift-jis"}
|
||||||
|
|
||||||
|
@ -368,7 +368,9 @@ class EPUBInput(InputFormatPlugin):
|
|||||||
def add_from_li(li, parent):
|
def add_from_li(li, parent):
|
||||||
href = text = None
|
href = text = None
|
||||||
for x in li.iterchildren(XHTML('a'), XHTML('span')):
|
for x in li.iterchildren(XHTML('a'), XHTML('span')):
|
||||||
text = etree.tostring(x, method='text', encoding=unicode_type, with_tail=False).strip() or ' '.join(x.xpath('descendant-or-self::*/@title')).strip()
|
text = etree.tostring(
|
||||||
|
x, method='text', encoding=unicode_type, with_tail=False).strip() or ' '.join(
|
||||||
|
x.xpath('descendant-or-self::*/@title')).strip()
|
||||||
href = x.get('href')
|
href = x.get('href')
|
||||||
if href:
|
if href:
|
||||||
if href.startswith('#'):
|
if href.startswith('#'):
|
||||||
|
@ -309,9 +309,11 @@ class HeuristicProcessor(object):
|
|||||||
if float(self.chapters_with_title) / float(hits) > .5:
|
if float(self.chapters_with_title) / float(hits) > .5:
|
||||||
title_req = True
|
title_req = True
|
||||||
strict_title = False
|
strict_title = False
|
||||||
self.log.debug(unicode_type(type_name)+" had "+unicode_type(hits)+" hits - "+unicode_type(self.chapters_no_title)+" chapters with no title, "+
|
self.log.debug(
|
||||||
unicode_type(self.chapters_with_title)+" chapters with titles, "+
|
unicode_type(type_name)+" had "+unicode_type(hits)+
|
||||||
unicode_type(float(self.chapters_with_title) / float(hits))+" percent. ")
|
" hits - "+unicode_type(self.chapters_no_title)+" chapters with no title, "+
|
||||||
|
unicode_type(self.chapters_with_title)+" chapters with titles, "+
|
||||||
|
unicode_type(float(self.chapters_with_title) / float(hits))+" percent. ")
|
||||||
if type_name == 'common':
|
if type_name == 'common':
|
||||||
analysis_result.append([chapter_type, n_lookahead_req, strict_title, ignorecase, title_req, log_message, type_name])
|
analysis_result.append([chapter_type, n_lookahead_req, strict_title, ignorecase, title_req, log_message, type_name])
|
||||||
elif self.min_chapters <= hits < max_chapters or self.min_chapters < 3 > hits:
|
elif self.min_chapters <= hits < max_chapters or self.min_chapters < 3 > hits:
|
||||||
|
@ -264,6 +264,7 @@ class DOCX(object):
|
|||||||
except EnvironmentError:
|
except EnvironmentError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
d = DOCX(sys.argv[-1], extract=False)
|
d = DOCX(sys.argv[-1], extract=False)
|
||||||
print (d.metadata)
|
print(d.metadata)
|
||||||
|
@ -95,6 +95,7 @@ def read_indent(parent, dest, XPath, get):
|
|||||||
ans = _read_width(cs, get)
|
ans = _read_width(cs, get)
|
||||||
setattr(dest, 'indent', ans)
|
setattr(dest, 'indent', ans)
|
||||||
|
|
||||||
|
|
||||||
border_edges = ('left', 'top', 'right', 'bottom', 'insideH', 'insideV')
|
border_edges = ('left', 'top', 'right', 'bottom', 'insideH', 'insideV')
|
||||||
|
|
||||||
|
|
||||||
|
@ -272,7 +272,7 @@ class OEB2HTMLInlineCSSizer(OEB2HTML):
|
|||||||
# as a page break and remove all other page break types that might be set.
|
# as a page break and remove all other page break types that might be set.
|
||||||
style_a = 'page-break-before: always; %s' % re.sub('page-break-[^:]+:[^;]+;?', '', style_a)
|
style_a = 'page-break-before: always; %s' % re.sub('page-break-[^:]+:[^;]+;?', '', style_a)
|
||||||
# Remove unnecessary spaces.
|
# Remove unnecessary spaces.
|
||||||
style_a = re.sub('\s{2,}', ' ', style_a).strip()
|
style_a = re.sub(r'\s{2,}', ' ', style_a).strip()
|
||||||
tags.append(tag)
|
tags.append(tag)
|
||||||
|
|
||||||
# Remove attributes we won't want.
|
# Remove attributes we won't want.
|
||||||
|
@ -168,5 +168,6 @@ def main(args=sys.argv, logger=None):
|
|||||||
logger.info(_('LRS written to ')+opts.out)
|
logger.info(_('LRS written to ')+opts.out)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
sys.exit(main())
|
sys.exit(main())
|
||||||
|
@ -335,8 +335,8 @@ class MetadataUpdater(object):
|
|||||||
self.original_exth_records.pop(rec[0])
|
self.original_exth_records.pop(rec[0])
|
||||||
|
|
||||||
if self.type != "BOOKMOBI":
|
if self.type != "BOOKMOBI":
|
||||||
raise MobiError("Setting metadata only supported for MOBI files of type 'BOOK'.\n"
|
raise MobiError("Setting metadata only supported for MOBI files of type 'BOOK'.\n"
|
||||||
"\tThis is a %r file of type %r" % (self.type[0:4], self.type[4:8]))
|
"\tThis is a %r file of type %r" % (self.type[0:4], self.type[4:8]))
|
||||||
|
|
||||||
recs = []
|
recs = []
|
||||||
added_501 = False
|
added_501 = False
|
||||||
|
@ -19,7 +19,7 @@ publisher_pat = re.compile(r'\{\\info.*?\{\\manager(.*?)(?<!\\)\}', re.DOTALL)
|
|||||||
|
|
||||||
def get_document_info(stream):
|
def get_document_info(stream):
|
||||||
"""
|
"""
|
||||||
Extract the \info block from an RTF file.
|
Extract the \\info block from an RTF file.
|
||||||
Return the info block as a string and the position in the file at which it
|
Return the info block as a string and the position in the file at which it
|
||||||
starts.
|
starts.
|
||||||
@param stream: File like object pointing to the RTF file.
|
@param stream: File like object pointing to the RTF file.
|
||||||
|
@ -129,7 +129,7 @@ class Reader132(FormatReader):
|
|||||||
if self.header_record.footnote_count > 0:
|
if self.header_record.footnote_count > 0:
|
||||||
html += '<br /><h1>%s</h1>' % _('Footnotes')
|
html += '<br /><h1>%s</h1>' % _('Footnotes')
|
||||||
footnoteids = re.findall(
|
footnoteids = re.findall(
|
||||||
'\w+(?=\x00)', self.section_data(self.header_record.footnote_offset).decode('cp1252' if self.encoding is None else self.encoding))
|
'\\w+(?=\x00)', self.section_data(self.header_record.footnote_offset).decode('cp1252' if self.encoding is None else self.encoding))
|
||||||
for fid, i in enumerate(range(self.header_record.footnote_offset + 1, self.header_record.footnote_offset + self.header_record.footnote_count)):
|
for fid, i in enumerate(range(self.header_record.footnote_offset + 1, self.header_record.footnote_offset + self.header_record.footnote_count)):
|
||||||
self.log.debug('Extracting footnote page %i' % i)
|
self.log.debug('Extracting footnote page %i' % i)
|
||||||
if fid < len(footnoteids):
|
if fid < len(footnoteids):
|
||||||
@ -141,7 +141,7 @@ class Reader132(FormatReader):
|
|||||||
if self.header_record.sidebar_count > 0:
|
if self.header_record.sidebar_count > 0:
|
||||||
html += '<br /><h1>%s</h1>' % _('Sidebar')
|
html += '<br /><h1>%s</h1>' % _('Sidebar')
|
||||||
sidebarids = re.findall(
|
sidebarids = re.findall(
|
||||||
'\w+(?=\x00)', self.section_data(self.header_record.sidebar_offset).decode('cp1252' if self.encoding is None else self.encoding))
|
'\\w+(?=\x00)', self.section_data(self.header_record.sidebar_offset).decode('cp1252' if self.encoding is None else self.encoding))
|
||||||
for sid, i in enumerate(range(self.header_record.sidebar_offset + 1, self.header_record.sidebar_offset + self.header_record.sidebar_count)):
|
for sid, i in enumerate(range(self.header_record.sidebar_offset + 1, self.header_record.sidebar_offset + self.header_record.sidebar_count)):
|
||||||
self.log.debug('Extracting sidebar page %i' % i)
|
self.log.debug('Extracting sidebar page %i' % i)
|
||||||
if sid < len(sidebarids):
|
if sid < len(sidebarids):
|
||||||
|
@ -77,8 +77,8 @@ class MarkdownMLizer(OEB2HTML):
|
|||||||
text = re.sub('(?msu)\n{7,}', '\n' * 6, text)
|
text = re.sub('(?msu)\n{7,}', '\n' * 6, text)
|
||||||
|
|
||||||
# Remove blank lines at beginning and end of document.
|
# Remove blank lines at beginning and end of document.
|
||||||
text = re.sub('^\s*', '', text)
|
text = re.sub(r'^\s*', '', text)
|
||||||
text = re.sub('\s*$', '\n\n', text)
|
text = re.sub(r'\s*$', '\n\n', text)
|
||||||
|
|
||||||
return text
|
return text
|
||||||
|
|
||||||
|
@ -23,7 +23,10 @@ from polyglot.builtins import unicode_type
|
|||||||
|
|
||||||
def add_window_properties_for_menu(widget, object_path, bus):
|
def add_window_properties_for_menu(widget, object_path, bus):
|
||||||
op = unicode_type(object_path)
|
op = unicode_type(object_path)
|
||||||
set_X_window_properties(widget.effectiveWinId(), _UNITY_OBJECT_PATH=op, _GTK_UNIQUE_BUS_NAME=unicode_type(bus.get_unique_name()), _GTK_MENUBAR_OBJECT_PATH=op)
|
set_X_window_properties(
|
||||||
|
widget.effectiveWinId(), _UNITY_OBJECT_PATH=op,
|
||||||
|
_GTK_UNIQUE_BUS_NAME=unicode_type(bus.get_unique_name()),
|
||||||
|
_GTK_MENUBAR_OBJECT_PATH=op)
|
||||||
|
|
||||||
|
|
||||||
class DBusMenu(QObject):
|
class DBusMenu(QObject):
|
||||||
|
@ -20,6 +20,7 @@ def log(*args, **kw):
|
|||||||
print('DBusExport:', *args, **kw)
|
print('DBusExport:', *args, **kw)
|
||||||
kw['file'].flush()
|
kw['file'].flush()
|
||||||
|
|
||||||
|
|
||||||
from calibre.ptempfile import PersistentTemporaryDirectory
|
from calibre.ptempfile import PersistentTemporaryDirectory
|
||||||
|
|
||||||
|
|
||||||
@ -60,6 +61,7 @@ class IconCache(object):
|
|||||||
# dir to decide whether it should look for new icons in the theme dir.
|
# dir to decide whether it should look for new icons in the theme dir.
|
||||||
os.utime(self.icon_theme_path, None)
|
os.utime(self.icon_theme_path, None)
|
||||||
|
|
||||||
|
|
||||||
_icon_cache = None
|
_icon_cache = None
|
||||||
|
|
||||||
|
|
||||||
|
@ -136,7 +136,11 @@ class ConfigWidget(QWidget, Ui_ConfigWidget):
|
|||||||
self.columns.setCurrentRow(idx+1)
|
self.columns.setCurrentRow(idx+1)
|
||||||
|
|
||||||
def format_map(self):
|
def format_map(self):
|
||||||
formats = [unicode_type(self.columns.item(i).data(Qt.UserRole) or '') for i in range(self.columns.count()) if self.columns.item(i).checkState()==Qt.Checked]
|
formats = [
|
||||||
|
unicode_type(self.columns.item(i).data(Qt.UserRole) or '')
|
||||||
|
for i in range(self.columns.count())
|
||||||
|
if self.columns.item(i).checkState()==Qt.Checked
|
||||||
|
]
|
||||||
return formats
|
return formats
|
||||||
|
|
||||||
def use_subdirs(self):
|
def use_subdirs(self):
|
||||||
|
@ -197,6 +197,7 @@ class AuthorsEdit(QDialog):
|
|||||||
authors[la] = author
|
authors[la] = author
|
||||||
self.author.setText('')
|
self.author.setText('')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app = QApplication([])
|
app = QApplication([])
|
||||||
d = AuthorsEdit(['kovid goyal', 'divok layog', 'other author'], ['kovid goyal', 'other author'])
|
d = AuthorsEdit(['kovid goyal', 'divok layog', 'other author'], ['kovid goyal', 'other author'])
|
||||||
|
@ -85,10 +85,10 @@ class DeviceCategoryEditor(QDialog, Ui_DeviceCategoryEditor):
|
|||||||
|
|
||||||
def finish_editing(self, item):
|
def finish_editing(self, item):
|
||||||
if not item.text():
|
if not item.text():
|
||||||
error_dialog(self, _('Item is blank'),
|
error_dialog(self, _('Item is blank'),
|
||||||
_('An item cannot be set to nothing. Delete it instead.')).exec_()
|
_('An item cannot be set to nothing. Delete it instead.')).exec_()
|
||||||
item.setText(item.previous_text())
|
item.setText(item.previous_text())
|
||||||
return
|
return
|
||||||
if item.text() != item.initial_text():
|
if item.text() != item.initial_text():
|
||||||
id_ = int(item.data(Qt.UserRole))
|
id_ = int(item.data(Qt.UserRole))
|
||||||
self.to_rename[id_] = unicode_type(item.text())
|
self.to_rename[id_] = unicode_type(item.text())
|
||||||
|
@ -139,10 +139,11 @@ class ImportOPML(QDialog):
|
|||||||
|
|
||||||
QDialog.accept(self)
|
QDialog.accept(self)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import sys
|
import sys
|
||||||
for group in import_opml(open(sys.argv[-1], 'rb').read()):
|
for group in import_opml(open(sys.argv[-1], 'rb').read()):
|
||||||
print (group.title)
|
print(group.title)
|
||||||
for title, url in group.feeds:
|
for title, url in group.feeds:
|
||||||
print ('\t%s - %s' % (title, url))
|
print('\t%s - %s' % (title, url))
|
||||||
print ()
|
print()
|
||||||
|
@ -843,7 +843,7 @@ class PluginUpdaterDialog(SizePersistedDialog):
|
|||||||
if heading_node.text_content().lower().find('version history') != -1:
|
if heading_node.text_content().lower().find('version history') != -1:
|
||||||
div_node = spoiler_node.xpath('div')[0]
|
div_node = spoiler_node.xpath('div')[0]
|
||||||
text = html.tostring(div_node, method='html', encoding=unicode_type)
|
text = html.tostring(div_node, method='html', encoding=unicode_type)
|
||||||
return re.sub('<div\s.*?>', '<div>', text)
|
return re.sub(r'<div\s.*?>', '<div>', text)
|
||||||
except:
|
except:
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
prints('======= MobileRead Parse Error =======')
|
prints('======= MobileRead Parse Error =======')
|
||||||
|
@ -169,6 +169,7 @@ class BlockingBusy(QDialog):
|
|||||||
def reject(self):
|
def reject(self):
|
||||||
pass # Cannot cancel this dialog
|
pass # Cannot cancel this dialog
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
from PyQt5.Qt import QTimer
|
from PyQt5.Qt import QTimer
|
||||||
app = QApplication([])
|
app = QApplication([])
|
||||||
|
@ -28,6 +28,7 @@ def image_extensions():
|
|||||||
image_extensions.ans = [bytes(x).decode('utf-8') for x in QImageReader.supportedImageFormats()]
|
image_extensions.ans = [bytes(x).decode('utf-8') for x in QImageReader.supportedImageFormats()]
|
||||||
return image_extensions.ans
|
return image_extensions.ans
|
||||||
|
|
||||||
|
|
||||||
# This is present for compatibility with old plugins, do not use
|
# This is present for compatibility with old plugins, do not use
|
||||||
IMAGE_EXTENSIONS = ['jpg', 'jpeg', 'gif', 'png', 'bmp']
|
IMAGE_EXTENSIONS = ['jpg', 'jpeg', 'gif', 'png', 'bmp']
|
||||||
|
|
||||||
@ -181,7 +182,7 @@ def dnd_has_extension(md, extensions, allow_all_extensions=False):
|
|||||||
f = unicode_type(f)
|
f = unicode_type(f)
|
||||||
raw = data_as_string(f, md)
|
raw = data_as_string(f, md)
|
||||||
prints(f, len(raw), repr(raw[:300]), '\n')
|
prints(f, len(raw), repr(raw[:300]), '\n')
|
||||||
print ()
|
print()
|
||||||
if has_firefox_ext(md, extensions):
|
if has_firefox_ext(md, extensions):
|
||||||
return True
|
return True
|
||||||
urls = urls_from_md(md)
|
urls = urls_from_md(md)
|
||||||
|
@ -7,23 +7,24 @@ __docformat__ = 'restructuredtext en'
|
|||||||
|
|
||||||
import functools
|
import functools
|
||||||
|
|
||||||
from PyQt5.Qt import (Qt, QApplication, QStackedWidget, QMenu, QTimer,
|
from PyQt5.Qt import (
|
||||||
QSizePolicy, QStatusBar, QLabel, QFont, QAction, QTabBar, QStyle,
|
QAction, QApplication, QFont, QIcon, QLabel, QMenu, QPainter, QSizePolicy,
|
||||||
QVBoxLayout, QWidget, QSplitter, QToolButton, QIcon, QPainter, QStyleOption)
|
QSplitter, QStackedWidget, QStatusBar, QStyle, QStyleOption, Qt, QTabBar, QTimer,
|
||||||
|
QToolButton, QVBoxLayout, QWidget
|
||||||
|
)
|
||||||
|
|
||||||
|
from calibre.constants import __appname__, get_version, isosx
|
||||||
|
from calibre.customize.ui import find_plugin
|
||||||
|
from calibre.gui2 import config, error_dialog, gprefs, is_widescreen, open_url
|
||||||
|
from calibre.gui2.book_details import BookDetails
|
||||||
|
from calibre.gui2.layout_menu import LayoutMenu
|
||||||
|
from calibre.gui2.library.alternate_views import GridView
|
||||||
|
from calibre.gui2.library.views import BooksView, DeviceBooksView
|
||||||
|
from calibre.gui2.notify import get_notifier
|
||||||
|
from calibre.gui2.tag_browser.ui import TagBrowserWidget
|
||||||
|
from calibre.gui2.widgets import LayoutButton, Splitter
|
||||||
from calibre.utils.config import prefs
|
from calibre.utils.config import prefs
|
||||||
from calibre.utils.icu import sort_key
|
from calibre.utils.icu import sort_key
|
||||||
from calibre.constants import (__appname__, preferred_encoding,
|
|
||||||
get_version)
|
|
||||||
from calibre.gui2 import config, is_widescreen, gprefs, error_dialog, open_url
|
|
||||||
from calibre.gui2.library.views import BooksView, DeviceBooksView
|
|
||||||
from calibre.gui2.library.alternate_views import GridView
|
|
||||||
from calibre.gui2.widgets import Splitter, LayoutButton
|
|
||||||
from calibre.gui2.tag_browser.ui import TagBrowserWidget
|
|
||||||
from calibre.gui2.book_details import BookDetails
|
|
||||||
from calibre.gui2.notify import get_notifier
|
|
||||||
from calibre.gui2.layout_menu import LayoutMenu
|
|
||||||
from calibre.customize.ui import find_plugin
|
|
||||||
from calibre.utils.localization import localize_website_link
|
from calibre.utils.localization import localize_website_link
|
||||||
from polyglot.builtins import unicode_type
|
from polyglot.builtins import unicode_type
|
||||||
|
|
||||||
|
@ -778,7 +778,7 @@ class BooksModel(QAbstractTableModel): # {{{
|
|||||||
|
|
||||||
def func(idx):
|
def func(idx):
|
||||||
val = fffunc(field_obj, idfunc(idx), default_value=0) or 0
|
val = fffunc(field_obj, idfunc(idx), default_value=0) or 0
|
||||||
if val is 0:
|
if val == 0:
|
||||||
return None
|
return None
|
||||||
ans = u'%.1f' % (val * sz_mult)
|
ans = u'%.1f' % (val * sz_mult)
|
||||||
return (u'<0.1' if ans == u'0.0' else ans)
|
return (u'<0.1' if ans == u'0.0' else ans)
|
||||||
@ -1027,8 +1027,8 @@ class BooksModel(QAbstractTableModel): # {{{
|
|||||||
return (self.headers[self.column_map[section]])
|
return (self.headers[self.column_map[section]])
|
||||||
return None
|
return None
|
||||||
if DEBUG and role == Qt.ToolTipRole and orientation == Qt.Vertical:
|
if DEBUG and role == Qt.ToolTipRole and orientation == Qt.Vertical:
|
||||||
col = self.db.field_metadata['uuid']['rec_index']
|
col = self.db.field_metadata['uuid']['rec_index']
|
||||||
return (_('This book\'s UUID is "{0}"').format(self.db.data[section][col]))
|
return (_('This book\'s UUID is "{0}"').format(self.db.data[section][col]))
|
||||||
|
|
||||||
if role == Qt.DisplayRole: # orientation is vertical
|
if role == Qt.DisplayRole: # orientation is vertical
|
||||||
return (section+1)
|
return (section+1)
|
||||||
|
@ -436,10 +436,10 @@ class BooksView(QTableView): # {{{
|
|||||||
m = ans.addMenu(_('Change text alignment for %s') % name)
|
m = ans.addMenu(_('Change text alignment for %s') % name)
|
||||||
al = self._model.alignment_map.get(col, 'left')
|
al = self._model.alignment_map.get(col, 'left')
|
||||||
for x, t in (('left', _('Left')), ('right', _('Right')), ('center', _('Center'))):
|
for x, t in (('left', _('Left')), ('right', _('Right')), ('center', _('Center'))):
|
||||||
a = m.addAction(t, partial(handler, action='align_'+x))
|
a = m.addAction(t, partial(handler, action='align_'+x))
|
||||||
if al == x:
|
if al == x:
|
||||||
a.setCheckable(True)
|
a.setCheckable(True)
|
||||||
a.setChecked(True)
|
a.setChecked(True)
|
||||||
if not isinstance(view, DeviceBooksView):
|
if not isinstance(view, DeviceBooksView):
|
||||||
col_font = self._model.styled_columns.get(col)
|
col_font = self._model.styled_columns.get(col)
|
||||||
m = ans.addMenu(_('Change font style for %s') % name)
|
m = ans.addMenu(_('Change font style for %s') % name)
|
||||||
|
@ -418,5 +418,6 @@ def main():
|
|||||||
QTimer.singleShot(10, doit)
|
QTimer.singleShot(10, doit)
|
||||||
app.exec_()
|
app.exec_()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
@ -302,7 +302,7 @@ class CreateVirtualLibrary(QDialog): # {{{
|
|||||||
_('The search found no books, so the virtual library '
|
_('The search found no books, so the virtual library '
|
||||||
'will be empty. Do you really want to use that search?'),
|
'will be empty. Do you really want to use that search?'),
|
||||||
default_yes=False):
|
default_yes=False):
|
||||||
return
|
return
|
||||||
|
|
||||||
self.library_name = n
|
self.library_name = n
|
||||||
self.library_search = v
|
self.library_search = v
|
||||||
|
@ -34,7 +34,7 @@ from calibre.gui2.tweak_book.widgets import BusyCursor
|
|||||||
from calibre.gui2.widgets2 import FlowLayout, HistoryComboBox
|
from calibre.gui2.widgets2 import FlowLayout, HistoryComboBox
|
||||||
from calibre.utils.icu import primary_contains
|
from calibre.utils.icu import primary_contains
|
||||||
from calibre.ebooks.conversion.search_replace import REGEX_FLAGS, compile_regular_expression
|
from calibre.ebooks.conversion.search_replace import REGEX_FLAGS, compile_regular_expression
|
||||||
src/calibre/gui2/tweak_book/preferences.py
|
from polyglot.builtins import unicode_type
|
||||||
|
|
||||||
|
|
||||||
# The search panel {{{
|
# The search panel {{{
|
||||||
|
@ -281,11 +281,11 @@ class SendEmail(QWidget, Ui_Form):
|
|||||||
_('You must either set both the username <b>and</b> password for '
|
_('You must either set both the username <b>and</b> password for '
|
||||||
'the mail server or no username and no password at all.')).exec_()
|
'the mail server or no username and no password at all.')).exec_()
|
||||||
return False
|
return False
|
||||||
if not (username and password) and not question_dialog(self,
|
if not (username and password) and not question_dialog(
|
||||||
_('Are you sure?'),
|
self, _('Are you sure?'),
|
||||||
_('No username and password set for mailserver. Most '
|
_('No username and password set for mailserver. Most '
|
||||||
' mailservers need a username and password. Are you sure?')):
|
' mailservers need a username and password. Are you sure?')):
|
||||||
return False
|
return False
|
||||||
conf = smtp_prefs()
|
conf = smtp_prefs()
|
||||||
conf.set('from_', from_)
|
conf.set('from_', from_)
|
||||||
conf.set('relay_host', host if host else None)
|
conf.set('relay_host', host if host else None)
|
||||||
|
@ -437,18 +437,17 @@ def update_serialized_metadata(book, common_data=None):
|
|||||||
plugboard_cache = common_data
|
plugboard_cache = common_data
|
||||||
from calibre.customize.ui import apply_null_metadata
|
from calibre.customize.ui import apply_null_metadata
|
||||||
with apply_null_metadata:
|
with apply_null_metadata:
|
||||||
|
fmts = [fp.rpartition(os.extsep)[-1] for fp in book['fmts']]
|
||||||
|
mi, cdata = read_serialized_metadata(book)
|
||||||
|
|
||||||
fmts = [fp.rpartition(os.extsep)[-1] for fp in book['fmts']]
|
def report_error(fmt, tb):
|
||||||
mi, cdata = read_serialized_metadata(book)
|
result.append((fmt, tb))
|
||||||
|
|
||||||
def report_error(fmt, tb):
|
for fmt, fmtpath in zip(fmts, book['fmts']):
|
||||||
result.append((fmt, tb))
|
try:
|
||||||
|
with lopen(fmtpath, 'r+b') as stream:
|
||||||
for fmt, fmtpath in zip(fmts, book['fmts']):
|
update_metadata(mi, fmt, stream, (), cdata, error_report=report_error, plugboard_cache=plugboard_cache)
|
||||||
try:
|
except Exception:
|
||||||
with lopen(fmtpath, 'r+b') as stream:
|
report_error(fmt, traceback.format_exc())
|
||||||
update_metadata(mi, fmt, stream, (), cdata, error_report=report_error, plugboard_cache=plugboard_cache)
|
|
||||||
except Exception:
|
|
||||||
report_error(fmt, traceback.format_exc())
|
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
@ -177,7 +177,7 @@ class Dictionaries(object):
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.remove_hyphenation = re.compile('[\u2010-]+')
|
self.remove_hyphenation = re.compile('[\u2010-]+')
|
||||||
self.negative_pat = re.compile('-[.\d+]')
|
self.negative_pat = re.compile(r'-[.\d+]')
|
||||||
self.fix_punctuation_pat = re.compile(r'''[:.]''')
|
self.fix_punctuation_pat = re.compile(r'''[:.]''')
|
||||||
self.dictionaries = {}
|
self.dictionaries = {}
|
||||||
self.word_cache = {}
|
self.word_cache = {}
|
||||||
|
@ -398,6 +398,7 @@ class FontScanner(Thread):
|
|||||||
prints()
|
prints()
|
||||||
prints()
|
prints()
|
||||||
|
|
||||||
|
|
||||||
font_scanner = FontScanner()
|
font_scanner = FontScanner()
|
||||||
font_scanner.start()
|
font_scanner.start()
|
||||||
|
|
||||||
@ -407,5 +408,6 @@ def force_rescan():
|
|||||||
font_scanner.force_rescan()
|
font_scanner.force_rescan()
|
||||||
font_scanner.run()
|
font_scanner.run()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
font_scanner.dump_fonts()
|
font_scanner.dump_fonts()
|
||||||
|
@ -121,8 +121,8 @@ def fixattrs(attrs):
|
|||||||
def onlywhite(line):
|
def onlywhite(line):
|
||||||
"""Return true if the line does only consist of whitespace characters."""
|
"""Return true if the line does only consist of whitespace characters."""
|
||||||
for c in line:
|
for c in line:
|
||||||
if c is not ' ' and c is not ' ':
|
if c != ' ' and c != ' ':
|
||||||
return c is ' '
|
return c == ' '
|
||||||
return line
|
return line
|
||||||
|
|
||||||
|
|
||||||
@ -136,7 +136,7 @@ def optwrap(text):
|
|||||||
newlines = 0
|
newlines = 0
|
||||||
for para in text.split("\n"):
|
for para in text.split("\n"):
|
||||||
if len(para) > 0:
|
if len(para) > 0:
|
||||||
if para[0] is not ' ' and para[0] is not '-' and para[0] is not '*':
|
if para[0] != ' ' and para[0] != '-' and para[0] != '*':
|
||||||
for line in wrap(para, BODY_WIDTH):
|
for line in wrap(para, BODY_WIDTH):
|
||||||
result += line + "\n"
|
result += line + "\n"
|
||||||
result += "\n"
|
result += "\n"
|
||||||
|
@ -329,7 +329,7 @@ def get_icon(path, pixmap_to_data=None, as_data=False, size=64):
|
|||||||
from PyQt5.Qt import QImage, Qt
|
from PyQt5.Qt import QImage, Qt
|
||||||
names.sort(key=numeric_sort_key)
|
names.sort(key=numeric_sort_key)
|
||||||
for name in names:
|
for name in names:
|
||||||
m = re.search('(\d+)x\d+', name)
|
m = re.search(r'(\d+)x\d+', name)
|
||||||
if m is not None and int(m.group(1)) >= size:
|
if m is not None and int(m.group(1)) >= size:
|
||||||
ans = QImage(os.path.join(iconset, name))
|
ans = QImage(os.path.join(iconset, name))
|
||||||
if not ans.isNull():
|
if not ans.isNull():
|
||||||
|
@ -118,7 +118,7 @@ except ImportError:
|
|||||||
from htmlentitydefs import name2codepoint
|
from htmlentitydefs import name2codepoint
|
||||||
import re
|
import re
|
||||||
|
|
||||||
handle_entities = re.compile("&(\w+);").sub
|
handle_entities = re.compile(r"&(\w+);").sub
|
||||||
|
|
||||||
|
|
||||||
def unescape(string):
|
def unescape(string):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user