5 |
5 |
6 """ |
6 """ |
7 Module implementing a scheme access handler for QtHelp. |
7 Module implementing a scheme access handler for QtHelp. |
8 """ |
8 """ |
9 |
9 |
10 |
|
11 import mimetypes |
10 import mimetypes |
12 import os |
11 import os |
13 |
12 |
14 from PyQt5.QtCore import ( |
13 from PyQt5.QtCore import ( |
15 pyqtSignal, QByteArray, QIODevice, QBuffer, QMutex, QMutexLocker |
14 pyqtSignal, QByteArray, QIODevice, QBuffer, QMutex |
16 ) |
15 ) |
17 from PyQt5.QtWebEngineCore import ( |
16 from PyQt5.QtWebEngineCore import ( |
18 QWebEngineUrlSchemeHandler, QWebEngineUrlRequestJob |
17 QWebEngineUrlSchemeHandler, QWebEngineUrlRequestJob |
19 ) |
18 ) |
|
19 |
|
20 from E5Utilities.E5MutexLocker import E5MutexLocker |
20 |
21 |
21 QtDocPath = "qthelp://org.qt-project." |
22 QtDocPath = "qthelp://org.qt-project." |
22 |
23 |
23 ExtensionMap = { |
24 ExtensionMap = { |
24 ".bmp": "image/bmp", |
25 ".bmp": "image/bmp", |
167 """<h1>The page could not be found</h1><br>""" |
168 """<h1>The page could not be found</h1><br>""" |
168 """<h3>'{0}'</h3></div></body>""" |
169 """<h3>'{0}'</h3></div></body>""" |
169 """</html>""").format(url.toString()) |
170 """</html>""").format(url.toString()) |
170 .encode("utf-8")) |
171 .encode("utf-8")) |
171 |
172 |
172 lock = QMutexLocker(self.__mutex) |
173 with E5MutexLocker(self.__mutex): |
173 self.__buffer.setData(data) |
174 self.__buffer.setData(data) |
174 self.__buffer.open(QIODevice.ReadOnly) |
175 self.__buffer.open(QIODevice.ReadOnly) |
175 self.open(QIODevice.ReadOnly) |
176 self.open(QIODevice.ReadOnly) |
176 lock.unlock() |
|
177 |
177 |
178 self.readyRead.emit() |
178 self.readyRead.emit() |
179 |
179 |
180 def bytesAvailable(self): |
180 def bytesAvailable(self): |
181 """ |
181 """ |
182 Public method to get the number of available bytes. |
182 Public method to get the number of available bytes. |
183 |
183 |
184 @return number of available bytes |
184 @return number of available bytes |
185 @rtype int |
185 @rtype int |
186 """ |
186 """ |
187 lock = QMutexLocker(self.__mutex) # __IGNORE_WARNING__ |
187 with E5MutexLocker(self.__mutex): |
188 return self.__buffer.bytesAvailable() |
188 return self.__buffer.bytesAvailable() |
189 |
189 |
190 def readData(self, maxlen): |
190 def readData(self, maxlen): |
191 """ |
191 """ |
192 Public method to retrieve data from the reply object. |
192 Public method to retrieve data from the reply object. |
193 |
193 |
194 @param maxlen maximum number of bytes to read (integer) |
194 @param maxlen maximum number of bytes to read (integer) |
195 @return string containing the data (bytes) |
195 @return string containing the data (bytes) |
196 """ |
196 """ |
197 lock = QMutexLocker(self.__mutex) # __IGNORE_WARNING__ |
197 with E5MutexLocker(self.__mutex): |
198 return self.__buffer.read(maxlen) |
198 return self.__buffer.read(maxlen) |
199 |
199 |
200 def close(self): |
200 def close(self): |
201 """ |
201 """ |
202 Public method used to cloase the reply. |
202 Public method used to cloase the reply. |
203 """ |
203 """ |