Port usage of QString and various miscellaneous imports that no longer work

This commit is contained in:
Kovid Goyal 2014-04-20 13:28:04 +05:30
parent 04e342c072
commit 098f178dfc
21 changed files with 68 additions and 76 deletions

View File

@ -18,6 +18,8 @@ __copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>'
# them to check that they work. This can probably be made part of python
# setup.py check.
# QT5XX: Check that DeviceCategoryEditor and TagListEditor work
# QT5XX: Delete this file after migration is completed
import os

View File

@ -12,7 +12,7 @@ from urllib import unquote
from collections import defaultdict
from cssutils import CSSParser
from PyQt5.Qt import (pyqtProperty, QString, QEventLoop, Qt, QSize, QTimer,
from PyQt5.Qt import (pyqtProperty, QEventLoop, Qt, QSize, QTimer,
pyqtSlot)
from PyQt5.QtWebKitWidgets import QWebPage, QWebView
@ -130,14 +130,14 @@ class Page(QWebPage): # {{{
def _pass_json_value_getter(self):
val = json.dumps(self.bridge_value)
return QString(val)
return val
def _pass_json_value_setter(self, value):
# Qt WebKit in Qt 4.x adds extra null bytes to the end of the string
# if the JSON contains non-BMP characters
self.bridge_value = json.loads(unicode(value).rstrip('\0'))
_pass_json_value = pyqtProperty(QString, fget=_pass_json_value_getter,
_pass_json_value = pyqtProperty(str, fget=_pass_json_value_getter,
fset=_pass_json_value_setter)
def load_js(self):

View File

@ -12,8 +12,8 @@ from future_builtins import map
from math import floor
from collections import defaultdict
from PyQt5.Qt import (QObject, QPainter, Qt, QSize, QString, QTimer,
pyqtProperty, QEventLoop, QPixmap, QRect, pyqtSlot)
from PyQt5.Qt import (
QObject, QPainter, Qt, QSize, QTimer, pyqtProperty, QEventLoop, QPixmap, QRect, pyqtSlot)
from PyQt5.QtWebKit import QWebSettings
from PyQt5.QtWebKitWidgets import QWebView, QWebPage
@ -125,12 +125,12 @@ class PDFWriter(QObject):
def _pass_json_value_getter(self):
val = json.dumps(self.bridge_value)
return QString(val)
return val
def _pass_json_value_setter(self, value):
self.bridge_value = json.loads(unicode(value))
_pass_json_value = pyqtProperty(QString, fget=_pass_json_value_getter,
_pass_json_value = pyqtProperty(str, fget=_pass_json_value_getter,
fset=_pass_json_value_setter)
@pyqtSlot(result=unicode)

View File

@ -11,7 +11,7 @@ Write content to PDF.
import os, shutil, json
from PyQt5.Qt import (QEventLoop, QObject, QPrinter, QSizeF, Qt, QPainter,
QPixmap, QTimer, pyqtProperty, QString, QSize)
QPixmap, QTimer, pyqtProperty, QSize)
from PyQt5.QtWebKit import QWebSettings
from PyQt5.QtWebKitWidgets import QWebView, QWebPage
@ -221,12 +221,12 @@ class PDFWriter(QObject): # {{{
def _pass_json_value_getter(self):
val = json.dumps(self.bridge_value)
return QString(val)
return val
def _pass_json_value_setter(self, value):
self.bridge_value = json.loads(unicode(value))
_pass_json_value = pyqtProperty(QString, fget=_pass_json_value_getter,
_pass_json_value = pyqtProperty(str, fget=_pass_json_value_getter,
fset=_pass_json_value_setter)
def setup_printer(self, outpath):

View File

@ -6,7 +6,7 @@ __docformat__ = 'restructuredtext en'
import shutil
from PyQt5.Qt import QString, QModelIndex
from PyQt5.Qt import QModelIndex
from calibre.gui2.convert.single import (Config, sort_formats_by_preference,
GroupModel, gprefs, get_output_formats)
@ -120,7 +120,7 @@ class BulkConfig(Config):
preferred_output_format and preferred_output_format \
in output_formats else sort_formats_by_preference(output_formats,
[prefs['output_format']])[0]
self.output_formats.addItems(list(map(QString, [x.upper() for x in
self.output_formats.addItems(list(map(unicode, [x.upper() for x in
output_formats])))
self.output_formats.setCurrentIndex(output_formats.index(preferred_output_format))

View File

@ -8,7 +8,7 @@ __docformat__ = 'restructuredtext en'
import cPickle, shutil
from PyQt5.Qt import QString, QAbstractListModel, Qt, QVariant, QFont, QModelIndex
from PyQt5.Qt import QAbstractListModel, Qt, QVariant, QFont, QModelIndex
from calibre.gui2 import ResizableDialog, NONE, gprefs
from calibre.ebooks.conversion.config import (GuiRecommendations, save_specifics,
@ -254,9 +254,9 @@ class Config(ResizableDialog, Ui_Dialog):
preferred_output_format in output_formats else \
sort_formats_by_preference(output_formats,
[prefs['output_format']])[0]
self.input_formats.addItems(list(map(QString, [x.upper() for x in
self.input_formats.addItems(list(map(unicode, [x.upper() for x in
input_formats])))
self.output_formats.addItems(list(map(QString, [x.upper() for x in
self.output_formats.addItems(list(map(unicode, [x.upper() for x in
output_formats])))
self.input_formats.setCurrentIndex(input_formats.index(input_format))
self.output_formats.setCurrentIndex(output_formats.index(preferred_output_format))

View File

@ -1,6 +1,7 @@
__license__ = 'GPL v3'
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
from PyQt5.QtGui import QDialog
from PyQt5.Qt import QDialog
from calibre.gui2.dialogs.conversion_error_ui import Ui_ConversionErrorDialog

View File

@ -1,8 +1,7 @@
__license__ = 'GPL v3'
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
from PyQt5.QtCore import Qt, QString
from PyQt5.QtGui import QDialog, QListWidgetItem
from PyQt5.Qt import Qt, QDialog, QListWidgetItem
from calibre.gui2.dialogs.device_category_editor_ui import Ui_DeviceCategoryEditor
from calibre.gui2 import question_dialog, error_dialog
@ -11,9 +10,9 @@ class ListWidgetItem(QListWidgetItem):
def __init__(self, txt):
QListWidgetItem.__init__(self, txt)
self.initial_value = QString(txt)
self.current_value = QString(txt)
self.previous_value = QString(txt)
self.initial_value = txt
self.current_value = txt
self.previous_value = txt
def data(self, role):
if role == Qt.DisplayRole:
@ -30,7 +29,7 @@ class ListWidgetItem(QListWidgetItem):
def setData(self, role, data):
if role == Qt.EditRole:
self.previous_value = self.current_value
self.current_value = data.toString()
self.current_value = data
QListWidgetItem.setData(self, role, data)
def text(self):

View File

@ -3,7 +3,7 @@ __license__ = 'GPL v3'
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
from PyQt5.QtGui import QDialog
from PyQt5.Qt import QDialog
from calibre.gui2.dialogs.saved_search_editor_ui import Ui_SavedSearchEditor
from calibre.utils.icu import sort_key

View File

@ -1,8 +1,7 @@
__license__ = 'GPL v3'
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
from PyQt5.Qt import (Qt, QDialog, QTableWidgetItem, QIcon, QByteArray,
QString, QSize)
from PyQt5.Qt import (Qt, QDialog, QTableWidgetItem, QIcon, QByteArray, QSize)
from calibre.gui2.dialogs.tag_list_editor_ui import Ui_TagListEditor
from calibre.gui2 import question_dialog, error_dialog, info_dialog, gprefs
@ -12,9 +11,9 @@ class NameTableWidgetItem(QTableWidgetItem):
def __init__(self, txt):
QTableWidgetItem.__init__(self, txt)
self.initial_value = QString(txt)
self.current_value = QString(txt)
self.previous_value = QString(txt)
self.initial_value = txt
self.current_value = txt
self.previous_value = txt
def data(self, role):
if role == Qt.DisplayRole:
@ -27,7 +26,7 @@ class NameTableWidgetItem(QTableWidgetItem):
def setData(self, role, data):
if role == Qt.EditRole:
self.previous_value = self.current_value
self.current_value = data.toString()
self.current_value = data
QTableWidgetItem.setData(self, role, data)
def text(self):
@ -113,7 +112,7 @@ class TagListEditor(QDialog, Ui_TagListEditor):
self.count_col.setIcon(self.blank_icon)
# Capture clicks on the horizontal header to sort the table columns
hh = self.table.horizontalHeader();
hh = self.table.horizontalHeader()
hh.setClickable(True)
hh.sectionClicked.connect(self.header_clicked)
hh.sectionResized.connect(self.table_column_resized)

View File

@ -12,7 +12,7 @@ from Queue import Empty, Queue
from PyQt5.Qt import (QAbstractTableModel, QVariant, QModelIndex, Qt,
QTimer, pyqtSignal, QIcon, QDialog, QAbstractItemDelegate, QApplication,
QSize, QStyleOptionProgressBarV2, QString, QStyle, QToolTip, QFrame,
QSize, QStyleOptionProgressBar, QStyle, QToolTip, QFrame,
QHBoxLayout, QVBoxLayout, QSizePolicy, QLabel, QCoreApplication, QAction,
QByteArray, QSortFilterProxyModel)
@ -387,7 +387,7 @@ class ProgressBarDelegate(QAbstractItemDelegate): # {{{
return QSize(120, 30)
def paint(self, painter, option, index):
opts = QStyleOptionProgressBarV2()
opts = QStyleOptionProgressBar()
opts.rect = option.rect
opts.minimum = 1
opts.maximum = 100
@ -396,7 +396,7 @@ class ProgressBarDelegate(QAbstractItemDelegate): # {{{
if not ok:
percent = 0
opts.progress = percent
opts.text = QString(_('Unavailable') if percent == 0 else '%d%%'%percent)
opts.text = (_('Unavailable') if percent == 0 else '%d%%'%percent)
QApplication.style().drawControl(QStyle.CE_ProgressBar, opts, painter)
# }}}

View File

@ -1,8 +1,7 @@
__license__ = 'GPL v3'
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
from PyQt5.QtGui import QGraphicsView
from PyQt5.QtCore import QSize
from PyQt5.Qt import QGraphicsView, QSize
class BookView(QGraphicsView):

View File

@ -2,10 +2,9 @@ __license__ = 'GPL v3'
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
import collections, itertools, glob
from PyQt5.QtCore import Qt, QByteArray, pyqtSignal
from PyQt5.QtGui import QGraphicsRectItem, QGraphicsScene, QPen, \
QBrush, QColor, QFontDatabase, \
QGraphicsItem, QGraphicsLineItem
from PyQt5.Qt import (
Qt, QByteArray, pyqtSignal, QGraphicsRectItem, QGraphicsScene, QPen,
QBrush, QColor, QFontDatabase, QGraphicsItem, QGraphicsLineItem)
from calibre.gui2.lrf_renderer.text import TextBlock, FontLoader, COLOR, PixmapItem

View File

@ -2,8 +2,8 @@ __license__ = 'GPL v3'
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
import sys, logging, os, traceback, time
from PyQt5.QtGui import QKeySequence, QPainter, QDialog, QSpinBox, QSlider, QIcon
from PyQt5.QtCore import Qt, QCoreApplication, QThread
from PyQt5.Qt import (
QKeySequence, QPainter, QDialog, QSpinBox, QSlider, QIcon, Qt, QCoreApplication, QThread, QScrollBar)
from calibre import __appname__, setup_cli_handlers, islinux, isbsd
from calibre.ebooks.lrf.lrfparser import LRFDocument
@ -162,7 +162,6 @@ class Main(MainWindow, Ui_MainWindow):
self.renderer.lrf.device_info.height
hdelta = self.tool_bar.height()+3
from PyQt5.QtGui import QScrollBar
s = QScrollBar(self)
scrollbar_adjust = min(s.width(), s.height())
self.graphics_view.resize_for(width+scrollbar_adjust, height+scrollbar_adjust)

View File

@ -2,9 +2,9 @@ __license__ = 'GPL v3'
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
import sys, collections, operator, copy, re
from PyQt5.QtCore import Qt, QRectF, QString
from PyQt5.QtGui import QFont, QColor, QPixmap, QGraphicsPixmapItem, \
QGraphicsItem, QFontMetrics, QPen, QBrush, QGraphicsRectItem
from PyQt5.Qt import (
Qt, QRectF, QFont, QColor, QPixmap, QGraphicsPixmapItem, QGraphicsItem,
QFontMetrics, QPen, QBrush, QGraphicsRectItem)
from calibre.ebooks.lrf.fonts import LIBERATION_FONT_MAP
from calibre.ebooks.BeautifulSoup import Tag
@ -565,7 +565,7 @@ class Line(QGraphicsItem):
class Word(object):
def __init__(self, string, width, height, ts, font, valign):
self.string, self.width, self.height = QString(string), width, height
self.string, self.width, self.height = string, width, height
self.font = font
self.text_color = ts.textcolor
self.highlight = False

View File

@ -12,7 +12,7 @@ from functools import partial
from PyQt5.Qt import QComboBox, Qt, QLineEdit, pyqtSlot, QDialog, \
pyqtSignal, QCompleter, QAction, QKeySequence, QTimer, \
QString, QIcon, QMenu
QIcon, QMenu
from calibre.gui2 import config, error_dialog, question_dialog, gprefs
from calibre.gui2.dialogs.confirm_delete import confirm
@ -84,8 +84,8 @@ class SearchBox2(QComboBox): # {{{
c = self.line_edit.completer()
c.setCompletionMode(c.PopupCompletion)
c.highlighted[QString].connect(self.completer_used)
c.activated[QString].connect(self.history_selected)
c.highlighted[str].connect(self.completer_used)
c.activated[str].connect(self.history_selected)
self.line_edit.key_pressed.connect(self.key_pressed, type=Qt.DirectConnection)
self.activated.connect(self.history_selected)

View File

@ -10,7 +10,7 @@ __docformat__ = 'restructuredtext en'
from functools import partial
from PyQt5.Qt import (Qt, QIcon, QWidget, QHBoxLayout, QVBoxLayout, QShortcut,
QKeySequence, QToolButton, QString, QLabel, QFrame, QTimer,
QKeySequence, QToolButton, QLabel, QFrame, QTimer,
QMenu, QPushButton, QActionGroup)
from calibre.gui2 import error_dialog, question_dialog
@ -370,7 +370,7 @@ class TagBrowserWidget(QWidget): # {{{
self.item_search.initialize('tag_browser_search')
self.item_search.lineEdit().returnPressed.connect(self.do_find)
self.item_search.lineEdit().textEdited.connect(self.find_text_changed)
self.item_search.activated[QString].connect(self.do_find)
self.item_search.activated[str].connect(self.do_find)
self.item_search.completer().setCaseSensitivity(Qt.CaseSensitive)
parent.tags_view = TagsView(parent)

View File

@ -9,7 +9,7 @@ Logic for setting up conversion jobs
import cPickle, os
from PyQt5.Qt import QDialog, QProgressDialog, QString, QTimer
from PyQt5.Qt import QDialog, QProgressDialog, QTimer
from calibre.ptempfile import PersistentTemporaryFile
from calibre.gui2 import warning_dialog, question_dialog
@ -151,7 +151,7 @@ class QueueBulk(QProgressDialog):
def __init__(self, parent, book_ids, output_format, queue, db, user_recs,
args, use_saved_single_settings=True):
QProgressDialog.__init__(self, '',
QString(), 0, len(book_ids), parent)
None, 0, len(book_ids), parent)
self.setWindowTitle(_('Queueing books for bulk conversion'))
self.book_ids, self.output_format, self.queue, self.db, self.args, self.user_recs = \
book_ids, output_format, queue, db, args, user_recs

View File

@ -82,15 +82,7 @@ class PlainTextEdit(QPlainTextEdit):
ans = c.selectedText().replace(PARAGRAPH_SEPARATOR, '\n')
# QTextCursor pads the return value of selectedText with null bytes if
# non BMP characters such as 0x1f431 are present.
if hasattr(ans, 'rstrip'):
ans = ans.rstrip('\0')
else: # QString
try:
while ans[-1] == '\0':
ans.chop(1)
except IndexError:
pass # ans is an empty string
return ans
return ans.rstrip('\0')
@pyqtSlot()
def copy(self):

View File

@ -10,7 +10,7 @@ from functools import partial
from PyQt5.Qt import (QSize, QSizePolicy, QUrl, Qt, pyqtProperty,
QPainter, QPalette, QBrush, QDialog, QColor, QPoint, QImage, QRegion,
QIcon, QAction, QMenu, QString, pyqtSignal, QApplication, pyqtSlot)
QIcon, QAction, QMenu, pyqtSignal, QApplication, pyqtSlot)
from PyQt5.QtWebKitWidgets import QWebPage, QWebView
from PyQt5.QtWebKit import QWebSettings, QWebElement
@ -225,12 +225,12 @@ class Document(QWebPage): # {{{
def _pass_json_value_getter(self):
val = json.dumps(self.bridge_value)
return QString(val)
return val
def _pass_json_value_setter(self, value):
self.bridge_value = json.loads(unicode(value))
_pass_json_value = pyqtProperty(QString, fget=_pass_json_value_getter,
_pass_json_value = pyqtProperty(str, fget=_pass_json_value_getter,
fset=_pass_json_value_setter)
def after_load(self, last_loaded_path=None):

View File

@ -195,6 +195,10 @@ class OptionSet(object):
src = src.decode('utf-8')
src = src.replace(u'PyQt5.QtCore', u'PyQt4.QtCore')
exec src in options
except RuntimeError:
try:
src = src.replace('PyQt' + '4', 'PyQt5')
exec src in options
except:
print 'Failed to parse options string:'
print repr(src)
@ -228,8 +232,6 @@ class OptionSet(object):
if val is val is True or val is False or val is None or \
isinstance(val, (int, float, long, basestring)):
return repr(val)
if val.__class__.__name__ == 'QString':
return repr(unicode(val))
pickle = cPickle.dumps(val, -1)
return 'cPickle.loads(%s)'%repr(pickle)