From 53991dc588d5e51cc8d5f3cb7f12eb2013989660 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 24 Apr 2014 14:19:22 +0530 Subject: [PATCH] Finish the QVariant porting --- src/calibre/gui2/actions/copy_to_library.py | 2 +- src/calibre/gui2/convert/look_and_feel.py | 8 +-- src/calibre/gui2/convert/page_setup.py | 2 +- src/calibre/gui2/convert/txt_input.py | 2 +- .../gui2/device_drivers/configwidget.py | 7 ++- src/calibre/gui2/device_drivers/mtp_config.py | 8 +-- .../gui2/device_drivers/mtp_folder_browser.py | 4 +- .../gui2/store/config/chooser/models.py | 45 ++++++++--------- src/calibre/gui2/store/search/models.py | 50 +++++++++---------- src/calibre/gui2/store/web_control.py | 4 +- 10 files changed, 65 insertions(+), 67 deletions(-) diff --git a/src/calibre/gui2/actions/copy_to_library.py b/src/calibre/gui2/actions/copy_to_library.py index 02ab493826..c42e4b225c 100644 --- a/src/calibre/gui2/actions/copy_to_library.py +++ b/src/calibre/gui2/actions/copy_to_library.py @@ -304,7 +304,7 @@ class DuplicatesQuestion(QDialog): # {{{ @property def ids(self): - return {i.data(Qt.UserRole).toInt()[0] for i in self.items if i.checkState() == Qt.Checked} + return {int(i.data(Qt.UserRole)) for i in self.items if i.checkState() == Qt.Checked} # }}} diff --git a/src/calibre/gui2/convert/look_and_feel.py b/src/calibre/gui2/convert/look_and_feel.py index 2b1b64354e..2095d39a96 100644 --- a/src/calibre/gui2/convert/look_and_feel.py +++ b/src/calibre/gui2/convert/look_and_feel.py @@ -6,7 +6,7 @@ __license__ = 'GPL v3' __copyright__ = '2009, Kovid Goyal ' __docformat__ = 'restructuredtext en' -from PyQt5.Qt import QVariant, Qt +from PyQt5.Qt import Qt from calibre.gui2.convert.look_and_feel_ui import Ui_Form from calibre.gui2.convert import Widget @@ -47,7 +47,7 @@ class LookAndFeelWidget(Widget, Ui_Form): ('left', _('Left align')), ('justify', _('Justify text')) ]: - self.opt_change_justification.addItem(text, QVariant(val)) + self.opt_change_justification.addItem(text, (val)) self.db, self.book_id = db, book_id self.initialize_options(get_option, get_help, db, book_id) self.opt_disable_font_rescaling.toggle() @@ -64,7 +64,7 @@ class LookAndFeelWidget(Widget, Ui_Form): def get_value_handler(self, g): if g is self.opt_change_justification: - ans = unicode(g.itemData(g.currentIndex()).toString()) + ans = unicode(g.itemData(g.currentIndex()) or '') return ans if g is self.opt_filter_css: ans = set() @@ -84,7 +84,7 @@ class LookAndFeelWidget(Widget, Ui_Form): def set_value_handler(self, g, val): if g is self.opt_change_justification: for i in range(g.count()): - c = unicode(g.itemData(i).toString()) + c = unicode(g.itemData(i) or '') if val == c: g.setCurrentIndex(i) break diff --git a/src/calibre/gui2/convert/page_setup.py b/src/calibre/gui2/convert/page_setup.py index c0812e8e8e..ccbd8486f0 100644 --- a/src/calibre/gui2/convert/page_setup.py +++ b/src/calibre/gui2/convert/page_setup.py @@ -66,7 +66,7 @@ class PageSetupWidget(Widget, Ui_Form): self.opt_output_profile.setToolTip('

