Finish the QVariant porting

This commit is contained in:
Kovid Goyal 2014-04-24 14:19:22 +05:30
parent e25696f16c
commit 53991dc588
10 changed files with 65 additions and 67 deletions

View File

@ -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}
# }}}

View File

@ -6,7 +6,7 @@ __license__ = 'GPL v3'
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
__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

View File

@ -66,7 +66,7 @@ class PageSetupWidget(Widget, Ui_Form):
self.opt_output_profile.setToolTip('<p>'+it.replace('t.','ce.\n<br>'))
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):

View File

@ -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:

View File

@ -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):

View File

@ -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

View File

@ -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))

View File

@ -6,9 +6,8 @@ __license__ = 'GPL 3'
__copyright__ = '2011, John Schember <john@nachtimwald.com>'
__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('<b>%s</b><br><i>%s</i>' % (result.name, result.description))
return ('<b>%s</b><br><i>%s</i>' % (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('<p>' + _('This store is currently disabled and cannot be used in other parts of calibre.') + '</p>')
return ('<p>' + _('This store is currently disabled and cannot be used in other parts of calibre.') + '</p>')
else:
return QVariant('<p>' + _('This store is currently enabled and can be used in other parts of calibre.') + '</p>')
return ('<p>' + _('This store is currently enabled and can be used in other parts of calibre.') + '</p>')
elif col == 1:
return QVariant('<p>%s</p>' % result.description)
return ('<p>%s</p>' % result.description)
elif col == 2:
if result.drm_free_only:
return QVariant('<p>' + _('This store only distributes ebooks without DRM.') + '</p>')
return ('<p>' + _('This store only distributes ebooks without DRM.') + '</p>')
else:
return QVariant('<p>' + _('This store distributes ebooks with DRM. It may have some titles without DRM, but you will need to check on a per title basis.') + '</p>')
return ('<p>' + _('This store distributes ebooks with DRM. It may have some titles without DRM, but you will need to check on a per title basis.') + '</p>')
elif col == 3:
return QVariant('<p>' + _('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 + '</p>')
return ('<p>' + _('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 + '</p>')
elif col == 4:
if result.affiliate:
return QVariant('<p>' + _('Buying from this store supports the calibre developer: %s.') % result.author + '</p>')
return ('<p>' + _('Buying from this store supports the calibre developer: %s.') % result.author + '</p>')
elif col == 5:
return QVariant('<p>' + _('This store distributes ebooks in the following formats: %s') % ', '.join(result.formats) + '</p>')
return NONE
return ('<p>' + _('This store distributes ebooks in the following formats: %s') % ', '.join(result.formats) + '</p>')
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))

View File

@ -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('<b>%s</b><br><i>%s</i>' % (t, a))
return ('<b>%s</b><br><i>%s</i>' % (t, a))
elif col == 2:
return QVariant(result.price)
return (result.price)
elif col == 4:
return QVariant('%s<br>%s' % (result.store_name, result.formats))
return NONE
return ('%s<br>%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('<p>%s</p>' % result.title)
return ('<p>%s</p>' % result.title)
elif col == 2:
return QVariant('<p>' + _('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 + '</p>') # noqa
return ('<p>' + _('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 + '</p>') # noqa
elif col == 3:
if result.drm == SearchResult.DRM_LOCKED:
return QVariant('<p>' + _('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.') + '</p>') # noqa
return ('<p>' + _('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.') + '</p>') # noqa
elif result.drm == SearchResult.DRM_UNLOCKED:
return QVariant('<p>' + _('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.') + '</p>') # noqa
return ('<p>' + _('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.') + '</p>') # noqa
else:
return QVariant('<p>' + _('The DRM status of this book could not be determined. There is a very high likelihood that this book is actually DRM restricted.') + '</p>') # noqa
return ('<p>' + _('The DRM status of this book could not be determined. There is a very high likelihood that this book is actually DRM restricted.') + '</p>') # noqa
elif col == 4:
return QVariant('<p>%s</p>' % result.formats)
return ('<p>%s</p>' % result.formats)
elif col == 5:
if result.downloads:
return QVariant('<p>' + _('The following formats can be downloaded directly: %s.') % ', '.join(result.downloads.keys()) + '</p>')
return ('<p>' + _('The following formats can be downloaded directly: %s.') % ', '.join(result.downloads.keys()) + '</p>')
elif col == 6:
if result.affiliate:
return QVariant('<p>' + _('Buying from this store supports the calibre developer: %s.') % result.plugin_author + '</p>')
return ('<p>' + _('Buying from this store supports the calibre developer: %s.') % result.plugin_author + '</p>')
elif role == Qt.SizeHintRole:
return QSize(64, 64)
return NONE
return None
def data_as_text(self, result, col):
text = ''

View File

@ -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)