6 """ |
6 """ |
7 Module implementing a scheme handler for the eric: scheme. |
7 Module implementing a scheme handler for the eric: scheme. |
8 """ |
8 """ |
9 |
9 |
10 from PyQt5.QtCore import ( |
10 from PyQt5.QtCore import ( |
11 pyqtSignal, QByteArray, QBuffer, QIODevice, QUrlQuery, QMutex, QMutexLocker |
11 pyqtSignal, QByteArray, QBuffer, QIODevice, QUrlQuery, QMutex |
12 ) |
12 ) |
13 from PyQt5.QtWebEngineCore import QWebEngineUrlSchemeHandler |
13 from PyQt5.QtWebEngineCore import QWebEngineUrlSchemeHandler |
14 |
14 |
15 from E5Gui.E5Application import e5App |
15 from E5Gui.E5Application import e5App |
|
16 |
|
17 from E5Utilities.E5MutexLocker import E5MutexLocker |
16 |
18 |
17 from ..Tools.WebBrowserTools import ( |
19 from ..Tools.WebBrowserTools import ( |
18 getHtmlPage, getJavascript, pixmapFileToDataUrl |
20 getHtmlPage, getJavascript, pixmapFileToDataUrl |
19 ) |
21 ) |
20 |
22 |
102 Private method to load the requested page. |
104 Private method to load the requested page. |
103 """ |
105 """ |
104 if self.__loaded: |
106 if self.__loaded: |
105 return |
107 return |
106 |
108 |
107 lock = QMutexLocker(self.__mutex) |
109 with E5MutexLocker(self.__mutex): |
108 |
110 if self.__pageName == "adblock": |
109 if self.__pageName == "adblock": |
111 contents = self.__adBlockPage() |
110 contents = self.__adBlockPage() |
112 elif self.__pageName in ["home", "start", "startpage"]: |
111 elif self.__pageName in ["home", "start", "startpage"]: |
113 contents = self.__startPage() |
112 contents = self.__startPage() |
114 elif self.__pageName == "speeddial": |
113 elif self.__pageName == "speeddial": |
115 contents = self.__speedDialPage() |
114 contents = self.__speedDialPage() |
116 else: |
115 else: |
117 contents = "" |
116 contents = "" |
118 |
117 |
119 self.__buffer.setData(contents.encode("utf-8")) |
118 self.__buffer.setData(contents.encode("utf-8")) |
120 self.__buffer.open(QIODevice.ReadOnly) |
119 self.__buffer.open(QIODevice.ReadOnly) |
121 self.open(QIODevice.ReadOnly) |
120 self.open(QIODevice.ReadOnly) |
|
121 lock.unlock() |
|
122 |
122 |
123 self.readyRead.emit() |
123 self.readyRead.emit() |
124 |
124 |
125 self.__loaded = True |
125 self.__loaded = True |
126 |
126 |
129 Public method to get the number of available bytes. |
129 Public method to get the number of available bytes. |
130 |
130 |
131 @return number of available bytes |
131 @return number of available bytes |
132 @rtype int |
132 @rtype int |
133 """ |
133 """ |
134 lock = QMutexLocker(self.__mutex) # __IGNORE_WARNING__ |
134 with E5MutexLocker(self.__mutex): |
135 return self.__buffer.bytesAvailable() |
135 return self.__buffer.bytesAvailable() |
136 |
136 |
137 def readData(self, maxlen): |
137 def readData(self, maxlen): |
138 """ |
138 """ |
139 Public method to retrieve data from the reply object. |
139 Public method to retrieve data from the reply object. |
140 |
140 |
141 @param maxlen maximum number of bytes to read (integer) |
141 @param maxlen maximum number of bytes to read (integer) |
142 @return string containing the data (bytes) |
142 @return string containing the data (bytes) |
143 """ |
143 """ |
144 lock = QMutexLocker(self.__mutex) # __IGNORE_WARNING__ |
144 with E5MutexLocker(self.__mutex): |
145 return self.__buffer.read(maxlen) |
145 return self.__buffer.read(maxlen) |
146 |
146 |
147 def close(self): |
147 def close(self): |
148 """ |
148 """ |
149 Public method used to cloase the reply. |
149 Public method used to cloase the reply. |
150 """ |
150 """ |