'+it.replace('t.','ce.\n
')) def show_desc(self, index): - desc = index.model().data(index, Qt.StatusTipRole).toString() + desc = unicode(index.model().data(index, Qt.StatusTipRole) or '') self.profile_description.setText(desc) def connect_gui_obj_handler(self, g, slot): diff --git a/src/calibre/gui2/convert/txt_input.py b/src/calibre/gui2/convert/txt_input.py index e84e3099a1..c8793e7029 100644 --- a/src/calibre/gui2/convert/txt_input.py +++ b/src/calibre/gui2/convert/txt_input.py @@ -52,7 +52,7 @@ class PluginWidget(Widget, Ui_Form): def get_value_handler(self, g): if g is not self.opt_markdown_extensions: return Widget.get_value_handler(self, g) - return ', '.join(unicode(i.data(Qt.UserRole).toString()) for i in self.md_map.itervalues() if i.checkState()) + return ', '.join(unicode(i.data(Qt.UserRole) or '') for i in self.md_map.itervalues() if i.checkState()) def connect_gui_obj_handler(self, g, f): if g is not self.opt_markdown_extensions: diff --git a/src/calibre/gui2/device_drivers/configwidget.py b/src/calibre/gui2/device_drivers/configwidget.py index 875c4c2b65..4ddafd8682 100644 --- a/src/calibre/gui2/device_drivers/configwidget.py +++ b/src/calibre/gui2/device_drivers/configwidget.py @@ -6,7 +6,7 @@ __docformat__ = 'restructuredtext en' import textwrap -from PyQt5.Qt import (QWidget, QListWidgetItem, Qt, QVariant, QLabel, +from PyQt5.Qt import (QWidget, QListWidgetItem, Qt, QLabel, QLineEdit, QCheckBox, QComboBox) from calibre.gui2 import error_dialog, question_dialog @@ -39,7 +39,7 @@ class ConfigWidget(QWidget, Ui_ConfigWidget): disabled_formats = list(set(all_formats).difference(format_map)) for format in format_map + list(sorted(disabled_formats)): item = QListWidgetItem(format, self.columns) - item.setData(Qt.UserRole, QVariant(format)) + item.setData(Qt.UserRole, (format)) item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsUserCheckable|Qt.ItemIsSelectable) item.setCheckState(Qt.Checked if format in format_map else Qt.Unchecked) @@ -133,8 +133,7 @@ class ConfigWidget(QWidget, Ui_ConfigWidget): self.columns.setCurrentRow(idx+1) def format_map(self): - formats = [unicode(self.columns.item(i).data(Qt.UserRole).toString()) - for i in range(self.columns.count()) if self.columns.item(i).checkState()==Qt.Checked] + formats = [unicode(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 def use_subdirs(self): diff --git a/src/calibre/gui2/device_drivers/mtp_config.py b/src/calibre/gui2/device_drivers/mtp_config.py index 9f4391f7b8..76bcedddeb 100644 --- a/src/calibre/gui2/device_drivers/mtp_config.py +++ b/src/calibre/gui2/device_drivers/mtp_config.py @@ -49,7 +49,7 @@ class FormatsConfig(QWidget): # {{{ @property def format_map(self): - return [unicode(self.f.item(i).data(Qt.UserRole).toString()) for i in + return [unicode(self.f.item(i).data(Qt.UserRole) or '') for i in xrange(self.f.count()) if self.f.item(i).checkState()==Qt.Checked] def validate(self): @@ -183,13 +183,13 @@ class IgnoredDevices(QWidget): # {{{ @property def blacklist(self): - return [unicode(self.f.item(i).data(Qt.UserRole).toString()) for i in + return [unicode(self.f.item(i).data(Qt.UserRole) or '') for i in xrange(self.f.count()) if self.f.item(i).checkState()==Qt.Checked] def ignore_device(self, snum): for i in xrange(self.f.count()): i = self.f.item(i) - c = unicode(i.data(Qt.UserRole).toString()) + c = unicode(i.data(Qt.UserRole) or '') if c == snum: i.setCheckState(Qt.Checked) break @@ -262,7 +262,7 @@ class Rule(QWidget): folder = unicode(self.folder.text()).strip() if folder: return ( - unicode(self.fmt.itemData(self.fmt.currentIndex()).toString()), + unicode(self.fmt.itemData(self.fmt.currentIndex()) or ''), folder ) return None diff --git a/src/calibre/gui2/device_drivers/mtp_folder_browser.py b/src/calibre/gui2/device_drivers/mtp_folder_browser.py index e687960914..467fe38fe0 100644 --- a/src/calibre/gui2/device_drivers/mtp_folder_browser.py +++ b/src/calibre/gui2/device_drivers/mtp_folder_browser.py @@ -53,7 +53,7 @@ class Storage(QTreeWidget): def current_item(self): item = self.currentItem() if item is not None: - return (self.object_id, item.data(0, Qt.UserRole).toPyObject()) + return (self.object_id, item.data(0, Qt.UserRole)) return None class Folders(QTabWidget): @@ -195,7 +195,7 @@ class IgnoredFolders(QDialog): for node in self.iterchildren(w.invisibleRootItem()): if node.checkState(0) == Qt.Checked: continue - path = unicode(node.data(0, Qt.UserRole).toString()) + path = unicode(node.data(0, Qt.UserRole) or '') parent = path.rpartition('/')[0] if '/' not in path or icu_lower(parent) not in folders: folders.add(icu_lower(path)) diff --git a/src/calibre/gui2/store/config/chooser/models.py b/src/calibre/gui2/store/config/chooser/models.py index 5d8c7315c9..7d28f18fb1 100644 --- a/src/calibre/gui2/store/config/chooser/models.py +++ b/src/calibre/gui2/store/config/chooser/models.py @@ -6,9 +6,8 @@ __license__ = 'GPL 3' __copyright__ = '2011, John Schember ' __docformat__ = 'restructuredtext en' -from PyQt5.Qt import (Qt, QAbstractItemModel, QIcon, QVariant, QModelIndex, QSize) +from PyQt5.Qt import (Qt, QAbstractItemModel, QIcon, QModelIndex, QSize) -from calibre.gui2 import NONE from calibre.customize.ui import is_disabled, disable_plugin, enable_plugin from calibre.db.search import _match, CONTAINS_MATCH, EQUALS_MATCH, REGEXP_MATCH from calibre.utils.config_base import prefs @@ -58,13 +57,13 @@ class Matches(QAbstractItemModel): def enable_all(self): for i in xrange(len(self.matches)): index = self.createIndex(i, 0) - data = QVariant(True) + data = (True) self.setData(index, data, Qt.CheckStateRole) def enable_none(self): for i in xrange(len(self.matches)): index = self.createIndex(i, 0) - data = QVariant(False) + data = (False) self.setData(index, data, Qt.CheckStateRole) def enable_invert(self): @@ -73,7 +72,7 @@ class Matches(QAbstractItemModel): def toggle_plugin(self, index): new_index = self.createIndex(index.row(), 0) - data = QVariant(is_disabled(self.get_plugin(index))) + data = (is_disabled(self.get_plugin(index))) self.setData(new_index, data, Qt.CheckStateRole) def index(self, row, column, parent=QModelIndex()): @@ -92,32 +91,32 @@ class Matches(QAbstractItemModel): def headerData(self, section, orientation, role): if role != Qt.DisplayRole: - return NONE + return None text = '' if orientation == Qt.Horizontal: if section < len(self.HEADERS): text = self.HEADERS[section] - return QVariant(text) + return (text) else: - return QVariant(section+1) + return (section+1) def data(self, index, role): row, col = index.row(), index.column() result = self.matches[row] if role in (Qt.DisplayRole, Qt.EditRole): if col == 1: - return QVariant('%s
%s' % (result.name, result.description)) + return ('%s
%s' % (result.name, result.description)) elif col == 3: - return QVariant(result.headquarters) + return (result.headquarters) elif col == 5: - return QVariant(', '.join(result.formats).upper()) + return (', '.join(result.formats).upper()) elif role == Qt.DecorationRole: if col == 2: if result.drm_free_only: - return QVariant(self.NO_DRM_ICON) + return (self.NO_DRM_ICON) if col == 4: if result.affiliate: - return QVariant(self.DONATE_ICON) + return (self.DONATE_ICON) elif role == Qt.CheckStateRole: if col == 0: if is_disabled(result): @@ -126,31 +125,31 @@ class Matches(QAbstractItemModel): elif role == Qt.ToolTipRole: if col == 0: if is_disabled(result): - return QVariant('

