diff --git a/setup/qt5-migrate.py b/setup/qt5-migrate.py index c5bb637113..7efd3530ab 100644 --- a/setup/qt5-migrate.py +++ b/setup/qt5-migrate.py @@ -48,7 +48,7 @@ def all_py_files(): def detect_qvariant(): count = 0 - pat = re.compile(b'|'.join(br'QVariant NONE toDateTime toDate toInt toBool toString\(\) toPyObject canConvert toBitArray toByteArray toHash toFloat toMap toLine toPoint toReal toRect toTime toUInt toUrl'.split())) # noqa + pat = re.compile(b'|'.join(br'QVariant NONE toDateTime toDate toInt toBool toString\(\) toPyObject canConvert toBitArray toByteArray toHash toFloat toMap toLine toPoint toReal toRect toTime\(\) toUInt toUrl'.split())) # noqa exclusions = { 'src/calibre/gui2/viewer/gestures.py': {'toPoint'}, 'src/calibre/utils/serve_coffee.py': {'toString()'}, diff --git a/src/calibre/gui2/toc/location.py b/src/calibre/gui2/toc/location.py index 245a3ca5ee..3f3a0c4ff9 100644 --- a/src/calibre/gui2/toc/location.py +++ b/src/calibre/gui2/toc/location.py @@ -88,8 +88,9 @@ class WebView(QWebView): # {{{ @property def scroll_frac(self): - val, ok = self.page().evaljs('window.pageYOffset/document.body.scrollHeight').toFloat() - if not ok: + try: + val = float(self.page().evaljs('window.pageYOffset/document.body.scrollHeight')) + except (TypeError, ValueError): val = 0 return val # }}} @@ -190,9 +191,9 @@ class ItemEdit(QWidget): _('No match found for: %s')%text, show=True) delta = 1 if forwards else -1 - current = unicode(d.currentItem().data(Qt.DisplayRole).toString()) + current = unicode(d.currentItem().data(Qt.DisplayRole) or '') next_index = (d.currentRow() + delta)%d.count() - next = unicode(d.item(next_index).data(Qt.DisplayRole).toString()) + next = unicode(d.item(next_index).data(Qt.DisplayRole) or '') msg = '

'+_('No matches for %(text)s found in the current file [%(current)s].' ' Do you want to search in the %(which)s file [%(next)s]?') msg = msg%dict(text=text, current=current, next=next, @@ -215,7 +216,7 @@ class ItemEdit(QWidget): self.dest_list.addItems(spine_names) def current_changed(self, item): - name = self.current_name = unicode(item.data(Qt.DisplayRole).toString()) + name = self.current_name = unicode(item.data(Qt.DisplayRole) or '') path = self.container.name_to_abspath(name) # Ensure encoding map is populated root = self.container.parsed(name) @@ -248,13 +249,13 @@ class ItemEdit(QWidget): dest_index, frag = 0, None if item is not None: if where is None: - self.name.setText(item.data(0, Qt.DisplayRole).toString()) + self.name.setText(item.data(0, Qt.DisplayRole) or '') self.name.setCursorPosition(0) - toc = item.data(0, Qt.UserRole).toPyObject() + toc = item.data(0, Qt.UserRole) if toc.dest: for i in xrange(self.dest_list.count()): litem = self.dest_list.item(i) - if unicode(litem.data(Qt.DisplayRole).toString()) == toc.dest: + if unicode(litem.data(Qt.DisplayRole) or '') == toc.dest: dest_index = i frag = toc.frag break diff --git a/src/calibre/gui2/toc/main.py b/src/calibre/gui2/toc/main.py index a3ba6852e2..c326be2b95 100644 --- a/src/calibre/gui2/toc/main.py +++ b/src/calibre/gui2/toc/main.py @@ -11,7 +11,7 @@ import sys, os, textwrap from threading import Thread from functools import partial -from PyQt5.Qt import (QPushButton, QFrame, QVariant, QMenu, QInputDialog, +from PyQt5.Qt import (QPushButton, QFrame, QMenu, QInputDialog, QDialog, QVBoxLayout, QDialogButtonBox, QSize, QStackedWidget, QWidget, QLabel, Qt, pyqtSignal, QIcon, QTreeWidget, QGridLayout, QTreeWidgetItem, QToolButton, QItemSelectionModel, QCursor, QKeySequence) @@ -330,12 +330,12 @@ class ItemView(QFrame): # {{{ def populate_item_pane(self): item = self.current_item - name = unicode(item.data(0, Qt.DisplayRole).toString()) + name = unicode(item.data(0, Qt.DisplayRole) or '') self.item_pane.heading.setText('

%s

