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 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):
from PyQt5.QtWebKit import QWebPage
from PyQt5.QtWebKitWidgets import QWebPage
from PyQt5.Qt import QEventLoop, QPalette, Qt, QUrl, QSize
from calibre.gui2 import 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
from PyQt5.Qt import QUrl, QApplication, QSize, QEventLoop, \
QPainter, QImage, QObject, Qt
from PyQt5.QtWebKit import QWebPage
from PyQt5.QtWebKitWidgets import QWebPage
class HTMLTableRenderer(QObject):

View File

@ -14,7 +14,7 @@ from collections import defaultdict
from cssutils import CSSParser
from PyQt5.Qt import (pyqtProperty, QString, QEventLoop, Qt, QSize, QTimer,
pyqtSlot)
from PyQt5.QtWebKit import QWebPage, QWebView
from PyQt5.QtWebKitWidgets import QWebPage, QWebView
from calibre.constants import iswindows
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,
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.constants import iswindows

View File

@ -12,7 +12,8 @@ import os, shutil, json
from PyQt5.Qt import (QEventLoop, QObject, QPrinter, QSizeF, Qt, QPainter,
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.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,
QSizePolicy, QPainter, QRect, pyqtProperty, QLayout, QPalette, QMenu,
QPen, QColor)
from PyQt5.QtWebKit import QWebView
from PyQt5.QtWebKitWidgets import QWebView
from calibre import fit_image
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,
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,
QCheckBox)
from PyQt5.QtWebKit import QWebView, QWebPage
from PyQt5.QtWebKitWidgets import QWebView, QWebPage
from calibre.ebooks.chardet import xml_to_unicode
from calibre import xml_replace_entities, prepare_string_for_xml
@ -443,7 +443,7 @@ class Highlighter(QSyntaxHighlighter):
def highlightBlock(self, text):
state = self.previousBlockState()
len_ = text.length()
len_ = len(text)
start = 0
pos = 0
@ -452,7 +452,7 @@ class Highlighter(QSyntaxHighlighter):
if state == State_Comment:
start = pos
while pos < len_:
if text.mid(pos, 3) == "-->":
if text[pos:pos+3] == u"-->":
pos += 3
state = State_Text
break
@ -463,9 +463,9 @@ class Highlighter(QSyntaxHighlighter):
elif state == State_DocType:
start = pos
while pos < len_:
ch = text.at(pos)
ch = text[pos]
pos += 1
if ch == QChar('>'):
if ch == u'>':
state = State_Text
break
self.setFormat(start, pos - start, self.colors['doctype'])
@ -474,12 +474,12 @@ class Highlighter(QSyntaxHighlighter):
elif state == State_TagStart:
start = pos + 1
while pos < len_:
ch = text.at(pos)
ch = text[pos]
pos += 1
if ch == QChar('>'):
if ch == u'>':
state = State_Text
break
if not ch.isSpace():
if not ch.isspace():
pos -= 1
state = State_TagName
break
@ -488,13 +488,13 @@ class Highlighter(QSyntaxHighlighter):
elif state == State_TagName:
start = pos
while pos < len_:
ch = text.at(pos)
ch = text[pos]
pos += 1
if ch.isSpace():
if ch.isspace():
pos -= 1
state = State_InsideTag
break
if ch == QChar('>'):
if ch == u'>':
state = State_Text
break
self.setFormat(start, pos - start, self.colors['tag'])
@ -504,17 +504,17 @@ class Highlighter(QSyntaxHighlighter):
start = pos
while pos < len_:
ch = text.at(pos)
ch = text[pos]
pos += 1
if ch == QChar('/'):
if ch == u'/':
continue
if ch == QChar('>'):
if ch == u'>':
state = State_Text
break
if not ch.isSpace():
if not ch.isspace():
pos -= 1
state = State_AttributeName
break
@ -524,14 +524,14 @@ class Highlighter(QSyntaxHighlighter):
start = pos
while pos < len_:
ch = text.at(pos)
ch = text[pos]
pos += 1
if ch == QChar('='):
if ch == u'=':
state = State_AttributeValue
break
if ch in (QChar('>'), QChar('/')):
if ch in (u'>', u'/'):
state = State_InsideTag
break
@ -543,20 +543,20 @@ class Highlighter(QSyntaxHighlighter):
# find first non-space character
while pos < len_:
ch = text.at(pos)
ch = text[pos]
pos += 1
# handle opening single quote
if ch == QChar("'"):
if ch == u"'":
state = State_SingleQuote
break
# handle opening double quote
if ch == QChar('"'):
if ch == u'"':
state = State_DoubleQuote
break
if not ch.isSpace():
if not ch.isspace():
break
if state == State_AttributeValue:
@ -564,10 +564,10 @@ class Highlighter(QSyntaxHighlighter):
# just stop at non-space or tag delimiter
start = pos
while pos < len_:
ch = text.at(pos)
if ch.isSpace():
ch = text[pos]
if ch.isspace():
break
if ch in (QChar('>'), QChar('/')):
if ch in (u'>', u'/'):
break
pos += 1
state = State_InsideTag
@ -578,9 +578,9 @@ class Highlighter(QSyntaxHighlighter):
start = pos
while pos < len_:
ch = text.at(pos)
ch = text[pos]
pos += 1
if ch == QChar("'"):
if ch == u"'":
break
state = State_InsideTag
@ -592,9 +592,9 @@ class Highlighter(QSyntaxHighlighter):
start = pos
while pos < len_:
ch = text.at(pos)
ch = text[pos]
pos += 1
if ch == QChar('"'):
if ch == u'"':
break
state = State_InsideTag
@ -604,19 +604,19 @@ class Highlighter(QSyntaxHighlighter):
else:
# State_Text and default
while pos < len_:
ch = text.at(pos)
if ch == QChar('<'):
if text.mid(pos, 4) == "<!--":
ch = text[pos]
if ch == u'<':
if text[pos:pos+4] == u"<!--":
state = State_Comment
else:
if text.mid(pos, 9).toUpper() == "<!DOCTYPE":
if text[pos:pos+9].upper() == u"<!DOCTYPE":
state = State_DocType
else:
state = State_TagStart
break
elif ch == QChar('&'):
elif ch == u'&':
start = pos
while pos < len_ and text.at(pos) != QChar(';'):
while pos < len_ and text[pos] != u';':
self.setFormat(start, pos - start,
self.colors['entity'])
pos += 1