' + _('This store is currently disabled and cannot be used in other parts of calibre.') + '

') + return ('

' + _('This store is currently disabled and cannot be used in other parts of calibre.') + '

') else: - return QVariant('

' + _('This store is currently enabled and can be used in other parts of calibre.') + '

') + return ('

' + _('This store is currently enabled and can be used in other parts of calibre.') + '

') elif col == 1: - return QVariant('

%s

' % result.description) + return ('

%s

' % result.description) elif col == 2: if result.drm_free_only: - return QVariant('

' + _('This store only distributes ebooks without DRM.') + '

') + return ('

' + _('This store only distributes ebooks without DRM.') + '

') else: - return QVariant('

' + _('This store distributes ebooks with DRM. It may have some titles without DRM, but you will need to check on a per title basis.') + '

') + return ('

' + _('This store distributes ebooks with DRM. It may have some titles without DRM, but you will need to check on a per title basis.') + '

') elif col == 3: - return QVariant('

' + _('This store is headquartered in %s. This is a good indication of what market the store caters to. However, this does not necessarily mean that the store is limited to that market only.') % result.headquarters + '

') + return ('

' + _('This store is headquartered in %s. This is a good indication of what market the store caters to. However, this does not necessarily mean that the store is limited to that market only.') % result.headquarters + '

