From 80beb72b65a96914c44e391bcd19131469821243 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Mon, 5 Aug 2019 16:14:38 -0400 Subject: [PATCH] py3: more work toward universal __future__s --- src/calibre/gui2/__init__.py | 50 ++-- src/calibre/gui2/actions/__init__.py | 5 +- src/calibre/gui2/actions/add.py | 1 + src/calibre/gui2/actions/add_to_library.py | 1 + src/calibre/gui2/actions/annotate.py | 1 + src/calibre/gui2/actions/catalog.py | 1 + src/calibre/gui2/actions/choose_library.py | 6 +- src/calibre/gui2/actions/convert.py | 1 + src/calibre/gui2/actions/copy_to_library.py | 1 + src/calibre/gui2/actions/delete.py | 1 + src/calibre/gui2/actions/device.py | 1 + src/calibre/gui2/actions/edit_collections.py | 1 + src/calibre/gui2/actions/edit_metadata.py | 5 +- src/calibre/gui2/actions/fetch_news.py | 1 + src/calibre/gui2/actions/help.py | 4 +- src/calibre/gui2/actions/next_match.py | 1 + src/calibre/gui2/actions/open.py | 3 +- src/calibre/gui2/actions/preferences.py | 1 + src/calibre/gui2/actions/restart.py | 3 +- src/calibre/gui2/actions/save_to_disk.py | 4 +- src/calibre/gui2/actions/show_book_details.py | 1 + src/calibre/gui2/actions/show_quickview.py | 1 + .../gui2/actions/show_template_tester.py | 1 + src/calibre/gui2/actions/similar_books.py | 1 + src/calibre/gui2/actions/tweak_epub.py | 1 + src/calibre/gui2/actions/unpack_book.py | 1 + src/calibre/gui2/actions/view.py | 1 + src/calibre/gui2/catalog/catalog_bibtex.py | 5 +- src/calibre/gui2/catalog/catalog_csv_xml.py | 5 +- src/calibre/gui2/catalog/catalog_epub_mobi.py | 250 +++++++++--------- src/calibre/gui2/comments_editor.py | 43 +-- src/calibre/gui2/convert/azw3_output.py | 2 +- src/calibre/gui2/convert/comic_input.py | 2 +- src/calibre/gui2/convert/docx_output.py | 1 + src/calibre/gui2/convert/epub_output.py | 2 +- src/calibre/gui2/convert/fb2_input.py | 1 + src/calibre/gui2/convert/fb2_output.py | 1 + src/calibre/gui2/convert/htmlz_output.py | 1 + src/calibre/gui2/convert/lrf_output.py | 2 +- src/calibre/gui2/convert/mobi_output.py | 2 +- src/calibre/gui2/convert/pdb_output.py | 1 + src/calibre/gui2/convert/txtz_output.py | 1 + src/calibre/gui2/device.py | 15 +- src/calibre/gui2/notify.py | 4 +- src/calibre/gui2/search_box.py | 10 +- src/calibre/gui2/tools.py | 2 + src/calibre/gui2/widgets.py | 31 +-- 47 files changed, 257 insertions(+), 223 deletions(-) diff --git a/src/calibre/gui2/__init__.py b/src/calibre/gui2/__init__.py index 091b5b1919..7812dfe1c0 100644 --- a/src/calibre/gui2/__init__.py +++ b/src/calibre/gui2/__init__.py @@ -1,6 +1,10 @@ +from __future__ import absolute_import, division, print_function, unicode_literals + __license__ = 'GPL v3' __copyright__ = '2008, Kovid Goyal ' + """ The GUI """ + import glob import os import signal @@ -354,7 +358,7 @@ def is_widescreen(): global _is_widescreen if _is_widescreen is None: try: - _is_widescreen = float(available_width())/available_height() > 1.4 + _is_widescreen = available_width()/available_height() > 1.4 except: _is_widescreen = False return _is_widescreen @@ -736,7 +740,7 @@ class Translator(QTranslator): try: src = unicode_type(args[1]) except: - return u'' + return '' t = _ return t(src) @@ -766,8 +770,8 @@ def load_builtin_fonts(): if fid > -1: fam = QFontDatabase.applicationFontFamilies(fid) fam = set(map(unicode_type, fam)) - if u'calibre Symbols' in fam: - _rating_font = u'calibre Symbols' + if 'calibre Symbols' in fam: + _rating_font = 'calibre Symbols' def setup_gui_option_parser(parser): @@ -881,7 +885,7 @@ class Application(QApplication): self.line_height = max(12, QFontMetrics(self.font()).lineSpacing()) dl = QLocale(get_lang()) - if unicode_type(dl.bcp47Name()) != u'C': + if unicode_type(dl.bcp47Name()) != 'C': QLocale.setDefault(dl) global gui_thread, qt_app gui_thread = QThread.currentThread() @@ -978,22 +982,22 @@ class Application(QApplication): icon_map = self.__icon_map_memory_ = {} pcache = {} for k, v in iteritems({ - 'DialogYesButton': u'ok.png', - 'DialogNoButton': u'window-close.png', - 'DialogCloseButton': u'window-close.png', - 'DialogOkButton': u'ok.png', - 'DialogCancelButton': u'window-close.png', - 'DialogHelpButton': u'help.png', - 'DialogOpenButton': u'document_open.png', - 'DialogSaveButton': u'save.png', - 'DialogApplyButton': u'ok.png', - 'DialogDiscardButton': u'trash.png', - 'MessageBoxInformation': u'dialog_information.png', - 'MessageBoxWarning': u'dialog_warning.png', - 'MessageBoxCritical': u'dialog_error.png', - 'MessageBoxQuestion': u'dialog_question.png', - 'BrowserReload': u'view-refresh.png', - 'LineEditClearButton': u'clear_left.png', + 'DialogYesButton': 'ok.png', + 'DialogNoButton': 'window-close.png', + 'DialogCloseButton': 'window-close.png', + 'DialogOkButton': 'ok.png', + 'DialogCancelButton': 'window-close.png', + 'DialogHelpButton': 'help.png', + 'DialogOpenButton': 'document_open.png', + 'DialogSaveButton': 'save.png', + 'DialogApplyButton': 'ok.png', + 'DialogDiscardButton': 'trash.png', + 'MessageBoxInformation': 'dialog_information.png', + 'MessageBoxWarning': 'dialog_warning.png', + 'MessageBoxCritical': 'dialog_error.png', + 'MessageBoxQuestion': 'dialog_question.png', + 'BrowserReload': 'view-refresh.png', + 'LineEditClearButton': 'clear_left.png', }): if v not in pcache: p = I(v) @@ -1242,7 +1246,7 @@ def elided_text(text, font=None, width=300, pos='middle'): from PyQt5.Qt import QFontMetrics, QApplication fm = QApplication.fontMetrics() if font is None else (font if isinstance(font, QFontMetrics) else QFontMetrics(font)) delta = 4 - ellipsis = u'\u2026' + ellipsis = '\u2026' def remove_middle(x): mid = len(x) // 2 @@ -1361,7 +1365,7 @@ def set_app_uid(val): try: AppUserModelID(unicode_type(val)) except Exception as err: - prints(u'Failed to set app uid with error:', as_unicode(err)) + prints('Failed to set app uid with error:', as_unicode(err)) return False return True diff --git a/src/calibre/gui2/actions/__init__.py b/src/calibre/gui2/actions/__init__.py index 59049a1a07..8383fd469a 100644 --- a/src/calibre/gui2/actions/__init__.py +++ b/src/calibre/gui2/actions/__init__.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' @@ -19,7 +20,7 @@ from polyglot.builtins import unicode_type, string_or_bytes def menu_action_unique_name(plugin, unique_name): - return u'%s : menu action : %s'%(plugin.unique_name, unique_name) + return '%s : menu action : %s'%(plugin.unique_name, unique_name) class InterfaceAction(QObject): @@ -151,7 +152,7 @@ class InterfaceAction(QObject): bn = self.__class__.__name__ if getattr(self.interface_action_base_plugin, 'name'): bn = self.interface_action_base_plugin.name - return u'Interface Action: %s (%s)'%(bn, self.name) + return 'Interface Action: %s (%s)'%(bn, self.name) def create_action(self, spec=None, attr='qaction', shortcut_name=None): if spec is None: diff --git a/src/calibre/gui2/actions/add.py b/src/calibre/gui2/actions/add.py index 8e41690e2c..444e654ba9 100644 --- a/src/calibre/gui2/actions/add.py +++ b/src/calibre/gui2/actions/add.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' diff --git a/src/calibre/gui2/actions/add_to_library.py b/src/calibre/gui2/actions/add_to_library.py index 9fe4da3b83..21e984b89f 100644 --- a/src/calibre/gui2/actions/add_to_library.py +++ b/src/calibre/gui2/actions/add_to_library.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' diff --git a/src/calibre/gui2/actions/annotate.py b/src/calibre/gui2/actions/annotate.py index 711ede7ccd..224de0ced9 100644 --- a/src/calibre/gui2/actions/annotate.py +++ b/src/calibre/gui2/actions/annotate.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' diff --git a/src/calibre/gui2/actions/catalog.py b/src/calibre/gui2/actions/catalog.py index 8430b69dfb..0c6144e645 100644 --- a/src/calibre/gui2/actions/catalog.py +++ b/src/calibre/gui2/actions/catalog.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' diff --git a/src/calibre/gui2/actions/choose_library.py b/src/calibre/gui2/actions/choose_library.py index 3ea3a6ddd9..cbf2410e79 100644 --- a/src/calibre/gui2/actions/choose_library.py +++ b/src/calibre/gui2/actions/choose_library.py @@ -1,7 +1,7 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import absolute_import, division, print_function, unicode_literals -from __future__ import print_function __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' __docformat__ = 'restructuredtext en' @@ -252,7 +252,7 @@ class ChooseLibraryAction(InterfaceAction): for i in range(5): ac = self.create_action(spec=('', None, None, None), attr='switch_action%d'%i) - ac.setObjectName(str(i)) + ac.setObjectName(unicode_type(i)) self.switch_actions.append(ac) ac.setVisible(False) connect_lambda(ac.triggered, self, lambda self: @@ -329,7 +329,7 @@ class ChooseLibraryAction(InterfaceAction): self.prev_lname = self.last_lname self.last_lname = lname if len(lname) > 16: - lname = lname[:16] + u'…' + lname = lname[:16] + '…' a = self.qaction a.setText(lname.replace('&', '&&&')) # I have no idea why this requires a triple ampersand self.update_tooltip(db.count()) diff --git a/src/calibre/gui2/actions/convert.py b/src/calibre/gui2/actions/convert.py index de31d199a6..d464bdb679 100644 --- a/src/calibre/gui2/actions/convert.py +++ b/src/calibre/gui2/actions/convert.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' diff --git a/src/calibre/gui2/actions/copy_to_library.py b/src/calibre/gui2/actions/copy_to_library.py index fa4a2635fa..82c7970453 100644 --- a/src/calibre/gui2/actions/copy_to_library.py +++ b/src/calibre/gui2/actions/copy_to_library.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' diff --git a/src/calibre/gui2/actions/delete.py b/src/calibre/gui2/actions/delete.py index f41810b3a8..12bd2695c4 100644 --- a/src/calibre/gui2/actions/delete.py +++ b/src/calibre/gui2/actions/delete.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' diff --git a/src/calibre/gui2/actions/device.py b/src/calibre/gui2/actions/device.py index a71d7ebeb3..0898dc3f56 100644 --- a/src/calibre/gui2/actions/device.py +++ b/src/calibre/gui2/actions/device.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' diff --git a/src/calibre/gui2/actions/edit_collections.py b/src/calibre/gui2/actions/edit_collections.py index 58b4c08f53..eda832f8fa 100644 --- a/src/calibre/gui2/actions/edit_collections.py +++ b/src/calibre/gui2/actions/edit_collections.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' diff --git a/src/calibre/gui2/actions/edit_metadata.py b/src/calibre/gui2/actions/edit_metadata.py index d0fcc7c624..d4df4d3242 100644 --- a/src/calibre/gui2/actions/edit_metadata.py +++ b/src/calibre/gui2/actions/edit_metadata.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' @@ -648,7 +649,7 @@ class EditMetadataAction(InterfaceAction): if not dest_mi.comments: dest_mi.comments = src_mi.comments else: - dest_mi.comments = unicode_type(dest_mi.comments) + u'\n\n' + unicode_type(src_mi.comments) + dest_mi.comments = unicode_type(dest_mi.comments) + '\n\n' + unicode_type(src_mi.comments) if src_mi.title and (not dest_mi.title or dest_mi.title == _('Unknown')): dest_mi.title = src_mi.title if (src_mi.authors and src_mi.authors[0] != _('Unknown')) and (not dest_mi.authors or dest_mi.authors[0] == _('Unknown')): @@ -701,7 +702,7 @@ class EditMetadataAction(InterfaceAction): if not dest_value: db.set_custom(dest_id, src_value, num=colnum) else: - dest_value = unicode_type(dest_value) + u'\n\n' + unicode_type(src_value) + dest_value = unicode_type(dest_value) + '\n\n' + unicode_type(src_value) db.set_custom(dest_id, dest_value, num=colnum) if (dt in {'bool', 'int', 'float', 'rating', 'datetime'} and dest_value is None): db.set_custom(dest_id, src_value, num=colnum) diff --git a/src/calibre/gui2/actions/fetch_news.py b/src/calibre/gui2/actions/fetch_news.py index 28b623f9b7..5aeeb5c3ba 100644 --- a/src/calibre/gui2/actions/fetch_news.py +++ b/src/calibre/gui2/actions/fetch_news.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' diff --git a/src/calibre/gui2/actions/help.py b/src/calibre/gui2/actions/help.py index b51d1ee606..da47c29d80 100644 --- a/src/calibre/gui2/actions/help.py +++ b/src/calibre/gui2/actions/help.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' @@ -22,6 +23,3 @@ class HelpAction(InterfaceAction): def show_help(self, *args): open_url(QUrl(localize_user_manual_link('https://manual.calibre-ebook.com'))) - - - diff --git a/src/calibre/gui2/actions/next_match.py b/src/calibre/gui2/actions/next_match.py index 8aa904cbbf..4e00dd2dbe 100644 --- a/src/calibre/gui2/actions/next_match.py +++ b/src/calibre/gui2/actions/next_match.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' diff --git a/src/calibre/gui2/actions/open.py b/src/calibre/gui2/actions/open.py index 02786349c7..122c0eedce 100644 --- a/src/calibre/gui2/actions/open.py +++ b/src/calibre/gui2/actions/open.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' @@ -24,5 +25,3 @@ class OpenFolderAction(InterfaceAction): enabled = loc == 'library' self.qaction.setEnabled(enabled) self.menuless_qaction.setEnabled(enabled) - - diff --git a/src/calibre/gui2/actions/preferences.py b/src/calibre/gui2/actions/preferences.py index f436450368..48ceb4db9b 100644 --- a/src/calibre/gui2/actions/preferences.py +++ b/src/calibre/gui2/actions/preferences.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' diff --git a/src/calibre/gui2/actions/restart.py b/src/calibre/gui2/actions/restart.py index 872c8d5e58..9ce20eb6ed 100644 --- a/src/calibre/gui2/actions/restart.py +++ b/src/calibre/gui2/actions/restart.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' @@ -19,5 +20,3 @@ class RestartAction(InterfaceAction): def restart(self, *args): self.gui.quit(restart=True) - - diff --git a/src/calibre/gui2/actions/save_to_disk.py b/src/calibre/gui2/actions/save_to_disk.py index 0802211a48..28b16200c6 100644 --- a/src/calibre/gui2/actions/save_to_disk.py +++ b/src/calibre/gui2/actions/save_to_disk.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' @@ -7,12 +8,11 @@ __docformat__ = 'restructuredtext en' import os, numbers from functools import partial -from polyglot.builtins import itervalues, map - from calibre.utils.config import prefs from calibre.gui2 import error_dialog, Dispatcher, choose_dir from calibre.gui2.actions import InterfaceAction +from polyglot.builtins import itervalues, map class SaveToDiskAction(InterfaceAction): diff --git a/src/calibre/gui2/actions/show_book_details.py b/src/calibre/gui2/actions/show_book_details.py index 4e4ceac324..4d3c2d164c 100644 --- a/src/calibre/gui2/actions/show_book_details.py +++ b/src/calibre/gui2/actions/show_book_details.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' diff --git a/src/calibre/gui2/actions/show_quickview.py b/src/calibre/gui2/actions/show_quickview.py index 279b91db60..28ce9aaf52 100644 --- a/src/calibre/gui2/actions/show_quickview.py +++ b/src/calibre/gui2/actions/show_quickview.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' diff --git a/src/calibre/gui2/actions/show_template_tester.py b/src/calibre/gui2/actions/show_template_tester.py index 7f62c291fe..08fc12c654 100644 --- a/src/calibre/gui2/actions/show_template_tester.py +++ b/src/calibre/gui2/actions/show_template_tester.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' diff --git a/src/calibre/gui2/actions/similar_books.py b/src/calibre/gui2/actions/similar_books.py index 5febe5f51f..c355425c14 100644 --- a/src/calibre/gui2/actions/similar_books.py +++ b/src/calibre/gui2/actions/similar_books.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' diff --git a/src/calibre/gui2/actions/tweak_epub.py b/src/calibre/gui2/actions/tweak_epub.py index a0d9f1c0a2..970e0551f9 100644 --- a/src/calibre/gui2/actions/tweak_epub.py +++ b/src/calibre/gui2/actions/tweak_epub.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' diff --git a/src/calibre/gui2/actions/unpack_book.py b/src/calibre/gui2/actions/unpack_book.py index e666c1a108..ff0f577487 100644 --- a/src/calibre/gui2/actions/unpack_book.py +++ b/src/calibre/gui2/actions/unpack_book.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' diff --git a/src/calibre/gui2/actions/view.py b/src/calibre/gui2/actions/view.py index c5fcfbeaae..9bfdf925b7 100644 --- a/src/calibre/gui2/actions/view.py +++ b/src/calibre/gui2/actions/view.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' diff --git a/src/calibre/gui2/catalog/catalog_bibtex.py b/src/calibre/gui2/catalog/catalog_bibtex.py index 0e38160819..1bb607ae74 100644 --- a/src/calibre/gui2/catalog/catalog_bibtex.py +++ b/src/calibre/gui2/catalog/catalog_bibtex.py @@ -1,16 +1,17 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai -from __future__ import with_statement +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2009, Kovid Goyal ' __docformat__ = 'restructuredtext en' +from PyQt5.Qt import QWidget, QListWidgetItem + from calibre.gui2 import gprefs from calibre.gui2.catalog.catalog_bibtex_ui import Ui_Form from polyglot.builtins import unicode_type, range -from PyQt5.Qt import QWidget, QListWidgetItem class PluginWidget(QWidget, Ui_Form): diff --git a/src/calibre/gui2/catalog/catalog_csv_xml.py b/src/calibre/gui2/catalog/catalog_csv_xml.py index 03f6c16cc4..5e1a356b2b 100644 --- a/src/calibre/gui2/catalog/catalog_csv_xml.py +++ b/src/calibre/gui2/catalog/catalog_csv_xml.py @@ -1,15 +1,16 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai -from __future__ import with_statement +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2009, Kovid Goyal ' __docformat__ = 'restructuredtext en' +from PyQt5.Qt import QWidget, QListWidgetItem, Qt, QVBoxLayout, QLabel, QListWidget + from calibre.gui2 import gprefs from calibre.gui2.ui import get_gui from polyglot.builtins import unicode_type, range -from PyQt5.Qt import QWidget, QListWidgetItem, Qt, QVBoxLayout, QLabel, QListWidget def get_saved_field_data(name, all_fields): diff --git a/src/calibre/gui2/catalog/catalog_epub_mobi.py b/src/calibre/gui2/catalog/catalog_epub_mobi.py index 1b9c66f9ae..c303efc328 100644 --- a/src/calibre/gui2/catalog/catalog_epub_mobi.py +++ b/src/calibre/gui2/catalog/catalog_epub_mobi.py @@ -1,6 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai -from __future__ import print_function +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2009, Kovid Goyal ' @@ -15,7 +15,7 @@ from calibre.gui2 import gprefs, open_url, question_dialog, error_dialog from calibre.utils.config import JSONConfig from calibre.utils.icu import sort_key from calibre.utils.localization import localize_user_manual_link -from polyglot.builtins import unicode_type, zip, range +from polyglot.builtins import native_string_type, unicode_type, zip, range from .catalog_epub_mobi_ui import Ui_Form from PyQt5.Qt import (Qt, QAbstractItemView, QCheckBox, QComboBox, @@ -115,7 +115,7 @@ class PluginWidget(QWidget,Ui_Form): 'name':_('Wishlist item'), 'field':_('Tags'), 'pattern':'Wishlist', - 'prefix':u'\u00d7'},], + 'prefix':'\u00d7'},], ['table_widget','table_widget'])) self.OPTION_FIELDS = option_fields @@ -423,7 +423,7 @@ class PluginWidget(QWidget,Ui_Form): # Hook Preset signals self.preset_delete_pb.clicked.connect(self.preset_remove) self.preset_save_pb.clicked.connect(self.preset_save) - self.preset_field.currentIndexChanged[str].connect(self.preset_change) + self.preset_field.currentIndexChanged[native_string_type].connect(self.preset_change) self.blocking_all_signals = False @@ -1338,127 +1338,127 @@ class PrefixRules(GenericRulesTable): # Create a list of prefixes for user selection raw_prefix_list = [ - ('Ampersand',u'&'), - ('Angle left double',u'\u00ab'), - ('Angle left',u'\u2039'), - ('Angle right double',u'\u00bb'), - ('Angle right',u'\u203a'), - ('Arrow carriage return',u'\u21b5'), - ('Arrow double',u'\u2194'), - ('Arrow down',u'\u2193'), - ('Arrow left',u'\u2190'), - ('Arrow right',u'\u2192'), - ('Arrow up',u'\u2191'), - ('Asterisk',u'*'), - ('At sign',u'@'), - ('Bullet smallest',u'\u22c5'), - ('Bullet small',u'\u00b7'), - ('Bullet',u'\u2022'), - ('Cards clubs',u'\u2663'), - ('Cards diamonds',u'\u2666'), - ('Cards hearts',u'\u2665'), - ('Cards spades',u'\u2660'), - ('Caret',u'^'), - ('Checkmark',u'\u2713'), - ('Copyright circle c',u'\u00a9'), - ('Copyright circle r',u'\u00ae'), - ('Copyright trademark',u'\u2122'), - ('Currency cent',u'\u00a2'), - ('Currency dollar',u'$'), - ('Currency euro',u'\u20ac'), - ('Currency pound',u'\u00a3'), - ('Currency yen',u'\u00a5'), - ('Dagger double',u'\u2021'), - ('Dagger',u'\u2020'), - ('Degree',u'\u00b0'), - ('Dots3',u'\u2234'), - ('Hash',u'#'), - ('Infinity',u'\u221e'), - ('Lozenge',u'\u25ca'), - ('Math divide',u'\u00f7'), - ('Math empty',u'\u2205'), - ('Math equals',u'='), - ('Math minus',u'\u2212'), - ('Math plus circled',u'\u2295'), - ('Math times circled',u'\u2297'), - ('Math times',u'\u00d7'), - ('Paragraph',u'\u00b6'), - ('Percent',u'%'), - ('Plus-or-minus',u'\u00b1'), - ('Plus',u'+'), - ('Punctuation colon',u':'), - ('Punctuation colon-semi',u';'), - ('Punctuation exclamation',u'!'), - ('Punctuation question',u'?'), - ('Punctuation period',u'.'), - ('Punctuation slash back',u'\\'), - ('Punctuation slash forward',u'/'), - ('Section',u'\u00a7'), - ('Tilde',u'~'), - ('Vertical bar',u'|'), - ('Vertical bar broken',u'\u00a6'), - ('_0',u'0'), - ('_1',u'1'), - ('_2',u'2'), - ('_3',u'3'), - ('_4',u'4'), - ('_5',u'5'), - ('_6',u'6'), - ('_7',u'7'), - ('_8',u'8'), - ('_9',u'9'), - ('_A',u'A'), - ('_B',u'B'), - ('_C',u'C'), - ('_D',u'D'), - ('_E',u'E'), - ('_F',u'F'), - ('_G',u'G'), - ('_H',u'H'), - ('_I',u'I'), - ('_J',u'J'), - ('_K',u'K'), - ('_L',u'L'), - ('_M',u'M'), - ('_N',u'N'), - ('_O',u'O'), - ('_P',u'P'), - ('_Q',u'Q'), - ('_R',u'R'), - ('_S',u'S'), - ('_T',u'T'), - ('_U',u'U'), - ('_V',u'V'), - ('_W',u'W'), - ('_X',u'X'), - ('_Y',u'Y'), - ('_Z',u'Z'), - ('_a',u'a'), - ('_b',u'b'), - ('_c',u'c'), - ('_d',u'd'), - ('_e',u'e'), - ('_f',u'f'), - ('_g',u'g'), - ('_h',u'h'), - ('_i',u'i'), - ('_j',u'j'), - ('_k',u'k'), - ('_l',u'l'), - ('_m',u'm'), - ('_n',u'n'), - ('_o',u'o'), - ('_p',u'p'), - ('_q',u'q'), - ('_r',u'r'), - ('_s',u's'), - ('_t',u't'), - ('_u',u'u'), - ('_v',u'v'), - ('_w',u'w'), - ('_x',u'x'), - ('_y',u'y'), - ('_z',u'z'), + ('Ampersand', '&'), + ('Angle left double', '\u00ab'), + ('Angle left', '\u2039'), + ('Angle right double', '\u00bb'), + ('Angle right', '\u203a'), + ('Arrow carriage return', '\u21b5'), + ('Arrow double', '\u2194'), + ('Arrow down', '\u2193'), + ('Arrow left', '\u2190'), + ('Arrow right', '\u2192'), + ('Arrow up', '\u2191'), + ('Asterisk', '*'), + ('At sign', '@'), + ('Bullet smallest', '\u22c5'), + ('Bullet small', '\u00b7'), + ('Bullet', '\u2022'), + ('Cards clubs', '\u2663'), + ('Cards diamonds', '\u2666'), + ('Cards hearts', '\u2665'), + ('Cards spades', '\u2660'), + ('Caret', '^'), + ('Checkmark', '\u2713'), + ('Copyright circle c', '\u00a9'), + ('Copyright circle r', '\u00ae'), + ('Copyright trademark', '\u2122'), + ('Currency cent', '\u00a2'), + ('Currency dollar', '$'), + ('Currency euro', '\u20ac'), + ('Currency pound', '\u00a3'), + ('Currency yen', '\u00a5'), + ('Dagger double', '\u2021'), + ('Dagger', '\u2020'), + ('Degree', '\u00b0'), + ('Dots3', '\u2234'), + ('Hash', '#'), + ('Infinity', '\u221e'), + ('Lozenge', '\u25ca'), + ('Math divide', '\u00f7'), + ('Math empty', '\u2205'), + ('Math equals', '='), + ('Math minus', '\u2212'), + ('Math plus circled', '\u2295'), + ('Math times circled', '\u2297'), + ('Math times', '\u00d7'), + ('Paragraph', '\u00b6'), + ('Percent', '%'), + ('Plus-or-minus', '\u00b1'), + ('Plus', '+'), + ('Punctuation colon', ':'), + ('Punctuation colon-semi', ';'), + ('Punctuation exclamation', '!'), + ('Punctuation question', '?'), + ('Punctuation period', '.'), + ('Punctuation slash back', '\\'), + ('Punctuation slash forward', '/'), + ('Section', '\u00a7'), + ('Tilde', '~'), + ('Vertical bar', '|'), + ('Vertical bar broken', '\u00a6'), + ('_0', '0'), + ('_1', '1'), + ('_2', '2'), + ('_3', '3'), + ('_4', '4'), + ('_5', '5'), + ('_6', '6'), + ('_7', '7'), + ('_8', '8'), + ('_9', '9'), + ('_A', 'A'), + ('_B', 'B'), + ('_C', 'C'), + ('_D', 'D'), + ('_E', 'E'), + ('_F', 'F'), + ('_G', 'G'), + ('_H', 'H'), + ('_I', 'I'), + ('_J', 'J'), + ('_K', 'K'), + ('_L', 'L'), + ('_M', 'M'), + ('_N', 'N'), + ('_O', 'O'), + ('_P', 'P'), + ('_Q', 'Q'), + ('_R', 'R'), + ('_S', 'S'), + ('_T', 'T'), + ('_U', 'U'), + ('_V', 'V'), + ('_W', 'W'), + ('_X', 'X'), + ('_Y', 'Y'), + ('_Z', 'Z'), + ('_a', 'a'), + ('_b', 'b'), + ('_c', 'c'), + ('_d', 'd'), + ('_e', 'e'), + ('_f', 'f'), + ('_g', 'g'), + ('_h', 'h'), + ('_i', 'i'), + ('_j', 'j'), + ('_k', 'k'), + ('_l', 'l'), + ('_m', 'm'), + ('_n', 'n'), + ('_o', 'o'), + ('_p', 'p'), + ('_q', 'q'), + ('_r', 'r'), + ('_s', 's'), + ('_t', 't'), + ('_u', 'u'), + ('_v', 'v'), + ('_w', 'w'), + ('_x', 'x'), + ('_y', 'y'), + ('_z', 'z'), ] raw_prefix_list = sorted(raw_prefix_list, key=prefix_sorter) self.prefix_list = [x[1] for x in raw_prefix_list] diff --git a/src/calibre/gui2/comments_editor.py b/src/calibre/gui2/comments_editor.py index 0fffa212f0..f6e5229124 100644 --- a/src/calibre/gui2/comments_editor.py +++ b/src/calibre/gui2/comments_editor.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' @@ -338,7 +339,7 @@ class EditorWidget(QWebView, LineEditECM): # {{{ @property def html(self): - ans = u'' + ans = '' try: if not self.page().mainFrame().documentElement().findFirst('meta[name="calibre-dont-sanitize"]').isNull(): # Bypass cleanup if special meta tag exists @@ -364,9 +365,9 @@ class EditorWidget(QWebView, LineEditECM): # {{{ x.tag not in ('script', 'style')] if len(elems) > 1: - ans = u'
%s
'%(u''.join(elems)) + ans = '
%s
'%(''.join(elems)) else: - ans = u''.join(elems) + ans = ''.join(elems) if not ans.startswith('<'): ans = '