'%name) self.icon_label.setPixmap(item.data(0, Qt.DecorationRole - ).toPyObject().pixmap(32, 32)) + ).pixmap(32, 32)) tt = _('This entry points to an existing destination') - toc = item.data(0, Qt.UserRole).toPyObject() + toc = item.data(0, Qt.UserRole) if toc.dest_exists is False: tt = _('The location this entry points to does not exist') elif toc.dest_exists is None: @@ -487,7 +487,7 @@ class TreeWidget(QTreeWidget): # {{{ def title_case(self): from calibre.utils.titlecase import titlecase for item in self.selectedItems(): - t = unicode(item.data(0, Qt.DisplayRole).toString()) + t = unicode(item.data(0, Qt.DisplayRole) or '') item.setData(0, Qt.DisplayRole, titlecase(t)) def bulk_rename(self): @@ -526,7 +526,7 @@ class TreeWidget(QTreeWidget): # {{{ if item is not None: m = QMenu() - ci = unicode(item.data(0, Qt.DisplayRole).toString()) + ci = unicode(item.data(0, Qt.DisplayRole) or '') p = item.parent() or self.invisibleRootItem() idx = p.indexOfChild(item) if idx > 0: @@ -622,7 +622,7 @@ class TOCView(QWidget): # {{{ return super(TOCView, self).event(e) def item_title(self, item): - return unicode(item.data(0, Qt.DisplayRole).toString()) + return unicode(item.data(0, Qt.DisplayRole) or '') def del_items(self): self.tocw.del_items() @@ -672,7 +672,7 @@ class TOCView(QWidget): # {{{ self.tocw.move_down() def update_status_tip(self, item): - c = item.data(0, Qt.UserRole).toPyObject() + c = item.data(0, Qt.UserRole) if c is not None: frag = c.frag or '' if frag: @@ -683,8 +683,8 @@ class TOCView(QWidget): # {{{ def data_changed(self, top_left, bottom_right): for r in xrange(top_left.row(), bottom_right.row()+1): idx = self.tocw.model().index(r, 0, top_left.parent()) - new_title = unicode(idx.data(Qt.DisplayRole).toString()).strip() - toc = idx.data(Qt.UserRole).toPyObject() + new_title = unicode(idx.data(Qt.DisplayRole) or '').strip() + toc = idx.data(Qt.UserRole) if toc is not None: toc.title = new_title or _('(Untitled)') item = self.tocw.itemFromIndex(idx) @@ -711,7 +711,7 @@ class TOCView(QWidget): # {{{ 'The location this entry point to does not exist:\n%s') %child.dest_error) else: - c.setData(0, Qt.ToolTipRole, QVariant()) + c.setData(0, Qt.ToolTipRole, None) self.update_status_tip(c) @@ -774,8 +774,8 @@ class TOCView(QWidget): # {{{ def process_node(parent, toc_parent): for i in xrange(parent.childCount()): item = parent.child(i) - title = unicode(item.data(0, Qt.DisplayRole).toString()).strip() - toc = item.data(0, Qt.UserRole).toPyObject() + title = unicode(item.data(0, Qt.DisplayRole) or '').strip() + toc = item.data(0, Qt.UserRole) dest, frag = toc.dest, toc.frag toc = toc_parent.add(title, dest, frag) process_node(item, toc) diff --git a/src/calibre/web/fetch/javascript.py b/src/calibre/web/fetch/javascript.py index d7dfcf0a6a..71de02de83 100644 --- a/src/calibre/web/fetch/javascript.py +++ b/src/calibre/web/fetch/javascript.py @@ -101,14 +101,14 @@ def download_resources(browser, resource_cache, output_dir): for img in browser.css_select('img[src]', all=True): # Using javascript ensures that absolute URLs are returned, direct # attribute access does not do that - src = unicode(img.evaluateJavaScript('this.src').toString()).strip() + src = unicode(img.evaluateJavaScript('this.src') or '').strip() if src: resources[src].append(img) for link in browser.css_select('link[href]', all=True): lt = unicode(link.attribute('type')).strip() or 'text/css' rel = unicode(link.attribute('rel')).strip() or 'stylesheet' if lt == 'text/css' and rel == 'stylesheet': - href = unicode(link.evaluateJavaScript('this.href').toString()).strip() + href = unicode(link.evaluateJavaScript('this.href') or '').strip() if href: resources[href].append(link) else: @@ -165,7 +165,7 @@ def links_from_selectors(selectors, recursions, browser, url, recursion_level): if recursions > recursion_level: for selector in selectors: for a in browser.css_select(selector, all=True): - href = unicode(a.evaluateJavaScript('this.href').toString()).strip() + href = unicode(a.evaluateJavaScript('this.href') or '').strip() if href: ans.append(href) return ans diff --git a/src/calibre/web/jsbrowser/browser.py b/src/calibre/web/jsbrowser/browser.py index e6e1b73cbc..c58580cc56 100644 --- a/src/calibre/web/jsbrowser/browser.py +++ b/src/calibre/web/jsbrowser/browser.py @@ -125,7 +125,7 @@ class WebPage(QWebPage): # {{{ @property def ready_state(self): - return unicode(self.mainFrame().evaluateJavaScript('document.readyState').toString()) + return unicode(self.mainFrame().evaluateJavaScript('document.readyState') or '') @pyqtSlot(QPixmap) def transfer_image(self, img): @@ -210,7 +210,7 @@ class NetworkAccessManager(QNetworkAccessManager): # {{{ reply.ignoreSslErrors() def createRequest(self, operation, request, data): - url = unicode(request.url().toString()) + url = unicode(request.url().toString(QUrl.None)) operation_name = self.OPERATION_NAMES[operation] debug = [] debug.append(('Request: %s %s' % (operation_name, url))) @@ -245,7 +245,7 @@ class NetworkAccessManager(QNetworkAccessManager): # {{{ self.report_reply(reply) def report_reply(self, reply): - reply_url = unicode(reply.url().toString()) + reply_url = unicode(reply.url().toString(QUrl.None)) self.reply_count += 1 err = reply.error()