') elif col == 4: if result.affiliate: - return QVariant('

' + _('Buying from this store supports the calibre developer: %s.') % result.author + '

') + return ('

' + _('Buying from this store supports the calibre developer: %s.') % result.author + '

') elif col == 5: - return QVariant('

' + _('This store distributes ebooks in the following formats: %s') % ', '.join(result.formats) + '

') - return NONE + return ('

' + _('This store distributes ebooks in the following formats: %s') % ', '.join(result.formats) + '

') + return None def setData(self, index, data, role): if not index.isValid(): return False col = index.column() if col == 0: - if data.toBool(): + if bool(data): enable_plugin(self.get_plugin(index)) else: disable_plugin(self.get_plugin(index)) diff --git a/src/calibre/gui2/store/search/models.py b/src/calibre/gui2/store/search/models.py index f0aa1ac5d0..b98edec887 100644 --- a/src/calibre/gui2/store/search/models.py +++ b/src/calibre/gui2/store/search/models.py @@ -9,10 +9,10 @@ __docformat__ = 'restructuredtext en' import re, string from operator import attrgetter -from PyQt5.Qt import (Qt, QAbstractItemModel, QVariant, QPixmap, QModelIndex, QSize, +from PyQt5.Qt import (Qt, QAbstractItemModel, QPixmap, QModelIndex, QSize, pyqtSignal) -from calibre.gui2 import NONE, FunctionDispatcher +from calibre.gui2 import FunctionDispatcher from calibre.gui2.store.search_result import SearchResult from calibre.gui2.store.search.download_thread import DetailsThreadPool, \ CoverThreadPool @@ -183,71 +183,71 @@ class Matches(QAbstractItemModel): def headerData(self, section, orientation, role): if role != Qt.DisplayRole: - return NONE + return None text = '' if orientation == Qt.Horizontal: if section < len(self.HEADERS): text = self.HEADERS[section] - return QVariant(text) + return (text) else: - return QVariant(section+1) + return (section+1) def data(self, index, role): row, col = index.row(), index.column() if row >= len(self.matches): - return NONE + return None result = self.matches[row] if role == Qt.DisplayRole: if col == 1: t = result.title if result.title else _('Unknown') a = result.author if result.author else '' - return QVariant('%s
%s' % (t, a)) + return ('%s
%s' % (t, a)) elif col == 2: - return QVariant(result.price) + return (result.price) elif col == 4: - return QVariant('%s
%s' % (result.store_name, result.formats)) - return NONE + return ('%s
%s' % (result.store_name, result.formats)) + return None elif role == Qt.DecorationRole: if col == 0 and result.cover_data: p = QPixmap() p.loadFromData(result.cover_data) - return QVariant(p) + return (p) if col == 3: if result.drm == SearchResult.DRM_LOCKED: - return QVariant(self.DRM_LOCKED_ICON) + return (self.DRM_LOCKED_ICON) elif result.drm == SearchResult.DRM_UNLOCKED: - return QVariant(self.DRM_UNLOCKED_ICON) + return (self.DRM_UNLOCKED_ICON) elif result.drm == SearchResult.DRM_UNKNOWN: - return QVariant(self.DRM_UNKNOWN_ICON) + return (self.DRM_UNKNOWN_ICON) if col == 5: if result.downloads: - return QVariant(self.DOWNLOAD_ICON) + return (self.DOWNLOAD_ICON) if col == 6: if result.affiliate: - return QVariant(self.DONATE_ICON) + return (self.DONATE_ICON) elif role == Qt.ToolTipRole: if col == 1: - return QVariant('

