WebBrowser/Network/EricSchemeHandler.py

Sun, 03 Feb 2019 16:10:39 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 03 Feb 2019 16:10:39 +0100
changeset 6695
0a51887c13cd
parent 6691
973b0d0ecc87
permissions
-rw-r--r--

Web Browser (NG):
- added a site info widget that is show when the site icon in the URL entry is clicked
- added code to register custom protocol handlers (upon request of the user via the site info widget)

4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
6645
ad476851d7e0 Updated copyright for 2019.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6625
diff changeset
3 # Copyright (c) 2016 - 2019 Detlev Offenbach <detlev@die-offenbachs.de>
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a scheme handler for the eric: scheme.
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 from __future__ import unicode_literals
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11
4859
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
12 from PyQt5.QtCore import pyqtSignal, QByteArray, QBuffer, QIODevice, \
6691
973b0d0ecc87 EricSchemeHandler: ensure that the page is loaded immediately.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
13 QUrlQuery, QMutex, QMutexLocker
4861
d419f153925d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4859
diff changeset
14 from PyQt5.QtWidgets import qApp
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 from PyQt5.QtWebEngineCore import QWebEngineUrlSchemeHandler
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 from ..Tools.WebBrowserTools import readAllFileContents
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
4917
682750cc7bd5 Corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4885
diff changeset
19
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 class EricSchemeHandler(QWebEngineUrlSchemeHandler):
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 """
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 Class implementing a scheme handler for the eric: scheme.
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 """
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 SupportedPages = [
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 "adblock", # error page for URLs blocked by AdBlock
4861
d419f153925d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4859
diff changeset
26 "home", "start", "startpage", # eric home page
4868
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4861
diff changeset
27 "speeddial", # eric speeddial
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 ]
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 def __init__(self, parent=None):
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 """
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 Constructor
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 @param parent reference to the parent object
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 @type QObject
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 """
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 super(EricSchemeHandler, self).__init__(parent)
4859
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
38
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
39 self.__replies = []
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 def requestStarted(self, job):
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 """
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 Public method handling the URL request.
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 @param job URL request job
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 @type QWebEngineUrlRequestJob
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 """
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 if job.requestUrl().path() in self.SupportedPages:
4859
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
49 reply = EricSchemeReply(job)
6120
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
50 reply.closed.connect(lambda: self.__replyClosed(reply))
4859
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
51 self.__replies.append(reply)
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
52 job.reply(b"text/html", reply)
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 else:
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 job.reply(QByteArray(), QBuffer())
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 # job.fail(QWebEngineUrlRequestJob.UrlNotFound)
4859
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
56
6120
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
57 def __replyClosed(self, reply):
4859
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
58 """
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
59 Private slot handling the closed signal of a reply.
6120
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
60
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
61 @param reply reference to the network reply
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
62 @type EricSchemeReply
4859
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
63 """
6120
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
64 if reply in self.__replies:
5605
1950fe1a32c4 Finished fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
65 self.__replies.remove(reply)
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 class EricSchemeReply(QIODevice):
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 """
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 Class implementing a reply for a requested eric: page.
4859
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
71
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
72 @signal closed emitted to signal that the web engine has read
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
73 the data
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 """
4859
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
75 closed = pyqtSignal()
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
76
4868
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4861
diff changeset
77 _speedDialPage = ""
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4861
diff changeset
78
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 def __init__(self, job, parent=None):
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 """
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 Constructor
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 @param job reference to the URL request
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 @type QWebEngineUrlRequestJob
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 @param parent reference to the parent object
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 @type QObject
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 """
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 super(EricSchemeReply, self).__init__(parent)
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 self.__loaded = False
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 self.__job = job
6507
54054456ca58 EricSchemeHandler, QtHelpSchemeHandler: ensure, that data is loaded in the main thread.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6134
diff changeset
92 self.__mutex = QMutex()
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 self.__pageName = self.__job.requestUrl().path()
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 self.__buffer = QBuffer()
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96
6691
973b0d0ecc87 EricSchemeHandler: ensure that the page is loaded immediately.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
97 self.__loadPage()
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 def __loadPage(self):
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 """
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 Private method to load the requested page.
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 """
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 if self.__loaded:
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 return
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105
6625
a67fee7bc09c Web Browser: changed the web browser logic inside eric to use a remote controlled web browser process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6531
diff changeset
106 lock = QMutexLocker(self.__mutex)
a67fee7bc09c Web Browser: changed the web browser logic inside eric to use a remote controlled web browser process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6531
diff changeset
107
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 if self.__pageName == "adblock":
6507
54054456ca58 EricSchemeHandler, QtHelpSchemeHandler: ensure, that data is loaded in the main thread.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6134
diff changeset
109 contents = self.__adBlockPage()
4861
d419f153925d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4859
diff changeset
110 elif self.__pageName in ["home", "start", "startpage"]:
6507
54054456ca58 EricSchemeHandler, QtHelpSchemeHandler: ensure, that data is loaded in the main thread.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6134
diff changeset
111 contents = self.__startPage()
4868
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4861
diff changeset
112 elif self.__pageName == "speeddial":
6507
54054456ca58 EricSchemeHandler, QtHelpSchemeHandler: ensure, that data is loaded in the main thread.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6134
diff changeset
113 contents = self.__speedDialPage()
54054456ca58 EricSchemeHandler, QtHelpSchemeHandler: ensure, that data is loaded in the main thread.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6134
diff changeset
114 else:
54054456ca58 EricSchemeHandler, QtHelpSchemeHandler: ensure, that data is loaded in the main thread.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6134
diff changeset
115 contents = ""
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116
6507
54054456ca58 EricSchemeHandler, QtHelpSchemeHandler: ensure, that data is loaded in the main thread.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6134
diff changeset
117 self.__buffer.setData(contents.encode("utf-8"))
54054456ca58 EricSchemeHandler, QtHelpSchemeHandler: ensure, that data is loaded in the main thread.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6134
diff changeset
118 self.__buffer.open(QIODevice.ReadOnly)
6531
a401efd02cd1 EricSchemeHandler, QtHelpSchemeHandler: change code slightly to avoid a timing related issue.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6507
diff changeset
119 self.open(QIODevice.ReadOnly)
6507
54054456ca58 EricSchemeHandler, QtHelpSchemeHandler: ensure, that data is loaded in the main thread.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6134
diff changeset
120 lock.unlock()
54054456ca58 EricSchemeHandler, QtHelpSchemeHandler: ensure, that data is loaded in the main thread.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6134
diff changeset
121
54054456ca58 EricSchemeHandler, QtHelpSchemeHandler: ensure, that data is loaded in the main thread.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6134
diff changeset
122 self.readyRead.emit()
54054456ca58 EricSchemeHandler, QtHelpSchemeHandler: ensure, that data is loaded in the main thread.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6134
diff changeset
123
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 self.__loaded = True
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 def bytesAvailable(self):
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 """
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 Public method to get the number of available bytes.
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 @return number of available bytes
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131 @rtype int
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 """
6507
54054456ca58 EricSchemeHandler, QtHelpSchemeHandler: ensure, that data is loaded in the main thread.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6134
diff changeset
133 lock = QMutexLocker(self.__mutex) # __IGNORE_WARNING__
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 return self.__buffer.bytesAvailable()
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 def readData(self, maxlen):
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 """
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138 Public method to retrieve data from the reply object.
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140 @param maxlen maximum number of bytes to read (integer)
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141 @return string containing the data (bytes)
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142 """
6507
54054456ca58 EricSchemeHandler, QtHelpSchemeHandler: ensure, that data is loaded in the main thread.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6134
diff changeset
143 lock = QMutexLocker(self.__mutex) # __IGNORE_WARNING__
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144 return self.__buffer.read(maxlen)
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145
4859
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
146 def close(self):
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
147 """
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
148 Public method used to cloase the reply.
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
149 """
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
150 super(EricSchemeReply, self).close()
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
151 self.closed.emit()
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153 def __adBlockPage(self):
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 """
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 Private method to build the AdBlock page.
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157 @return built AdBlock page
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158 @rtype str
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159 """
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 query = QUrlQuery(self.__job.requestUrl())
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161 rule = query.queryItemValue("rule")
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162 subscription = query.queryItemValue("subscription")
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 title = self.tr("Content blocked by AdBlock Plus")
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 message = self.tr(
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165 "Blocked by rule: <i>{0} ({1})</i>").format(rule, subscription)
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167 page = readAllFileContents(":/html/adblockPage.html")
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168 page = page.replace(
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169 "@FAVICON@", "qrc:icons/adBlockPlus16.png")
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170 page = page.replace(
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171 "@IMAGE@", "qrc:icons/adBlockPlus64.png")
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172 page = page.replace("@TITLE@", title)
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173 page = page.replace("@MESSAGE@", message)
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175 return page
4861
d419f153925d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4859
diff changeset
176
d419f153925d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4859
diff changeset
177 def __startPage(self):
d419f153925d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4859
diff changeset
178 """
d419f153925d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4859
diff changeset
179 Private method to build the Start page.
d419f153925d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4859
diff changeset
180
d419f153925d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4859
diff changeset
181 @return built Start page
d419f153925d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4859
diff changeset
182 @rtype str
d419f153925d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4859
diff changeset
183 """
d419f153925d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4859
diff changeset
184 page = readAllFileContents(":/html/startPage.html")
d419f153925d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4859
diff changeset
185 page = page.replace("@FAVICON@", "qrc:icons/ericWeb16.png")
d419f153925d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4859
diff changeset
186 page = page.replace("@IMAGE@", "qrc:icons/ericWeb32.png")
d419f153925d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4859
diff changeset
187 page = page.replace("@TITLE@",
d419f153925d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4859
diff changeset
188 self.tr("Welcome to eric6 Web Browser!"))
d419f153925d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4859
diff changeset
189 page = page.replace("@ERIC_LINK@", self.tr("About eric6"))
d419f153925d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4859
diff changeset
190 page = page.replace("@HEADER_TITLE@", self.tr("eric6 Web Browser"))
d419f153925d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4859
diff changeset
191 page = page.replace("@SUBMIT@", self.tr("Search!"))
d419f153925d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4859
diff changeset
192 if qApp.isLeftToRight():
d419f153925d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4859
diff changeset
193 ltr = "LTR"
d419f153925d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4859
diff changeset
194 else:
d419f153925d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4859
diff changeset
195 ltr = "RTL"
d419f153925d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4859
diff changeset
196 page = page.replace("@QT_LAYOUT_DIRECTION@", ltr)
d419f153925d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4859
diff changeset
197
d419f153925d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4859
diff changeset
198 return page
4868
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4861
diff changeset
199
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4861
diff changeset
200 def __speedDialPage(self):
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4861
diff changeset
201 """
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4861
diff changeset
202 Private method to create the Speeddial page.
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4861
diff changeset
203
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4861
diff changeset
204 @return prepared speeddial page (QByteArray)
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4861
diff changeset
205 """
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4861
diff changeset
206 if not self._speedDialPage:
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4861
diff changeset
207 page = readAllFileContents(":/html/speeddialPage.html")
5664
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
208 page = page.replace("@FAVICON@", "qrc:icons/ericWeb16.png")
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
209 page = page.replace("@IMG_PLUS@", "qrc:icons/plus.png")
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
210 page = page.replace("@IMG_CLOSE@", "qrc:icons/close.png")
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
211 page = page.replace("@IMG_EDIT@", "qrc:icons/edit.png")
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
212 page = page.replace("@IMG_RELOAD@", "qrc:icons/reload.png")
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
213 page = page.replace("@IMG_SETTINGS@", "qrc:icons/setting.png")
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
214 page = page.replace("@LOADING-IMG@", "qrc:icons/loading.gif")
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
215 page = page.replace("@BOX-BORDER@",
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
216 "qrc:icons/box-border-small.png")
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
217
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
218 page = page.replace("@JQUERY@", "qrc:javascript/jquery.js")
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
219 page = page.replace("@JQUERY-UI@", "qrc:javascript/jquery-ui.js")
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
220
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
221 page = page.replace("@SITE-TITLE@", self.tr("Speed Dial"))
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
222 page = page.replace("@URL@", self.tr("URL"))
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
223 page = page.replace("@TITLE@", self.tr("Title"))
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
224 page = page.replace("@APPLY@", self.tr("Apply"))
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
225 page = page.replace("@CLOSE@", self.tr("Close"))
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
226 page = page.replace("@NEW-PAGE@", self.tr("New Page"))
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
227 page = page.replace("@TITLE-EDIT@", self.tr("Edit"))
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
228 page = page.replace("@TITLE-REMOVE@", self.tr("Remove"))
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
229 page = page.replace("@TITLE-RELOAD@", self.tr("Reload"))
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
230 page = page.replace("@TITLE-WARN@",
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
231 self.tr("Are you sure to remove this"
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
232 " speed dial?"))
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
233 page = page.replace("@TITLE-WARN-REL@",
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
234 self.tr("Are you sure you want to reload"
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
235 " all speed dials?"))
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
236 page = page.replace("@TITLE-FETCHTITLE@",
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
237 self.tr("Load title from page"))
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
238 page = page.replace("@SETTINGS-TITLE@",
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
239 self.tr("Speed Dial Settings"))
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
240 page = page.replace("@ADD-TITLE@", self.tr("Add New Page"))
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
241 page = page.replace("@TXT_NRROWS@",
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
242 self.tr("Maximum pages in a row:"))
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
243 page = page.replace("@TXT_SDSIZE@",
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
244 self.tr("Change size of pages:"))
6127
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
245 page = page.replace("@JAVASCRIPT_DISABLED@",
6134
cb0985e8da91 Introduced a navigation bar button to open the downloads manager window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6127
diff changeset
246 self.tr("SpeedDial requires enabled"
cb0985e8da91 Introduced a navigation bar button to open the downloads manager window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6127
diff changeset
247 " JavaScript."))
4868
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4861
diff changeset
248
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4861
diff changeset
249 self._speedDialPage = page
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4861
diff changeset
250
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4861
diff changeset
251 from WebBrowser.WebBrowserWindow import WebBrowserWindow
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4861
diff changeset
252 dial = WebBrowserWindow.speedDial()
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4861
diff changeset
253 page = (
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4861
diff changeset
254 self._speedDialPage
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4861
diff changeset
255 .replace("@INITIAL-SCRIPT@", dial.initialScript())
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4861
diff changeset
256 .replace("@ROW-PAGES@", str(dial.pagesInRow()))
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4861
diff changeset
257 .replace("@SD-SIZE@", str(dial.sdSize()))
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4861
diff changeset
258 )
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4861
diff changeset
259
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4861
diff changeset
260 return page

eric ide

mercurial