eric6/WebBrowser/Network/QtHelpSchemeHandler.py

Sat, 27 Feb 2021 12:08:23 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 27 Feb 2021 12:08:23 +0100
changeset 8138
169e65a6787c
parent 7923
91e843545d9a
child 8043
0acf98cd089a
child 8143
2c730d5fd177
permissions
-rw-r--r--

Shell: added functionality to show a prompt when the main client process has exited (e.g. a script ended).

0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7923
91e843545d9a Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7781
diff changeset
3 # Copyright (c) 2009 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a scheme access handler for QtHelp.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
641
b06d4df23797 Fixed an issue in the web browser related to webkit and Qt help and fixed an issue introduced by the latest refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 168
diff changeset
10 import mimetypes
b06d4df23797 Fixed an issue in the web browser related to webkit and Qt help and fixed an issue introduced by the latest refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 168
diff changeset
11 import os
b06d4df23797 Fixed an issue in the web browser related to webkit and Qt help and fixed an issue introduced by the latest refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 168
diff changeset
12
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
13 from PyQt5.QtCore import (
7774
9eed155411f0 Changed code to our own context manager type mutex locker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
14 pyqtSignal, QByteArray, QIODevice, QBuffer, QMutex
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
15 )
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
16 from PyQt5.QtWebEngineCore import (
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
17 QWebEngineUrlSchemeHandler, QWebEngineUrlRequestJob
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
18 )
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19
7774
9eed155411f0 Changed code to our own context manager type mutex locker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
20 from E5Utilities.E5MutexLocker import E5MutexLocker
9eed155411f0 Changed code to our own context manager type mutex locker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
21
4875
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
22 QtDocPath = "qthelp://org.qt-project."
641
b06d4df23797 Fixed an issue in the web browser related to webkit and Qt help and fixed an issue introduced by the latest refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 168
diff changeset
23
b06d4df23797 Fixed an issue in the web browser related to webkit and Qt help and fixed an issue introduced by the latest refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 168
diff changeset
24 ExtensionMap = {
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
25 ".bmp": "image/bmp",
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
26 ".css": "text/css",
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
27 ".gif": "image/gif",
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
28 ".html": "text/html",
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
29 ".htm": "text/html",
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
30 ".ico": "image/x-icon",
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
31 ".jpeg": "image/jpeg",
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
32 ".jpg": "image/jpeg",
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
33 ".js": "application/x-javascript",
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
34 ".mng": "video/x-mng",
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
35 ".pbm": "image/x-portable-bitmap",
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
36 ".pgm": "image/x-portable-graymap",
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
37 ".pdf": "application/pdf",
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
38 ".png": "image/png",
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
39 ".ppm": "image/x-portable-pixmap",
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
40 ".rss": "application/rss+xml",
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
41 ".svg": "image/svg+xml",
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
42 ".svgz": "image/svg+xml",
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
43 ".text": "text/plain",
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
44 ".tif": "image/tiff",
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
45 ".tiff": "image/tiff",
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
46 ".txt": "text/plain",
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
47 ".xbm": "image/x-xbitmap",
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
48 ".xml": "text/xml",
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
49 ".xpm": "image/x-xpm",
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
50 ".xsl": "text/xsl",
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
51 ".xhtml": "application/xhtml+xml",
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
52 ".wml": "text/vnd.wap.wml",
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
53 ".wmlc": "application/vnd.wap.wmlc",
641
b06d4df23797 Fixed an issue in the web browser related to webkit and Qt help and fixed an issue introduced by the latest refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 168
diff changeset
54 }
b06d4df23797 Fixed an issue in the web browser related to webkit and Qt help and fixed an issue introduced by the latest refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 168
diff changeset
55
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
56
4875
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
57 class QtHelpSchemeHandler(QWebEngineUrlSchemeHandler):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 """
4875
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
59 Class implementing a scheme handler for the qthelp: scheme.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 """
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
61 def __init__(self, engine, parent=None):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 Constructor
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64
4875
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
65 @param engine reference to the help engine
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
66 @type QHelpEngine
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
67 @param parent reference to the parent object
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
68 @type QObject
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 """
4875
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
70 super(QtHelpSchemeHandler, self).__init__(parent)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 self.__engine = engine
4875
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
73
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
74 self.__replies = []
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
75
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
76 def requestStarted(self, job):
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
77 """
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
78 Public method handling the URL request.
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
79
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
80 @param job URL request job
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
81 @type QWebEngineUrlRequestJob
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
82 """
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
83 if job.requestUrl().scheme() == "qthelp":
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
84 reply = QtHelpSchemeReply(job, self.__engine)
6120
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
85 reply.closed.connect(lambda: self.__replyClosed(reply))
4875
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
86 self.__replies.append(reply)
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
87 job.reply(reply.mimeType(), reply)
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
88 else:
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
89 job.fail(QWebEngineUrlRequestJob.UrlInvalid)
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
90
6120
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
91 def __replyClosed(self, reply):
4875
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
92 """
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
93 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
94
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
95 @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
96 @type QtHelpSchemeReply
4875
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
97 """
6120
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
98 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
99 self.__replies.remove(reply)
4875
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
100
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
101
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
102 class QtHelpSchemeReply(QIODevice):
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
103 """
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
104 Class implementing a reply for a requested qthelp: page.
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
105
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
106 @signal closed emitted to signal that the web engine has read
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
107 the data
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
108 """
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
109 closed = pyqtSignal()
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
110
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
111 def __init__(self, job, engine, parent=None):
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
112 """
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
113 Constructor
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
114
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
115 @param job reference to the URL request
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
116 @type QWebEngineUrlRequestJob
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
117 @param engine reference to the help engine
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
118 @type QHelpEngine
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
119 @param parent reference to the parent object
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
120 @type QObject
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
121 """
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
122 super(QtHelpSchemeReply, self).__init__(parent)
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
123
6507
54054456ca58 EricSchemeHandler, QtHelpSchemeHandler: ensure, that data is loaded in the main thread.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
124 self.__job = job
54054456ca58 EricSchemeHandler, QtHelpSchemeHandler: ensure, that data is loaded in the main thread.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
125 self.__engine = engine
54054456ca58 EricSchemeHandler, QtHelpSchemeHandler: ensure, that data is loaded in the main thread.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
126 self.__mutex = QMutex()
4875
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
127
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
128 self.__buffer = QBuffer()
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
129
6507
54054456ca58 EricSchemeHandler, QtHelpSchemeHandler: ensure, that data is loaded in the main thread.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
130 # determine mimetype
54054456ca58 EricSchemeHandler, QtHelpSchemeHandler: ensure, that data is loaded in the main thread.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
131 url = self.__job.requestUrl()
54054456ca58 EricSchemeHandler, QtHelpSchemeHandler: ensure, that data is loaded in the main thread.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
132 strUrl = url.toString()
54054456ca58 EricSchemeHandler, QtHelpSchemeHandler: ensure, that data is loaded in the main thread.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
133
4875
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
134 # For some reason the url to load maybe wrong (passed from web engine)
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
135 # though the css file and the references inside should work that way.
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
136 # One possible problem might be that the css is loaded at the same
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
137 # level as the html, thus a path inside the css like
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
138 # (../images/foo.png) might cd out of the virtual folder
6507
54054456ca58 EricSchemeHandler, QtHelpSchemeHandler: ensure, that data is loaded in the main thread.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
139 if not self.__engine.findFile(url).isValid():
4875
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
140 if strUrl.startswith(QtDocPath):
6507
54054456ca58 EricSchemeHandler, QtHelpSchemeHandler: ensure, that data is loaded in the main thread.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
141 newUrl = self.__job.requestUrl()
4875
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
142 if not newUrl.path().startswith("/qdoc/"):
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
143 newUrl.setPath("/qdoc" + newUrl.path())
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
144 url = newUrl
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
145 strUrl = url.toString()
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
146
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
147 self.__mimeType = mimetypes.guess_type(strUrl)[0]
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
148 if self.__mimeType is None:
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
149 # do our own (limited) guessing
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
150 self.__mimeType = self.__mimeFromUrl(url)
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
151
6540
978df36d2f4d QtHelpSchemeHandler: changed the way the Qt help pages are loaded again in order to get rid of some crash situations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6531
diff changeset
152 self.__loadQtHelpPage(url)
6507
54054456ca58 EricSchemeHandler, QtHelpSchemeHandler: ensure, that data is loaded in the main thread.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
153
54054456ca58 EricSchemeHandler, QtHelpSchemeHandler: ensure, that data is loaded in the main thread.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
154 def __loadQtHelpPage(self, url):
54054456ca58 EricSchemeHandler, QtHelpSchemeHandler: ensure, that data is loaded in the main thread.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
155 """
54054456ca58 EricSchemeHandler, QtHelpSchemeHandler: ensure, that data is loaded in the main thread.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
156 Private method to load the requested QtHelp page.
54054456ca58 EricSchemeHandler, QtHelpSchemeHandler: ensure, that data is loaded in the main thread.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
157
54054456ca58 EricSchemeHandler, QtHelpSchemeHandler: ensure, that data is loaded in the main thread.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
158 @param url URL of the requested page
54054456ca58 EricSchemeHandler, QtHelpSchemeHandler: ensure, that data is loaded in the main thread.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
159 @type QUrl
54054456ca58 EricSchemeHandler, QtHelpSchemeHandler: ensure, that data is loaded in the main thread.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
160 """
54054456ca58 EricSchemeHandler, QtHelpSchemeHandler: ensure, that data is loaded in the main thread.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
161 if self.__engine.findFile(url).isValid():
54054456ca58 EricSchemeHandler, QtHelpSchemeHandler: ensure, that data is loaded in the main thread.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
162 data = self.__engine.fileData(url)
4875
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
163 else:
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
164 data = QByteArray(self.tr(
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
165 """<html>"""
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
166 """<head><title>Error 404...</title></head>"""
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
167 """<body><div align="center"><br><br>"""
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
168 """<h1>The page could not be found</h1><br>"""
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
169 """<h3>'{0}'</h3></div></body>"""
6507
54054456ca58 EricSchemeHandler, QtHelpSchemeHandler: ensure, that data is loaded in the main thread.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
170 """</html>""").format(url.toString())
4875
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
171 .encode("utf-8"))
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
172
7774
9eed155411f0 Changed code to our own context manager type mutex locker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
173 with E5MutexLocker(self.__mutex):
9eed155411f0 Changed code to our own context manager type mutex locker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
174 self.__buffer.setData(data)
9eed155411f0 Changed code to our own context manager type mutex locker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
175 self.__buffer.open(QIODevice.ReadOnly)
9eed155411f0 Changed code to our own context manager type mutex locker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
176 self.open(QIODevice.ReadOnly)
6507
54054456ca58 EricSchemeHandler, QtHelpSchemeHandler: ensure, that data is loaded in the main thread.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
177
54054456ca58 EricSchemeHandler, QtHelpSchemeHandler: ensure, that data is loaded in the main thread.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
178 self.readyRead.emit()
4875
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
179
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
180 def bytesAvailable(self):
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
181 """
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
182 Public method to get the number of available bytes.
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
183
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
184 @return number of available bytes
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
185 @rtype int
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
186 """
7774
9eed155411f0 Changed code to our own context manager type mutex locker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
187 with E5MutexLocker(self.__mutex):
9eed155411f0 Changed code to our own context manager type mutex locker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
188 return self.__buffer.bytesAvailable()
4875
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
189
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
190 def readData(self, maxlen):
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
191 """
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
192 Public method to retrieve data from the reply object.
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
193
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
194 @param maxlen maximum number of bytes to read (integer)
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
195 @return string containing the data (bytes)
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
196 """
7774
9eed155411f0 Changed code to our own context manager type mutex locker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
197 with E5MutexLocker(self.__mutex):
9eed155411f0 Changed code to our own context manager type mutex locker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
198 return self.__buffer.read(maxlen)
4875
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
199
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
200 def close(self):
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
201 """
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
202 Public method used to cloase the reply.
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
203 """
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
204 super(QtHelpSchemeReply, self).close()
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
205 self.closed.emit()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
206
641
b06d4df23797 Fixed an issue in the web browser related to webkit and Qt help and fixed an issue introduced by the latest refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 168
diff changeset
207 def __mimeFromUrl(self, url):
b06d4df23797 Fixed an issue in the web browser related to webkit and Qt help and fixed an issue introduced by the latest refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 168
diff changeset
208 """
b06d4df23797 Fixed an issue in the web browser related to webkit and Qt help and fixed an issue introduced by the latest refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 168
diff changeset
209 Private method to guess the mime type given an URL.
b06d4df23797 Fixed an issue in the web browser related to webkit and Qt help and fixed an issue introduced by the latest refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 168
diff changeset
210
b06d4df23797 Fixed an issue in the web browser related to webkit and Qt help and fixed an issue introduced by the latest refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 168
diff changeset
211 @param url URL to guess the mime type from (QUrl)
2954
bf0215fe12d1 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
212 @return mime type for the given URL (string)
641
b06d4df23797 Fixed an issue in the web browser related to webkit and Qt help and fixed an issue introduced by the latest refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 168
diff changeset
213 """
b06d4df23797 Fixed an issue in the web browser related to webkit and Qt help and fixed an issue introduced by the latest refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 168
diff changeset
214 path = url.path()
b06d4df23797 Fixed an issue in the web browser related to webkit and Qt help and fixed an issue introduced by the latest refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 168
diff changeset
215 ext = os.path.splitext(path)[1].lower()
b06d4df23797 Fixed an issue in the web browser related to webkit and Qt help and fixed an issue introduced by the latest refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 168
diff changeset
216 if ext in ExtensionMap:
b06d4df23797 Fixed an issue in the web browser related to webkit and Qt help and fixed an issue introduced by the latest refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 168
diff changeset
217 return ExtensionMap[ext]
b06d4df23797 Fixed an issue in the web browser related to webkit and Qt help and fixed an issue introduced by the latest refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 168
diff changeset
218 else:
b06d4df23797 Fixed an issue in the web browser related to webkit and Qt help and fixed an issue introduced by the latest refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 168
diff changeset
219 return "application/octet-stream"
b06d4df23797 Fixed an issue in the web browser related to webkit and Qt help and fixed an issue introduced by the latest refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 168
diff changeset
220
4875
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
221 def mimeType(self):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
222 """
4875
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
223 Public method to get the reply mime type.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
224
4875
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
225 @return mime type of the reply
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
226 @rtype bytes
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
227 """
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
228 return self.__mimeType.encode("utf-8")

eric ide

mercurial