-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update: Changes for Python 3 support in calibre. Update: Internal changes to how dialogs are handled.
- Loading branch information
Showing
19 changed files
with
312 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
print_function) | ||
|
||
__license__ = 'GPL v3' | ||
__copyright__ = '2013-2019, David Forrester <[email protected]>' | ||
__copyright__ = '2013-2020, David Forrester <[email protected]>' | ||
__docformat__ = 'restructuredtext en' | ||
|
||
from calibre.customize import InterfaceActionBase | ||
|
@@ -13,7 +13,7 @@ class AnnotationsPlugin(InterfaceActionBase): | |
description = 'Import annotations' | ||
supported_platforms = ['linux', 'osx', 'windows'] | ||
author = 'David Forrester' | ||
version = (1, 12, 0) | ||
version = (1, 13, 0) | ||
minimum_calibre_version = (1, 0, 0) | ||
|
||
actual_plugin = 'calibre_plugins.annotations.action:AnnotationsAction' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,10 +5,18 @@ | |
print_function) | ||
|
||
__license__ = 'GPL v3' | ||
__copyright__ = '2013, Greg Riker <[email protected]>, 2014-2019 additions by David Forrester <[email protected]>' | ||
__copyright__ = '2013, Greg Riker <[email protected]>, 2014-2020 additions by David Forrester <[email protected]>' | ||
__docformat__ = 'restructuredtext en' | ||
|
||
import imp, inspect, os, re, sys, tempfile, threading, types, urlparse | ||
import imp, inspect, os, re, sys, tempfile, threading, types | ||
|
||
# calibre Python 3 compatibility. | ||
try: | ||
from urllib.parse import urlparse | ||
except ImportError as e: | ||
from urlparse import urlparse | ||
import six | ||
from six import text_type as unicode | ||
|
||
from functools import partial | ||
from zipfile import ZipFile | ||
|
@@ -153,12 +161,14 @@ def add_annotations_to_calibre(self, book_mi, annotations_db, cid): | |
# Any older annotations? | ||
um = mi.metadata_for_field(update_field) | ||
if mi.get_user_metadata(update_field, False)['#value#'] is None: | ||
um['#value#'] = unicode(new_soup) | ||
um['#value#'] = new_soup | ||
# um['#value#'] = unicode(new_soup) | ||
else: | ||
# Merge new hashes into old | ||
old_soup = BeautifulSoup(mi.get_user_metadata(update_field, False)['#value#']) | ||
merged_soup = merge_annotations(self, cid, old_soup, new_soup) | ||
um['#value#'] = unicode(merged_soup) | ||
# um['#value#'] = unicode(merged_soup) | ||
um['#value#'] = merged_soup | ||
mi.set_user_metadata(update_field, um) | ||
db.set_metadata(cid, mi, set_title=False, set_authors=False) | ||
db.commit() | ||
|
@@ -254,8 +264,8 @@ def do_drop_event(self): | |
self._log("waiting for library_scanner()") | ||
self.library_scanner.wait() | ||
|
||
path = urlparse.urlparse(self.dropped_url).path.strip() | ||
scheme = urlparse.urlparse(self.dropped_url).scheme | ||
path = urlparse(self.dropped_url).path.strip() | ||
scheme = urlparse(self.dropped_url).scheme | ||
path = re.sub('%20', ' ', path) | ||
self._log_location(path) | ||
|
||
|
@@ -534,7 +544,7 @@ def get_annotated_books_in_ios_reader_app(self, reader_app): | |
this_book_list = [] | ||
for book in books: | ||
book_mi = {} | ||
for key in book.keys(): | ||
for key in list(book.keys()): | ||
book_mi[key] = book[key] | ||
if not book_mi['active']: | ||
continue | ||
|
@@ -596,7 +606,7 @@ def get_annotated_books_on_usb_device(self, reader_app): | |
this_book_list = [] | ||
for book in books: | ||
book_mi = {} | ||
for key in book.keys(): | ||
for key in list(book.keys()): | ||
book_mi[key] = book[key] | ||
if not book_mi['active']: | ||
continue | ||
|
@@ -844,7 +854,7 @@ def load_dynamic_reader_classes(self): | |
tmp_file = os.path.join(tempfile.gettempdir(), plugin_tmpdir, basename) | ||
if not os.path.exists(os.path.dirname(tmp_file)): | ||
os.makedirs(os.path.dirname(tmp_file)) | ||
with open(tmp_file, 'w') as tf: | ||
with open(tmp_file, 'wb') as tf: | ||
tf.write(get_resources(rac)) | ||
self._log(" loading built-in class '%s'" % name) | ||
imp.load_source(name, tmp_file) | ||
|
@@ -1196,7 +1206,7 @@ def rebuild_menus(self): | |
ac.triggered.connect(self.show_supported_ios_reader_apps) | ||
|
||
else: | ||
usb_reader_classes = USBReader.get_usb_reader_classes().keys() | ||
usb_reader_classes = list(USBReader.get_usb_reader_classes().keys()) | ||
primary_name = self.connected_device.name.split()[0] | ||
if primary_name in usb_reader_classes: | ||
haveDevice = True | ||
|
@@ -1304,7 +1314,7 @@ def show_help(self): | |
def show_supported_ios_reader_apps(self): | ||
''' | ||
''' | ||
supported_reader_apps = sorted(iOSReaderApp.get_reader_app_classes().keys(), | ||
supported_reader_apps = sorted(list(iOSReaderApp.get_reader_app_classes().keys()), | ||
key=lambda s: s.lower()) | ||
|
||
title = _("Supported iOS reader apps") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,16 @@ | |
# coding: utf-8 | ||
|
||
__license__ = 'GPL v3' | ||
__copyright__ = '2013, Greg Riker <[email protected]>, 2014-2017 additions by David Forrester <[email protected]>' | ||
__copyright__ = '2013, Greg Riker <[email protected]>, 2014-2020 additions by David Forrester <[email protected]>' | ||
__docformat__ = 'restructuredtext en' | ||
|
||
import operator | ||
from time import localtime, strftime | ||
|
||
# calibre Python 3 compatibility. | ||
import six | ||
from six import text_type as unicode | ||
|
||
from calibre.devices.usbms.driver import debug_print | ||
try: | ||
from PyQt5 import QtCore | ||
|
@@ -306,7 +310,7 @@ def __init__(self, parent, book_list, get_annotations_as_HTML, source): | |
# Set row height | ||
fm = QFontMetrics(self.FONT) | ||
nrows = len(self.tabledata) | ||
for row in xrange(nrows): | ||
for row in range(nrows): | ||
self.tv.setRowHeight(row, fm.height() + 4) | ||
|
||
self.tv.setSortingEnabled(True) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,11 +5,15 @@ | |
print_function) | ||
|
||
__license__ = 'GPL v3' | ||
__copyright__ = '2013, Greg Riker <[email protected]>, 2014-2019 additions by David Forrester <[email protected]>' | ||
__copyright__ = '2013, Greg Riker <[email protected]>, 2014-2020 additions by David Forrester <[email protected]>' | ||
__docformat__ = 'restructuredtext en' | ||
|
||
import hashlib, re | ||
|
||
# calibre Python 3 compatibility. | ||
import six | ||
from six import text_type as unicode | ||
|
||
from datetime import datetime | ||
from xml.sax.saxutils import escape | ||
|
||
|
@@ -117,6 +121,7 @@ def to_HTML(self, header=''): | |
''' | ||
Generate HTML with user-specified CSS, element order | ||
''' | ||
from calibre.ebooks.BeautifulSoup import prettify | ||
# Retrieve CSS prefs | ||
from calibre_plugins.annotations.appearance import default_elements | ||
stored_css = plugin_prefs.get('appearance_css', default_elements) | ||
|
@@ -187,12 +192,12 @@ def to_HTML(self, header=''): | |
|
||
if agroup.hash is not None: | ||
# Use existing hash when re-rendering | ||
hash = agroup.hash | ||
annotation_hash = agroup.hash | ||
else: | ||
m = hashlib.md5() | ||
m.update(text) | ||
m.update(note) | ||
hash = m.hexdigest() | ||
m.update(text.encode('utf-8')) | ||
m.update(note.encode('utf-8')) | ||
annotation_hash = m.hexdigest() | ||
|
||
try: | ||
ka_soup = BeautifulSoup() | ||
|
@@ -214,7 +219,7 @@ def to_HTML(self, header=''): | |
divTag['genre'] = '' | ||
if agroup.genre: | ||
divTag['genre'] = escape(agroup.genre) | ||
divTag['hash'] = hash | ||
divTag['hash'] = annotation_hash | ||
divTag['location_sort'] = agroup.location_sort | ||
divTag['reader'] = agroup.reader_app | ||
divTag['style'] = ANNOTATION_DIV_STYLE | ||
|
@@ -227,7 +232,7 @@ def to_HTML(self, header=''): | |
|
||
else: | ||
soup = BeautifulSoup(ANNOTATIONS_HEADER) | ||
return unicode(soup.renderContents()) | ||
return prettify(soup) | ||
|
||
|
||
def merge_annotations(parent, cid, old_soup, new_soup): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
# coding: utf-8 | ||
|
||
__license__ = 'GPL v3' | ||
__copyright__ = '2013, Greg Riker <[email protected]>, 2014-2019 additions by David Forrester <[email protected]>' | ||
__copyright__ = '2013, Greg Riker <[email protected]>, 2014-2020 additions by David Forrester <[email protected]>' | ||
__docformat__ = 'restructuredtext en' | ||
|
||
import os, sqlite3, sys | ||
|
@@ -169,7 +169,7 @@ def _row_to_dict(ann): | |
|
||
# Create an Annotations object to hold annotations | ||
stored_annotations = Annotations(self.opts, title=book_mi['title']) | ||
annotations = self.get_annotations(annotations_db, book_mi[b'book_id']) | ||
annotations = self.get_annotations(annotations_db, book_mi['book_id']) | ||
for ann in annotations: | ||
ann = _row_to_dict(ann) | ||
ann['reader_app'] = book_mi['reader_app'] | ||
|
@@ -211,7 +211,7 @@ def _row_to_dict(ann): | |
|
||
# Create an Annotations object to hold annotations | ||
stored_annotations = Annotations(self.opts, title=book_mi['title']) | ||
annotations = self.get_annotations(annotations_db, book_mi[b'book_id']) | ||
annotations = self.get_annotations(annotations_db, book_mi['book_id']) | ||
for ann in annotations: | ||
ann = _row_to_dict(ann) | ||
ann['reader_app'] = book_mi['reader_app'] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,11 +5,15 @@ | |
print_function) | ||
|
||
__license__ = 'GPL v3' | ||
__copyright__ = '2013, Greg Riker <[email protected]>, 2014-2017 additions by David Forrester <[email protected]>' | ||
__copyright__ = '2013, Greg Riker <[email protected]>, 2014-2020 additions by David Forrester <[email protected]>' | ||
__docformat__ = 'restructuredtext en' | ||
|
||
import re, time | ||
|
||
# calibre Python 3 compatibility. | ||
import six | ||
from six import text_type as unicode | ||
|
||
from functools import partial | ||
|
||
from calibre.devices.usbms.driver import debug_print | ||
|
Oops, something went wrong.