View File

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

View File

@ -22,7 +22,7 @@ from PyQt5.Qt import (
QWidget, QTableView, QGridLayout, QFontInfo, QPalette, QTimer, pyqtSignal,
QAbstractTableModel, QVariant, QSize, QListView, QPixmap, QModelIndex,
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.ebooks.metadata import authors_to_string

View File

@ -10,7 +10,7 @@ import os
from urlparse import urlparse
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.ebooks import BOOK_EXTENSIONS

View File

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

View File

@ -13,7 +13,8 @@ from base64 import b64encode
from PyQt5.Qt import (QWidget, QGridLayout, QListWidget, QSize, Qt, QUrl,
pyqtSlot, pyqtSignal, QVBoxLayout, QFrame, QLabel,
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.gui2 import error_dialog, question_dialog, gprefs

View File

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

View File

@ -11,7 +11,8 @@ 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)
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.shortcuts import Shortcuts

View File

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

View File

@ -9,7 +9,7 @@ __docformat__ = 'restructuredtext en'
from PyQt5.Qt import (QObject, QEventLoop, Qt, QPrintDialog, QPainter, QSize,
QPrintPreviewDialog)
from PyQt5.QtWebKit import QWebView
from PyQt5.QtWebKitWidgets import QWebView
from calibre.gui2 import error_dialog
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,
QSize, QIcon, Qt)
from PyQt5.QtWebKit import QWebView
from PyQt5.QtWebKitWidgets import QWebView
from calibre.gui2 import gprefs, error_dialog

View File

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

View File

@ -14,7 +14,8 @@ from threading import current_thread
from PyQt5.Qt import (QObject, QNetworkAccessManager, QNetworkDiskCache,
QNetworkProxy, QNetworkProxyFactory, QEventLoop, QUrl, pyqtSignal,
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.constants import ispy3, cache_dir