Port WebKit imports and QChar

WebKit has been split up into QtWebKit and QtWebKitWidgets. Change
imports accordingly.

Replace use of QChar since it no longer exists in PyQt5
This commit is contained in:
Kovid Goyal 2014-04-12 08:07:26 +05:30
parent f090af1bd0
commit f5334df877
20 changed files with 60 additions and 60 deletions

View File

@ -298,8 +298,3 @@ def get_windows_user_locale_name():
return None return None
return u'_'.join(buf.value.split(u'-')[:2]) return u'_'.join(buf.value.split(u'-')[:2])
def is_modern_webkit():
# Check if we are using QtWebKit >= 2.3
from PyQt5.QtWebKit import qWebKitMajorVersion
return qWebKitMajorVersion() >= 537

View File

@ -130,7 +130,7 @@ def render_html_svg_workaround(path_to_html, log, width=590, height=750):
def render_html(path_to_html, width=590, height=750, as_xhtml=True): def render_html(path_to_html, width=590, height=750, as_xhtml=True):
from PyQt5.QtWebKit import QWebPage from PyQt5.QtWebKitWidgets import QWebPage
from PyQt5.Qt import QEventLoop, QPalette, Qt, QUrl, QSize from PyQt5.Qt import QEventLoop, QPalette, Qt, QUrl, QSize
from calibre.gui2 import is_ok_to_use_qt from calibre.gui2 import is_ok_to_use_qt
if not is_ok_to_use_qt(): if not is_ok_to_use_qt():

View File

@ -9,7 +9,7 @@ Render HTML tables as images.
import os, tempfile, atexit, shutil import os, tempfile, atexit, shutil
from PyQt5.Qt import QUrl, QApplication, QSize, QEventLoop, \ from PyQt5.Qt import QUrl, QApplication, QSize, QEventLoop, \
QPainter, QImage, QObject, Qt QPainter, QImage, QObject, Qt
from PyQt5.QtWebKit import QWebPage from PyQt5.QtWebKitWidgets import QWebPage
class HTMLTableRenderer(QObject): class HTMLTableRenderer(QObject):

View File

@ -14,7 +14,7 @@ from collections import defaultdict
from cssutils import CSSParser from cssutils import CSSParser
from PyQt5.Qt import (pyqtProperty, QString, QEventLoop, Qt, QSize, QTimer, from PyQt5.Qt import (pyqtProperty, QString, QEventLoop, Qt, QSize, QTimer,
pyqtSlot) pyqtSlot)
from PyQt5.QtWebKit import QWebPage, QWebView from PyQt5.QtWebKitWidgets import QWebPage, QWebView
from calibre.constants import iswindows from calibre.constants import iswindows
from calibre.ebooks.oeb.display.webview import load_html from calibre.ebooks.oeb.display.webview import load_html

View File

@ -14,7 +14,8 @@ from collections import defaultdict
from PyQt5.Qt import (QObject, QPainter, Qt, QSize, QString, QTimer, from PyQt5.Qt import (QObject, QPainter, Qt, QSize, QString, QTimer,
pyqtProperty, QEventLoop, QPixmap, QRect, pyqtSlot) pyqtProperty, QEventLoop, QPixmap, QRect, pyqtSlot)
from PyQt5.QtWebKit import QWebView, QWebPage, QWebSettings from PyQt5.QtWebKit import QWebSettings
from PyQt5.QtWebKitWidgets import QWebView, QWebPage
from calibre import fit_image from calibre import fit_image
from calibre.constants import iswindows from calibre.constants import iswindows

View File

@ -12,7 +12,8 @@ import os, shutil, json
from PyQt5.Qt import (QEventLoop, QObject, QPrinter, QSizeF, Qt, QPainter, from PyQt5.Qt import (QEventLoop, QObject, QPrinter, QSizeF, Qt, QPainter,
QPixmap, QTimer, pyqtProperty, QString, QSize) QPixmap, QTimer, pyqtProperty, QString, QSize)
from PyQt5.QtWebKit import QWebView, QWebPage, QWebSettings from PyQt5.QtWebKit import QWebSettings
from PyQt5.QtWebKitWidgets import QWebView, QWebPage
from calibre.ptempfile import PersistentTemporaryDirectory from calibre.ptempfile import PersistentTemporaryDirectory
from calibre.ebooks.pdf.pageoptions import (unit, paper_size) from calibre.ebooks.pdf.pageoptions import (unit, paper_size)

View File