%s

' % result.title) + return ('

%s

' % result.title) elif col == 2: - return QVariant('

' + _('Detected price as: %s. Check with the store before making a purchase to verify this price is correct. This price often does not include promotions the store may be running.') % result.price + '

') # noqa + return ('

' + _('Detected price as: %s. Check with the store before making a purchase to verify this price is correct. This price often does not include promotions the store may be running.') % result.price + '

') # noqa elif col == 3: if result.drm == SearchResult.DRM_LOCKED: - return QVariant('

' + _('This book as been detected as having DRM restrictions. This book may not work with your reader and you will have limitations placed upon you as to what you can do with this book. Check with the store before making any purchases to ensure you can actually read this book.') + '

') # noqa + return ('

' + _('This book as been detected as having DRM restrictions. This book may not work with your reader and you will have limitations placed upon you as to what you can do with this book. Check with the store before making any purchases to ensure you can actually read this book.') + '

') # noqa elif result.drm == SearchResult.DRM_UNLOCKED: - return QVariant('

' + _('This book has been detected as being DRM Free. You should be able to use this book on any device provided it is in a format calibre supports for conversion. However, before making a purchase double check the DRM status with the store. The store may not be disclosing the use of DRM.') + '

') # noqa + return ('

' + _('This book has been detected as being DRM Free. You should be able to use this book on any device provided it is in a format calibre supports for conversion. However, before making a purchase double check the DRM status with the store. The store may not be disclosing the use of DRM.') + '

') # noqa else: - return QVariant('

' + _('The DRM status of this book could not be determined. There is a very high likelihood that this book is actually DRM restricted.') + '

') # noqa + return ('

' + _('The DRM status of this book could not be determined. There is a very high likelihood that this book is actually DRM restricted.') + '

') # noqa elif col == 4: - return QVariant('

%s

' % result.formats) + return ('

%s

' % result.formats) elif col == 5: if result.downloads: - return QVariant('

' + _('The following formats can be downloaded directly: %s.') % ', '.join(result.downloads.keys()) + '

') + return ('

' + _('The following formats can be downloaded directly: %s.') % ', '.join(result.downloads.keys()) + '

') elif col == 6: if result.affiliate: - return QVariant('

' + _('Buying from this store supports the calibre developer: %s.') % result.plugin_author + '

') + return ('

' + _('Buying from this store supports the calibre developer: %s.') % result.plugin_author + '

') elif role == Qt.SizeHintRole: return QSize(64, 64) - return NONE + return None def data_as_text(self, result, col): text = '' diff --git a/src/calibre/gui2/store/web_control.py b/src/calibre/gui2/store/web_control.py index acb9824bc2..c2f38f2bd4 100644 --- a/src/calibre/gui2/store/web_control.py +++ b/src/calibre/gui2/store/web_control.py @@ -9,7 +9,7 @@ __docformat__ = 'restructuredtext en' import os from urlparse import urlparse -from PyQt5.Qt import QNetworkCookieJar, QNetworkProxy +from PyQt5.Qt import QNetworkCookieJar, QNetworkProxy, QUrl from PyQt5.QtWebKitWidgets import QWebView, QWebPage from calibre import USER_AGENT, get_proxies, get_download_filename @@ -66,7 +66,7 @@ class NPWebView(QWebView): if not self.gui: return - url = unicode(request.url().toString()) + url = unicode(request.url().toString(QUrl.None)) cf = self.get_cookies() filename = get_download_filename(url, cf)