eric6/WebBrowser/Tools/WebBrowserTools.py

Tue, 02 Mar 2021 17:17:09 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 02 Mar 2021 17:17:09 +0100
changeset 8143
2c730d5fd177
parent 7923
91e843545d9a
child 8221
0572a215bd2f
permissions
-rw-r--r--

Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.

4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
b19ff70ba509 Continued porting the web browser.
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) 2016 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing tool functions for the web browser.
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
4763
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
10 import os
4810
f68d0446609e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
11 import re
7717
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
12 import mimetypes
4763
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
13
7270
41d09cf20415 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
14 from PyQt5.QtCore import (
41d09cf20415 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
15 QFile, QByteArray, QUrl, QCoreApplication, QBuffer, QIODevice
41d09cf20415 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
16 )
4783
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
17 from PyQt5.QtGui import QPixmap
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19
7717
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
20 WebBrowserDataDirectory = {
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
21 "html": os.path.join(os.path.dirname(__file__), "..", "data", "html"),
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
22 "icons": os.path.join(os.path.dirname(__file__), "..", "data", "icons"),
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
23 "js": os.path.join(os.path.dirname(__file__), "..", "data", "javascript"),
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
24 }
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
25
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
26
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 def readAllFileContents(filename):
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 """
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 Function to read the string contents of the given file.
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 @param filename name of the file
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 @type str
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 @return contents of the file
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 @rtype str
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 """
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 return str(readAllFileByteContents(filename), encoding="utf-8")
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 def readAllFileByteContents(filename):
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 """
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 Function to read the bytes contents of the given file.
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 @param filename name of the file
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 @type str
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 @return contents of the file
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 @rtype str
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 """
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 dataFile = QFile(filename)
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 if filename and dataFile.open(QFile.ReadOnly):
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 contents = dataFile.readAll()
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 dataFile.close()
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 return contents
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 return QByteArray()
4741
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
55
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
56
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
57 def containsSpace(string):
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
58 """
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
59 Function to check, if a string contains whitespace characters.
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
60
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
61 @param string string to be checked
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
62 @type str
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
63 @return flag indicating the presence of at least one whitespace character
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
64 @rtype bool
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
65 """
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
66 for ch in string:
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
67 if ch.isspace():
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
68 return True
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
69
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
70 return False
4763
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
71
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
72
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
73 def ensureUniqueFilename(name, appendFormat="({0})"):
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
74 """
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
75 Module function to generate an unique file name based on a pattern.
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
76
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
77 @param name desired file name (string)
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
78 @param appendFormat format pattern to be used to make the unique name
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
79 (string)
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
80 @return unique file name
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
81 """
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
82 if not os.path.exists(name):
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
83 return name
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
84
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
85 tmpFileName = name
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
86 i = 1
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
87 while os.path.exists(tmpFileName):
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
88 tmpFileName = name
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
89 index = tmpFileName.rfind(".")
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
90
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
91 appendString = appendFormat.format(i)
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
92 if index == -1:
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
93 tmpFileName += appendString
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
94 else:
7270
41d09cf20415 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
95 tmpFileName = (
41d09cf20415 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
96 tmpFileName[:index] + appendString + tmpFileName[index:]
41d09cf20415 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
97 )
4763
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
98 i += 1
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
99
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
100 return tmpFileName
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
101
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
102
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
103 def getFileNameFromUrl(url):
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
104 """
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
105 Module function to generate a file name based on the given URL.
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
106
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
107 @param url URL (QUrl)
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
108 @return file name (string)
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
109 """
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
110 fileName = url.toString(
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
111 QUrl.UrlFormattingOption.RemoveFragment |
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
112 QUrl.UrlFormattingOption.RemoveQuery |
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
113 QUrl.UrlFormattingOption.RemoveScheme |
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
114 QUrl.UrlFormattingOption.RemovePort
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
115 )
4763
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
116 if fileName.find("/") != -1:
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
117 pos = fileName.rfind("/")
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
118 fileName = fileName[pos:]
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
119 fileName = fileName.replace("/", "")
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
120
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
121 fileName = filterCharsFromFilename(fileName)
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
122
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
123 if not fileName:
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
124 fileName = filterCharsFromFilename(url.host().replace(".", "_"))
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
125
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
126 return fileName
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
127
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
128
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
129 def filterCharsFromFilename(name):
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
130 """
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
131 Module function to filter illegal characters.
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
132
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
133 @param name name to be sanitized (string)
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
134 @return sanitized name (string)
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
135 """
7270
41d09cf20415 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
136 return (
41d09cf20415 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
137 name
41d09cf20415 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
138 .replace("/", "_")
41d09cf20415 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
139 .replace("\\", "")
41d09cf20415 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
140 .replace(":", "")
41d09cf20415 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
141 .replace("*", "")
41d09cf20415 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
142 .replace("?", "")
41d09cf20415 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
143 .replace('"', "")
41d09cf20415 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
144 .replace("<", "")
41d09cf20415 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
145 .replace(">", "")
4763
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
146 .replace("|", "")
7270
41d09cf20415 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
147 )
4783
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
148
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
149
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
150 def pixmapFromByteArray(data):
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
151 """
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
152 Module function to convert a byte array to a pixmap.
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
153
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
154 @param data data for the pixmap
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
155 @type bytes or QByteArray
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
156 @return extracted pixmap
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
157 @rtype QPixmap
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
158 """
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
159 pixmap = QPixmap()
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
160 barray = QByteArray.fromBase64(data)
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
161 pixmap.loadFromData(barray)
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
162
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
163 return pixmap
4810
f68d0446609e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
164
f68d0446609e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
165
4865
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
166 def pixmapToByteArray(pixmap):
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
167 """
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
168 Module function to convert a pixmap to a byte array containing the pixmap
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
169 as a PNG encoded as base64.
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
170
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
171 @param pixmap pixmap to be converted
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
172 @type QPixmap
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
173 @return byte array containing the pixmap
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
174 @rtype QByteArray
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
175 """
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
176 byteArray = QByteArray()
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
177 buffer = QBuffer(byteArray)
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
178 buffer.open(QIODevice.OpenModeFlag.WriteOnly)
4865
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
179 if pixmap.save(buffer, "PNG"):
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
180 return buffer.buffer().toBase64()
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
181
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
182 return QByteArray()
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
183
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
184
7717
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
185 def pixmapToDataUrl(pixmap, mimetype="image/png"):
4865
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
186 """
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
187 Module function to convert a pixmap to a data: URL.
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
188
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
189 @param pixmap pixmap to be converted
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
190 @type QPixmap
7732
4c9cf117acf6 Fixed some code style issues and one coding issue.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7717
diff changeset
191 @param mimetype MIME type to be used
4c9cf117acf6 Fixed some code style issues and one coding issue.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7717
diff changeset
192 @type str
4865
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
193 @return data: URL
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
194 @rtype QUrl
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
195 """
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
196 data = bytes(pixmapToByteArray(pixmap)).decode()
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
197 if data:
7717
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
198 return QUrl("data:{0};base64,{1}".format(mimetype, data))
4865
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
199 else:
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
200 return QUrl()
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
201
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
202
7717
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
203 def pixmapFileToDataUrl(pixmapFile, asString=False):
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
204 """
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
205 Module function to load a pixmap file and convert the pixmap to a
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
206 data: URL.
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
207
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
208 Note: If the given pixmap file path is not absolute, it is assumed to
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
209 denote a pixmap file in the icons data directory.
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
210
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
211 @param pixmapFile file name of the pixmap file
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
212 @type str
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
213 @param asString flag indicating a string representation is requested
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
214 @type bool
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
215 @return data: URL
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
216 @rtype QUrl or str
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
217 """
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
218 if not os.path.isabs(pixmapFile):
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
219 pixmapFile = os.path.join(WebBrowserDataDirectory["icons"], pixmapFile)
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
220
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
221 mime = mimetypes.guess_type(pixmapFile, strict=False)[0]
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
222 if mime is None:
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
223 # assume PNG file
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
224 mime = "image/png"
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
225 url = pixmapToDataUrl(QPixmap(pixmapFile), mimetype=mime)
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
226
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
227 if asString:
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
228 return url.toString()
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
229 else:
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
230 return url
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
231
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
232
4810
f68d0446609e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
233 def getWebEngineVersions():
f68d0446609e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
234 """
f68d0446609e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
235 Module function to extract the web engine version from the default user
f68d0446609e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
236 agent string.
f68d0446609e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
237
f68d0446609e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
238 @return tuple containing the Chrome version and the QtWebEngine version
f68d0446609e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
239 @rtype tuple of str
f68d0446609e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
240 """
6630
bddd12f27a4c Web Browser (QtWebKit): applied the changes of the new Web Brwoser to the QtWebKit based variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
241 from PyQt5.QtWebEngineWidgets import QWebEngineProfile
bddd12f27a4c Web Browser (QtWebKit): applied the changes of the new Web Brwoser to the QtWebKit based variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
242
bddd12f27a4c Web Browser (QtWebKit): applied the changes of the new Web Brwoser to the QtWebKit based variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
243 useragent = QWebEngineProfile.defaultProfile().httpUserAgent()
4810
f68d0446609e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
244 match = re.search(r"""Chrome/([\d.]+)""", useragent)
f68d0446609e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
245 if match:
f68d0446609e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
246 chromeVersion = match.group(1)
f68d0446609e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
247 else:
f68d0446609e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
248 chromeVersion = QCoreApplication.translate(
f68d0446609e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
249 "WebBrowserTools", "<unknown>")
f68d0446609e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
250 match = re.search(r"""QtWebEngine/([\d.]+)""", useragent)
f68d0446609e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
251 if match:
f68d0446609e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
252 webengineVersion = match.group(1)
f68d0446609e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
253 else:
f68d0446609e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
254 webengineVersion = QCoreApplication.translate(
f68d0446609e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
255 "WebBrowserTools", "<unknown>")
f68d0446609e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
256 return (chromeVersion, webengineVersion)
7717
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
257
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
258
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
259 def getHtmlPage(pageFileName):
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
260 """
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
261 Module function to load a HTML page.
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
262
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
263 Note: If the given HTML file path is not absolute, it is assumed to
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
264 denote a HTML file in the html data directory.
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
265
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
266 @param pageFileName file name of the HTML file
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
267 @type str
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
268 @return HTML page
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
269 @rtype str
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
270 """
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
271 if not os.path.isabs(pageFileName):
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
272 pageFileName = os.path.join(
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
273 WebBrowserDataDirectory["html"], pageFileName)
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
274
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
275 return readAllFileContents(pageFileName)
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
276
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
277
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
278 def getJavascript(jsFileName):
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
279 """
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
280 Module function to load a JavaScript source file.
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
281
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
282 Note: If the given JavaScript source file path is not absolute, it is
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
283 assumed to denote a JavaScript source file in the javascript data
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
284 directory.
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
285
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
286 @param jsFileName file name of the JavaScript source file
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
287 @type str
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
288 @return JavaScript source
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
289 @rtype str
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
290 """
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
291 if not os.path.isabs(jsFileName):
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
292 jsFileName = os.path.join(
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
293 WebBrowserDataDirectory["js"], jsFileName)
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
294
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
295 return readAllFileContents(jsFileName)

eric ide

mercurial