src/eric7/WebBrowser/Tools/WebBrowserTools.py

Mon, 24 Feb 2025 15:43:49 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Mon, 24 Feb 2025 15:43:49 +0100
branch
eric7
changeset 11148
15e30f0c76a8
parent 11090
f5f5f5803935
permissions
-rw-r--r--

Adjusted the code to the modified issue codes.

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
11090
f5f5f5803935 Updated copyright for 2025.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10439
diff changeset
3 # Copyright (c) 2016 - 2025 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
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
10 import mimetypes
4763
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
11 import os
4810
f68d0446609e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
12 import re
4763
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
13
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
14 from PyQt6.QtCore import QBuffer, QByteArray, QCoreApplication, QIODevice, QUrl
8318
962bce857696 Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8312
diff changeset
15 from PyQt6.QtGui import QPixmap
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
9672
335f695d59e7 Changed loading of the JQuery libraries into the speeddial page so that a system wide library is loaded in case the internal one has been removed (e.g. by distro package maintainers).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
17 from eric7.SystemUtilities import OSUtilities
335f695d59e7 Changed loading of the JQuery libraries into the speeddial page so that a system wide library is loaded in case the internal one has been removed (e.g. by distro package maintainers).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
18
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
19 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
20 "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
21 "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
22 "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
23 }
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
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 def readAllFileContents(filename):
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 """
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 Function to read the string contents of the given file.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
29
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 @param filename name of the file
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 @type str
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 @return contents of the file
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 @rtype str
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 """
9162
8b75b1668583 Changed some use of QFile() to a more pythonic solution and fixed a few issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8881
diff changeset
35 try:
8b75b1668583 Changed some use of QFile() to a more pythonic solution and fixed a few issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8881
diff changeset
36 with open(filename, "r", encoding="utf-8") as f:
8b75b1668583 Changed some use of QFile() to a more pythonic solution and fixed a few issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8881
diff changeset
37 return f.read()
8b75b1668583 Changed some use of QFile() to a more pythonic solution and fixed a few issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8881
diff changeset
38 except OSError:
8b75b1668583 Changed some use of QFile() to a more pythonic solution and fixed a few issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8881
diff changeset
39 return ""
4741
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
40
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
41
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
42 def containsSpace(string):
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
43 """
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
44 Function to check, if a string contains whitespace characters.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
45
4741
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
46 @param string string to be checked
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
47 @type str
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
48 @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
49 @rtype bool
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
50 """
8221
0572a215bd2f Applied some more code simplifications suggested by the new Simplify checker (Y110, Y111: use any() or all()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8143
diff changeset
51 return any(ch.isspace() for ch in string)
4763
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
52
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
53
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
54 def ensureUniqueFilename(name, appendFormat="({0})"):
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
55 """
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
56 Module function to generate an unique file name based on a pattern.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
57
10436
f6881d10e995 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
58 @param name desired file name
f6881d10e995 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
59 @type str
4763
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
60 @param appendFormat format pattern to be used to make the unique name
10436
f6881d10e995 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
61 @type str
4763
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
62 @return unique file name
10436
f6881d10e995 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
63 @rtype str
4763
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
64 """
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
65 if not os.path.exists(name):
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
66 return name
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
67
4763
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
68 tmpFileName = name
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
69 i = 1
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
70 while os.path.exists(tmpFileName):
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
71 tmpFileName = name
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
72 index = tmpFileName.rfind(".")
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
73
4763
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
74 appendString = appendFormat.format(i)
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
75 if index == -1:
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
76 tmpFileName += appendString
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
77 else:
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
78 tmpFileName = tmpFileName[:index] + appendString + tmpFileName[index:]
4763
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
79 i += 1
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
80
4763
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
81 return tmpFileName
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
82
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
83
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
84 def getFileNameFromUrl(url):
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
85 """
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
86 Module function to generate a file name based on the given URL.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
87
10436
f6881d10e995 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
88 @param url URL
f6881d10e995 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
89 @type QUrl
f6881d10e995 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
90 @return file name
f6881d10e995 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
91 @rtype str
4763
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
92 """
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
93 fileName = url.toString(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
94 QUrl.UrlFormattingOption.RemoveFragment
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
95 | QUrl.UrlFormattingOption.RemoveQuery
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
96 | QUrl.UrlFormattingOption.RemoveScheme
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
97 | QUrl.UrlFormattingOption.RemovePort
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
98 )
4763
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
99 if fileName.find("/") != -1:
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
100 pos = fileName.rfind("/")
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
101 fileName = fileName[pos:]
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
102 fileName = fileName.replace("/", "")
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
103
4763
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
104 fileName = filterCharsFromFilename(fileName)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
105
4763
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
106 if not fileName:
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
107 fileName = filterCharsFromFilename(url.host().replace(".", "_"))
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
108
4763
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
109 return fileName
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
110
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
111
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
112 def filterCharsFromFilename(name):
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
113 """
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
114 Module function to filter illegal characters.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
115
10436
f6881d10e995 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
116 @param name name to be sanitized
f6881d10e995 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
117 @type str
f6881d10e995 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
118 @return sanitized name
f6881d10e995 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10339
diff changeset
119 @rtype str
4763
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
120 """
7270
41d09cf20415 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
121 return (
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
122 name.replace("/", "_")
7270
41d09cf20415 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
123 .replace("\\", "")
41d09cf20415 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
124 .replace(":", "")
41d09cf20415 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
125 .replace("*", "")
41d09cf20415 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
126 .replace("?", "")
41d09cf20415 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
127 .replace('"', "")
41d09cf20415 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
128 .replace("<", "")
41d09cf20415 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
129 .replace(">", "")
4763
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
130 .replace("|", "")
7270
41d09cf20415 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
131 )
4783
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
132
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
133
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
134 def pixmapFromByteArray(data):
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
135 """
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
136 Module function to convert a byte array to a pixmap.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
137
4783
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
138 @param data data for the pixmap
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
139 @type bytes or QByteArray
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
140 @return extracted pixmap
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
141 @rtype QPixmap
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
142 """
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
143 pixmap = QPixmap()
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
144 barray = QByteArray.fromBase64(data)
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
145 pixmap.loadFromData(barray)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
146
4783
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
147 return pixmap
4810
f68d0446609e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
148
f68d0446609e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
149
4865
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
150 def pixmapToByteArray(pixmap):
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
151 """
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
152 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
153 as a PNG encoded as base64.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
154
4865
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
155 @param pixmap pixmap to be converted
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
156 @type QPixmap
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
157 @return byte array containing the pixmap
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
158 @rtype QByteArray
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
159 """
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
160 byteArray = QByteArray()
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
161 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
162 buffer.open(QIODevice.OpenModeFlag.WriteOnly)
4865
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
163 if pixmap.save(buffer, "PNG"):
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
164 return buffer.buffer().toBase64()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
165
4865
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
166 return QByteArray()
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
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
169 def pixmapToDataUrl(pixmap, mimetype="image/png"):
4865
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 Module function to convert a pixmap to a data: URL.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
172
4865
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
173 @param pixmap pixmap to be converted
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
174 @type QPixmap
7732
4c9cf117acf6 Fixed some code style issues and one coding issue.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7717
diff changeset
175 @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
176 @type str
4865
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
177 @return data: URL
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
178 @rtype QUrl
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
179 """
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
180 data = bytes(pixmapToByteArray(pixmap)).decode()
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
181 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
182 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
183 else:
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
184 return QUrl()
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
185
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
186
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
187 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
188 """
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
189 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
190 data: URL.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
191
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
192 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
193 denote a pixmap file in the icons data directory.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
194
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
195 @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
196 @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
197 @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
198 @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
199 @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
200 @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
201 """
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
202 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
203 pixmapFile = os.path.join(WebBrowserDataDirectory["icons"], pixmapFile)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
204
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
205 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
206 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
207 # 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
208 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
209 url = pixmapToDataUrl(QPixmap(pixmapFile), mimetype=mime)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
210
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
211 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
212 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
213 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
214 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
215
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
4810
f68d0446609e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
217 def getWebEngineVersions():
f68d0446609e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
218 """
9167
2d2b9a26e904 Changed the QtWebEngine version reporting code to use the new (as of PyQt 6.3.1) functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9162
diff changeset
219 Module function to extract the web engine related versions from the default
2d2b9a26e904 Changed the QtWebEngine version reporting code to use the new (as of PyQt 6.3.1) functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9162
diff changeset
220 user agent string.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
221
9167
2d2b9a26e904 Changed the QtWebEngine version reporting code to use the new (as of PyQt 6.3.1) functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9162
diff changeset
222 Note: For PyQt 6.3.1 or newer the data is extracted via some Qt functions.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
223
9167
2d2b9a26e904 Changed the QtWebEngine version reporting code to use the new (as of PyQt 6.3.1) functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9162
diff changeset
224 @return tuple containing the Chromium version, the Chromium security patch
2d2b9a26e904 Changed the QtWebEngine version reporting code to use the new (as of PyQt 6.3.1) functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9162
diff changeset
225 version and the QtWebEngine version
2d2b9a26e904 Changed the QtWebEngine version reporting code to use the new (as of PyQt 6.3.1) functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9162
diff changeset
226 @rtype tuple of (str, str, str)
2d2b9a26e904 Changed the QtWebEngine version reporting code to use the new (as of PyQt 6.3.1) functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9162
diff changeset
227 """
2d2b9a26e904 Changed the QtWebEngine version reporting code to use the new (as of PyQt 6.3.1) functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9162
diff changeset
228 try:
11148
15e30f0c76a8 Adjusted the code to the modified issue codes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 11090
diff changeset
229 from PyQt6.QtWebEngineCore import ( # __IGNORE_WARNING_I-10__
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
230 qWebEngineChromiumSecurityPatchVersion,
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
231 qWebEngineChromiumVersion,
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
232 qWebEngineVersion,
9167
2d2b9a26e904 Changed the QtWebEngine version reporting code to use the new (as of PyQt 6.3.1) functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9162
diff changeset
233 )
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
234
9167
2d2b9a26e904 Changed the QtWebEngine version reporting code to use the new (as of PyQt 6.3.1) functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9162
diff changeset
235 chromiumVersion = qWebEngineChromiumVersion()
2d2b9a26e904 Changed the QtWebEngine version reporting code to use the new (as of PyQt 6.3.1) functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9162
diff changeset
236 chromiumSecurityVersion = qWebEngineChromiumSecurityPatchVersion()
2d2b9a26e904 Changed the QtWebEngine version reporting code to use the new (as of PyQt 6.3.1) functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9162
diff changeset
237 webengineVersion = qWebEngineVersion()
2d2b9a26e904 Changed the QtWebEngine version reporting code to use the new (as of PyQt 6.3.1) functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9162
diff changeset
238 except ImportError:
2d2b9a26e904 Changed the QtWebEngine version reporting code to use the new (as of PyQt 6.3.1) functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9162
diff changeset
239 # backwards compatibility for PyQt < 6.3.1
11148
15e30f0c76a8 Adjusted the code to the modified issue codes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 11090
diff changeset
240 from PyQt6.QtWebEngineCore import QWebEngineProfile # __IGNORE_WARNING_I-10__
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
241
9167
2d2b9a26e904 Changed the QtWebEngine version reporting code to use the new (as of PyQt 6.3.1) functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9162
diff changeset
242 useragent = QWebEngineProfile.defaultProfile().httpUserAgent()
2d2b9a26e904 Changed the QtWebEngine version reporting code to use the new (as of PyQt 6.3.1) functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9162
diff changeset
243 match = re.search(r"""Chrome/([\d.]+)""", useragent)
2d2b9a26e904 Changed the QtWebEngine version reporting code to use the new (as of PyQt 6.3.1) functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9162
diff changeset
244 chromiumVersion = (
2d2b9a26e904 Changed the QtWebEngine version reporting code to use the new (as of PyQt 6.3.1) functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9162
diff changeset
245 match.group(1)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
246 if match
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
247 else QCoreApplication.translate("WebBrowserTools", "<unknown>")
9167
2d2b9a26e904 Changed the QtWebEngine version reporting code to use the new (as of PyQt 6.3.1) functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9162
diff changeset
248 )
2d2b9a26e904 Changed the QtWebEngine version reporting code to use the new (as of PyQt 6.3.1) functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9162
diff changeset
249 match = re.search(r"""QtWebEngine/([\d.]+)""", useragent)
2d2b9a26e904 Changed the QtWebEngine version reporting code to use the new (as of PyQt 6.3.1) functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9162
diff changeset
250 webengineVersion = (
2d2b9a26e904 Changed the QtWebEngine version reporting code to use the new (as of PyQt 6.3.1) functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9162
diff changeset
251 match.group(1)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
252 if match
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
253 else QCoreApplication.translate("WebBrowserTools", "<unknown>")
9167
2d2b9a26e904 Changed the QtWebEngine version reporting code to use the new (as of PyQt 6.3.1) functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9162
diff changeset
254 )
2d2b9a26e904 Changed the QtWebEngine version reporting code to use the new (as of PyQt 6.3.1) functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9162
diff changeset
255 chromiumSecurityVersion = ""
2d2b9a26e904 Changed the QtWebEngine version reporting code to use the new (as of PyQt 6.3.1) functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9162
diff changeset
256 # not available via the user agent string
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
257
9167
2d2b9a26e904 Changed the QtWebEngine version reporting code to use the new (as of PyQt 6.3.1) functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9162
diff changeset
258 return (chromiumVersion, chromiumSecurityVersion, 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
259
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 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
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 Module function to load a HTML page.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
264
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
265 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
266 denote a HTML file in the html data directory.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
267
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
268 @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
269 @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
270 @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
271 @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
272 """
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 if not os.path.isabs(pageFileName):
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
274 pageFileName = os.path.join(WebBrowserDataDirectory["html"], pageFileName)
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
275
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
276 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
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
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 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
280 """
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 Module function to load a JavaScript source file.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
282
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
283 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
284 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
285 directory.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
286
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
287 @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
288 @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
289 @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
290 @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
291 """
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 if not os.path.isabs(jsFileName):
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
293 jsFileName = os.path.join(WebBrowserDataDirectory["js"], jsFileName)
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
294
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
295 return readAllFileContents(jsFileName)
9672
335f695d59e7 Changed loading of the JQuery libraries into the speeddial page so that a system wide library is loaded in case the internal one has been removed (e.g. by distro package maintainers).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
296
335f695d59e7 Changed loading of the JQuery libraries into the speeddial page so that a system wide library is loaded in case the internal one has been removed (e.g. by distro package maintainers).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
297
335f695d59e7 Changed loading of the JQuery libraries into the speeddial page so that a system wide library is loaded in case the internal one has been removed (e.g. by distro package maintainers).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
298 def getJquery(jqName):
335f695d59e7 Changed loading of the JQuery libraries into the speeddial page so that a system wide library is loaded in case the internal one has been removed (e.g. by distro package maintainers).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
299 """
335f695d59e7 Changed loading of the JQuery libraries into the speeddial page so that a system wide library is loaded in case the internal one has been removed (e.g. by distro package maintainers).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
300 Module function to load a JQuery source file.
335f695d59e7 Changed loading of the JQuery libraries into the speeddial page so that a system wide library is loaded in case the internal one has been removed (e.g. by distro package maintainers).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
301
335f695d59e7 Changed loading of the JQuery libraries into the speeddial page so that a system wide library is loaded in case the internal one has been removed (e.g. by distro package maintainers).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
302 Note: If the JQuery file is not found in the javascript data directory and
335f695d59e7 Changed loading of the JQuery libraries into the speeddial page so that a system wide library is loaded in case the internal one has been removed (e.g. by distro package maintainers).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
303 the platform is Linux, it is assumed that it is installed system wide in the
335f695d59e7 Changed loading of the JQuery libraries into the speeddial page so that a system wide library is loaded in case the internal one has been removed (e.g. by distro package maintainers).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
304 '/usr/share/javascript' directory (e.g. as packaged by Debian).
335f695d59e7 Changed loading of the JQuery libraries into the speeddial page so that a system wide library is loaded in case the internal one has been removed (e.g. by distro package maintainers).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
305
335f695d59e7 Changed loading of the JQuery libraries into the speeddial page so that a system wide library is loaded in case the internal one has been removed (e.g. by distro package maintainers).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
306 @param jqName name of the JQuery library to be loaded (one of 'jquery' or
335f695d59e7 Changed loading of the JQuery libraries into the speeddial page so that a system wide library is loaded in case the internal one has been removed (e.g. by distro package maintainers).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
307 'jquery-ui')
335f695d59e7 Changed loading of the JQuery libraries into the speeddial page so that a system wide library is loaded in case the internal one has been removed (e.g. by distro package maintainers).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
308 @type str
335f695d59e7 Changed loading of the JQuery libraries into the speeddial page so that a system wide library is loaded in case the internal one has been removed (e.g. by distro package maintainers).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
309 @return JQuery source
335f695d59e7 Changed loading of the JQuery libraries into the speeddial page so that a system wide library is loaded in case the internal one has been removed (e.g. by distro package maintainers).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
310 @rtype str
335f695d59e7 Changed loading of the JQuery libraries into the speeddial page so that a system wide library is loaded in case the internal one has been removed (e.g. by distro package maintainers).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
311 """
335f695d59e7 Changed loading of the JQuery libraries into the speeddial page so that a system wide library is loaded in case the internal one has been removed (e.g. by distro package maintainers).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
312 jsFileName = os.path.join(WebBrowserDataDirectory["js"], jqName + ".js")
10334
24300d16a154 General
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9672
diff changeset
313 if not os.path.exists(jsFileName) and (
10339
446d22fa1aea Renamed "isBsdPlatform()" to "isFreeBsdPlatform()" to express its real test.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10334
diff changeset
314 OSUtilities.isLinuxPlatform() or OSUtilities.isFreeBsdPlatform()
10334
24300d16a154 General
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9672
diff changeset
315 ):
9672
335f695d59e7 Changed loading of the JQuery libraries into the speeddial page so that a system wide library is loaded in case the internal one has been removed (e.g. by distro package maintainers).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
316 if jqName == "jquery":
335f695d59e7 Changed loading of the JQuery libraries into the speeddial page so that a system wide library is loaded in case the internal one has been removed (e.g. by distro package maintainers).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
317 jsFileName = "/usr/share/javascript/jquery/jquery.min.js"
335f695d59e7 Changed loading of the JQuery libraries into the speeddial page so that a system wide library is loaded in case the internal one has been removed (e.g. by distro package maintainers).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
318 elif jqName == "jquery-ui":
335f695d59e7 Changed loading of the JQuery libraries into the speeddial page so that a system wide library is loaded in case the internal one has been removed (e.g. by distro package maintainers).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
319 jsFileName = "/usr/share/javascript/jquery-ui/jquery-ui.min.js"
335f695d59e7 Changed loading of the JQuery libraries into the speeddial page so that a system wide library is loaded in case the internal one has been removed (e.g. by distro package maintainers).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
320
335f695d59e7 Changed loading of the JQuery libraries into the speeddial page so that a system wide library is loaded in case the internal one has been removed (e.g. by distro package maintainers).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
321 return readAllFileContents(jsFileName)

eric ide

mercurial