@ -11,7 +11,7 @@ from PyQt5.Qt import (QPixmap, QSize, QWidget, Qt, pyqtSignal, QUrl, QIcon,
QPropertyAnimation, QEasingCurve, QApplication, QFontInfo, QAction, QPropertyAnimation, QEasingCurve, QApplication, QFontInfo, QAction,
QSizePolicy, QPainter, QRect, pyqtProperty, QLayout, QPalette, QMenu, QSizePolicy, QPainter, QRect, pyqtProperty, QLayout, QPalette, QMenu,
QPen, QColor) QPen, QColor)
from PyQt5.QtWebKit import QWebView from PyQt5.QtWebKitWidgets import QWebView
from calibre import fit_image from calibre import fit_image
from calibre.gui2.dnd import (dnd_has_image, dnd_get_image, dnd_get_files, from calibre.gui2.dnd import (dnd_has_image, dnd_get_image, dnd_get_files,

View File

@ -12,10 +12,10 @@ import sip
from PyQt5.Qt import (QApplication, QFontInfo, QSize, QWidget, QPlainTextEdit, from PyQt5.Qt import (QApplication, QFontInfo, QSize, QWidget, QPlainTextEdit,
QToolBar, QVBoxLayout, QAction, QIcon, Qt, QTabWidget, QUrl, QFormLayout, QToolBar, QVBoxLayout, QAction, QIcon, Qt, QTabWidget, QUrl, QFormLayout,
QSyntaxHighlighter, QColor, QChar, QColorDialog, QMenu, QDialog, QLabel, QSyntaxHighlighter, QColor, QColorDialog, QMenu, QDialog, QLabel,
QHBoxLayout, QKeySequence, QLineEdit, QDialogButtonBox, QPushButton, QHBoxLayout, QKeySequence, QLineEdit, QDialogButtonBox, QPushButton,
QCheckBox) QCheckBox)
from PyQt5.QtWebKit import QWebView, QWebPage from PyQt5.QtWebKitWidgets import QWebView, QWebPage
from calibre.ebooks.chardet import xml_to_unicode from calibre.ebooks.chardet import xml_to_unicode
from calibre import xml_replace_entities, prepare_string_for_xml from calibre import xml_replace_entities, prepare_string_for_xml
@ -443,7 +443,7 @@ class Highlighter(QSyntaxHighlighter):
def highlightBlock(self, text): def highlightBlock(self, text):
state = self.previousBlockState() state = self.previousBlockState()
len_ = text.length() len_ = len(text)
start = 0 start = 0
pos = 0 pos = 0
@ -452,7 +452,7 @@ class Highlighter(QSyntaxHighlighter):
if state == State_Comment: if state == State_Comment:
start = pos start = pos
while pos < len_: while pos < len_:
if text.mid(pos, 3) == "-->": if text[pos:pos+3] == u"-->":
pos += 3 pos += 3
state = State_Text state = State_Text
break break
@ -463,9 +463,9 @@ class Highlighter(QSyntaxHighlighter):
elif state == State_DocType: elif state == State_DocType:
start = pos start = pos
while pos < len_: while pos < len_:
ch = text.at(pos) ch = text[pos]
pos += 1 pos += 1
if ch == QChar('>'): if ch == u'>':
state = State_Text state = State_Text
break break
self.setFormat(start, pos - start, self.colors['doctype']) self.setFormat(start, pos - start, self.colors['doctype'])
@ -474,12 +474,12 @@ class Highlighter(QSyntaxHighlighter):
elif state == State_TagStart: elif state == State_TagStart:
start = pos + 1 start = pos + 1
while pos < len_: while pos < len_:
ch = text.at(pos) ch = text[pos]
pos += 1 pos += 1
if ch == QChar('>'): if ch == u'>':
state = State_Text state = State_Text
break break
if not ch.isSpace(): if not ch.isspace():
pos -= 1 pos -= 1
state = State_TagName state = State_TagName
break break
@ -488,13 +488,13 @@ class Highlighter(QSyntaxHighlighter):
elif state == State_TagName: elif state == State_TagName:
start = pos start = pos
while pos < len_: while pos < len_:
ch = text.at(pos) ch = text[pos]
pos += 1 pos += 1
if ch.isSpace(): if ch.isspace():
pos -= 1 pos -= 1
state = State_InsideTag state = State_InsideTag
break break
if ch == QChar('>'): if ch == u'>':
state = State_Text state = State_Text
break break
self.setFormat(start, pos - start, self.colors['tag']) self.setFormat(start, pos - start, self.colors['tag'])
@ -504,17 +504,17 @@ class Highlighter(QSyntaxHighlighter):
start = pos start = pos
while pos < len_: while pos < len_:
ch = text.at(pos) ch = text[pos]
pos += 1 pos += 1
if ch == QChar('/'): if ch == u'/':
continue continue
if ch == QChar('>'): if ch == u'>':
state = State_Text state = State_Text
break break
if not ch.isSpace(): if not ch.isspace():
pos -= 1 pos -= 1
state = State_AttributeName state = State_AttributeName
break break
@ -524,14 +524,14 @@ class Highlighter(QSyntaxHighlighter):
start = pos start = pos
while pos < len_: while pos < len_:
ch = text.at(pos) ch = text[pos]
pos += 1 pos += 1
if ch == QChar('='): if ch == u'=':
state = State_AttributeValue state = State_AttributeValue
break break
if ch in (QChar('>'), QChar('/')): if ch in (u'>', u'/'):
state = State_InsideTag state = State_InsideTag
break break
@ -543,20 +543,20 @@ class Highlighter(QSyntaxHighlighter):
# find first non-space character # find first non-space character
while pos < len_: while pos < len_:
ch = text.at(pos) ch = text[pos]
pos += 1 pos += 1
# handle opening single quote # handle opening single quote
if ch == QChar("'"): if ch == u"'":
state = State_SingleQuote state = State_SingleQuote
break break
# handle opening double quote # handle opening double quote
if ch == QChar('"'): if ch == u'"':
state = State_DoubleQuote state = State_DoubleQuote
break break
if not ch.isSpace(): if not ch.isspace():
break break
if state == State_AttributeValue: if state == State_AttributeValue:
@ -564,10 +564,10 @@ class Highlighter(QSyntaxHighlighter):
# just stop at non-space or tag delimiter # just stop at non-space or tag delimiter
start = pos start = pos
while pos < len_: while pos < len_:
ch = text.at(pos) ch = text[pos]
if ch.isSpace(): if ch.isspace():
break break
if ch in (QChar('>'), QChar('/')): if ch in (u'>', u'/'):
break break
pos += 1 pos += 1
state = State_InsideTag state = State_InsideTag
@ -578,9 +578,9 @@ class Highlighter(QSyntaxHighlighter):
start = pos start = pos
while pos < len_: while pos < len_:
ch = text.at(pos) ch = text[pos]
pos += 1 pos += 1
if ch == QChar("'"): if ch == u"'":
break break
state = State_InsideTag state = State_InsideTag
@ -592,9 +592,9 @@ class Highlighter(QSyntaxHighlighter):
start = pos start = pos
while pos < len_: while pos < len_:
ch = text.at(pos) ch = text[pos]
pos += 1 pos += 1
if ch == QChar('"'): if ch == u'"':
break break
state = State_InsideTag state = State_InsideTag
@ -604,19 +604,19 @@ class Highlighter(QSyntaxHighlighter):
else: else:
# State_Text and default # State_Text and default
while pos < len_: while pos < len_:
ch = text.at(pos) ch = text[pos]
if ch == QChar('<'): if ch == u'<':
if text.mid(pos, 4) == "<!--": if text[pos:pos+4] == u"<!--":
state = State_Comment state = State_Comment
else: else:
if text.mid(pos, 9).toUpper() == "<!DOCTYPE": if text[pos:pos+9].upper() == u"<!DOCTYPE":
state = State_DocType state = State_DocType
else: else:
state = State_TagStart state = State_TagStart
break break
elif ch == QChar('&'): elif ch == u'&':
start = pos start = pos
while pos < len_ and text.at(pos) != QChar(';'): while pos < len_ and text[pos] != u';':
self.setFormat(start, pos - start, self.setFormat(start, pos - start,
self.colors['entity']) self.colors['entity'])
pos += 1 pos += 1

View File

@ -10,7 +10,7 @@ from PyQt5.Qt import (
QCoreApplication, QModelIndex, QTimer, Qt, pyqtSignal, QWidget, QCoreApplication, QModelIndex, QTimer, Qt, pyqtSignal, QWidget,
QGridLayout, QDialog, QPixmap, QSize, QPalette, QShortcut, QKeySequence, QGridLayout, QDialog, QPixmap, QSize, QPalette, QShortcut, QKeySequence,
QSplitter, QVBoxLayout, QCheckBox, QPushButton, QIcon, QBrush) QSplitter, QVBoxLayout, QCheckBox, QPushButton, QIcon, QBrush)
from PyQt5.QtWebKit import QWebView from PyQt5.QtWebKitWidgets import QWebView
from calibre.gui2 import gprefs from calibre.gui2 import gprefs
from calibre import fit_image from calibre import fit_image

View File

@ -22,7 +22,7 @@ from PyQt5.Qt import (
QWidget, QTableView, QGridLayout, QFontInfo, QPalette, QTimer, pyqtSignal, QWidget, QTableView, QGridLayout, QFontInfo, QPalette, QTimer, pyqtSignal,
QAbstractTableModel, QVariant, QSize, QListView, QPixmap, QModelIndex, QAbstractTableModel, QVariant, QSize, QListView, QPixmap, QModelIndex,
QAbstractListModel, QColor, QRect, QTextBrowser, QStringListModel, QMenu, QCursor) QAbstractListModel, QColor, QRect, QTextBrowser, QStringListModel, QMenu, QCursor)
from PyQt5.QtWebKit import QWebView from PyQt5.QtWebKitWidgets import QWebView
from calibre.customize.ui import metadata_plugins from calibre.customize.ui import metadata_plugins
from calibre.ebooks.metadata import authors_to_string from calibre.ebooks.metadata import authors_to_string