%s

'%ans ans = xml_replace_entities(ans) @@ -482,7 +483,7 @@ class Highlighter(QSyntaxHighlighter): if state == State_Comment: start = pos while pos < len_: - if text[pos:pos+3] == u"-->": + if text[pos:pos+3] == "-->": pos += 3 state = State_Text break @@ -495,7 +496,7 @@ class Highlighter(QSyntaxHighlighter): while pos < len_: ch = text[pos] pos += 1 - if ch == u'>': + if ch == '>': state = State_Text break self.setFormat(start, pos - start, self.colors['doctype']) @@ -506,7 +507,7 @@ class Highlighter(QSyntaxHighlighter): while pos < len_: ch = text[pos] pos += 1 - if ch == u'>': + if ch == '>': state = State_Text break if not ch.isspace(): @@ -524,7 +525,7 @@ class Highlighter(QSyntaxHighlighter): pos -= 1 state = State_InsideTag break - if ch == u'>': + if ch == '>': state = State_Text break self.setFormat(start, pos - start, self.colors['tag']) @@ -537,10 +538,10 @@ class Highlighter(QSyntaxHighlighter): ch = text[pos] pos += 1 - if ch == u'/': + if ch == '/': continue - if ch == u'>': + if ch == '>': state = State_Text break @@ -557,11 +558,11 @@ class Highlighter(QSyntaxHighlighter): ch = text[pos] pos += 1 - if ch == u'=': + if ch == '=': state = State_AttributeValue break - if ch in (u'>', u'/'): + if ch in ('>', '/'): state = State_InsideTag break @@ -577,12 +578,12 @@ class Highlighter(QSyntaxHighlighter): pos += 1 # handle opening single quote - if ch == u"'": + if ch == "'": state = State_SingleQuote break # handle opening double quote - if ch == u'"': + if ch == '"': state = State_DoubleQuote break @@ -597,7 +598,7 @@ class Highlighter(QSyntaxHighlighter): ch = text[pos] if ch.isspace(): break - if ch in (u'>', u'/'): + if ch in ('>', '/'): break pos += 1 state = State_InsideTag @@ -610,7 +611,7 @@ class Highlighter(QSyntaxHighlighter): while pos < len_: ch = text[pos] pos += 1 - if ch == u"'": + if ch == "'": break state = State_InsideTag @@ -624,7 +625,7 @@ class Highlighter(QSyntaxHighlighter): while pos < len_: ch = text[pos] pos += 1 - if ch == u'"': + if ch == '"': break state = State_InsideTag @@ -635,18 +636,18 @@ class Highlighter(QSyntaxHighlighter): # State_Text and default while pos < len_: ch = text[pos] - if ch == u'<': - if text[pos:pos+4] == u"