View File

@ -10,7 +10,7 @@ import os
from urlparse import urlparse from urlparse import urlparse
from PyQt5.Qt import QNetworkCookieJar, QFileDialog, QNetworkProxy from PyQt5.Qt import QNetworkCookieJar, QFileDialog, QNetworkProxy
from PyQt5.QtWebKit import QWebView, QWebPage from PyQt5.QtWebKitWidgets import QWebView, QWebPage
from calibre import USER_AGENT, get_proxies, get_download_filename from calibre import USER_AGENT, get_proxies, get_download_filename
from calibre.ebooks import BOOK_EXTENSIONS from calibre.ebooks import BOOK_EXTENSIONS

View File

@ -85,12 +85,12 @@
<customwidget> <customwidget>
<class>QWebView</class> <class>QWebView</class>
<extends>QWidget</extends> <extends>QWidget</extends>
<header>QtWebKit/QWebView</header> <header>QtWebKitWidgets/QWebView</header>
</customwidget> </customwidget>
<customwidget> <customwidget>
<class>NPWebView</class> <class>NPWebView</class>
<extends>QWebView</extends> <extends>QWebView</extends>
<header>web_control.h</header> <header>calibre/gui2/store/web_control.h</header>
</customwidget> </customwidget>
</customwidgets> </customwidgets>
<resources/> <resources/>

View File

@ -13,7 +13,8 @@ from base64 import b64encode
from PyQt5.Qt import (QWidget, QGridLayout, QListWidget, QSize, Qt, QUrl, from PyQt5.Qt import (QWidget, QGridLayout, QListWidget, QSize, Qt, QUrl,
pyqtSlot, pyqtSignal, QVBoxLayout, QFrame, QLabel, pyqtSlot, pyqtSignal, QVBoxLayout, QFrame, QLabel,
QLineEdit, QTimer, QPushButton, QIcon, QSplitter) QLineEdit, QTimer, QPushButton, QIcon, QSplitter)
from PyQt5.QtWebKit import QWebView, QWebPage, QWebElement from PyQt5.QtWebKitWidgets import QWebView, QWebPage
from PyQt5.QtWebKit import QWebElement
from calibre.ebooks.oeb.display.webview import load_html from calibre.ebooks.oeb.display.webview import load_html
from calibre.gui2 import error_dialog, question_dialog, gprefs from calibre.gui2 import error_dialog, question_dialog, gprefs

View File

@ -20,7 +20,7 @@ from PyQt5.Qt import (
QWidget, QVBoxLayout, QApplication, QSize, QNetworkAccessManager, QMenu, QIcon, QWidget, QVBoxLayout, QApplication, QSize, QNetworkAccessManager, QMenu, QIcon,
QNetworkReply, QTimer, QNetworkRequest, QUrl, Qt, QNetworkDiskCache, QToolBar, QNetworkReply, QTimer, QNetworkRequest, QUrl, Qt, QNetworkDiskCache, QToolBar,
pyqtSlot, pyqtSignal, QFontDatabase) pyqtSlot, pyqtSignal, QFontDatabase)
from PyQt5.QtWebKit import QWebView, QWebInspector, QWebPage from PyQt5.QtWebKitWidgets import QWebView, QWebInspector, QWebPage
from calibre import prints from calibre import prints
from calibre.constants import iswindows from calibre.constants import iswindows

View File

@ -11,7 +11,8 @@ from functools import partial
from PyQt5.Qt import (QSize, QSizePolicy, QUrl, Qt, pyqtProperty, from PyQt5.Qt import (QSize, QSizePolicy, QUrl, Qt, pyqtProperty,
QPainter, QPalette, QBrush, QDialog, QColor, QPoint, QImage, QRegion, QPainter, QPalette, QBrush, QDialog, QColor, QPoint, QImage, QRegion,
QIcon, QAction, QMenu, QString, pyqtSignal, QApplication, pyqtSlot) QIcon, QAction, QMenu, QString, pyqtSignal, QApplication, pyqtSlot)
from PyQt5.QtWebKit import QWebPage, QWebView, QWebSettings, QWebElement from PyQt5.QtWebKitWidgets import QWebPage, QWebView
from PyQt5.QtWebKit import QWebSettings, QWebElement
from calibre.gui2.viewer.flip import SlideFlip from calibre.gui2.viewer.flip import SlideFlip
from calibre.gui2.shortcuts import Shortcuts from calibre.gui2.shortcuts import Shortcuts

View File

@ -7,7 +7,7 @@ __license__ = 'GPL v3'
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>' __copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
from PyQt5.Qt import QDialog, QDialogButtonBox, QVBoxLayout, QIcon from PyQt5.Qt import QDialog, QDialogButtonBox, QVBoxLayout, QIcon
from PyQt5.QtWebKit import QWebInspector from PyQt5.QtWebKitWidgets import QWebInspector
from calibre.gui2 import gprefs from calibre.gui2 import gprefs

View File

@ -9,7 +9,7 @@ __docformat__ = 'restructuredtext en'
from PyQt5.Qt import (QObject, QEventLoop, Qt, QPrintDialog, QPainter, QSize, from PyQt5.Qt import (QObject, QEventLoop, Qt, QPrintDialog, QPainter, QSize,
QPrintPreviewDialog) QPrintPreviewDialog)
from PyQt5.QtWebKit import QWebView from PyQt5.QtWebKitWidgets import QWebView
from calibre.gui2 import error_dialog from calibre.gui2 import error_dialog
from calibre.ebooks.oeb.display.webview import load_html from calibre.ebooks.oeb.display.webview import load_html

View File

@ -9,7 +9,7 @@ __docformat__ = 'restructuredtext en'
from PyQt5.Qt import (QDialog, QDialogButtonBox, QVBoxLayout, QApplication, from PyQt5.Qt import (QDialog, QDialogButtonBox, QVBoxLayout, QApplication,
QSize, QIcon, Qt) QSize, QIcon, Qt)
from PyQt5.QtWebKit import QWebView from PyQt5.QtWebKitWidgets import QWebView
from calibre.gui2 import gprefs, error_dialog from calibre.gui2 import gprefs, error_dialog

View File

@ -77,7 +77,7 @@ def test_apsw():
def test_qt(): def test_qt():
from PyQt5.Qt import (QDialog, QImageReader, QNetworkAccessManager) from PyQt5.Qt import (QDialog, QImageReader, QNetworkAccessManager)
from PyQt5.QtWebKit import QWebView from PyQt5.QtWebKitWidgets import QWebView
fmts = set(map(unicode, QImageReader.supportedImageFormats())) fmts = set(map(unicode, QImageReader.supportedImageFormats()))
testf = set(['jpg', 'png', 'mng', 'svg', 'ico', 'gif']) testf = set(['jpg', 'png', 'mng', 'svg', 'ico', 'gif'])
if testf.intersection(fmts) != testf: if testf.intersection(fmts) != testf:

View File

@ -14,7 +14,8 @@ from threading import current_thread
from PyQt5.Qt import (QObject, QNetworkAccessManager, QNetworkDiskCache, from PyQt5.Qt import (QObject, QNetworkAccessManager, QNetworkDiskCache,
QNetworkProxy, QNetworkProxyFactory, QEventLoop, QUrl, pyqtSignal, QNetworkProxy, QNetworkProxyFactory, QEventLoop, QUrl, pyqtSignal,
QDialog, QVBoxLayout, QSize, QNetworkCookieJar, Qt, pyqtSlot, QPixmap) QDialog, QVBoxLayout, QSize, QNetworkCookieJar, Qt, pyqtSlot, QPixmap)
from PyQt5.QtWebKit import QWebPage, QWebSettings, QWebView, QWebElement from PyQt5.QtWebKit import QWebSettings, QWebElement
from PyQt5.QtWebKitWidgets import QWebPage, QWebView
from calibre import USER_AGENT, prints, get_proxies, get_proxy_info, prepare_string_for_xml from calibre import USER_AGENT, prints, get_proxies, get_proxy_info, prepare_string_for_xml
from calibre.constants import ispy3, cache_dir from calibre.constants import ispy3, cache_dir