src/eric7/WebBrowser/Tools/WebBrowserTools.py

Thu, 07 Jul 2022 11:23:56 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Thu, 07 Jul 2022 11:23:56 +0200
branch
eric7
changeset 9209
b99e7fd55fd3
parent 9167
eric7/WebBrowser/Tools/WebBrowserTools.py@2d2b9a26e904
child 9221
bf71ee032bb4
permissions
-rw-r--r--

Reorganized the project structure to use the source layout in order to support up-to-date build systems with "pyproject.toml".

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
8881
54e42bc2437a Updated copyright for 2022.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8556
diff changeset
3 # Copyright (c) 2016 - 2022 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
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
14 from PyQt6.QtCore import (
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
15 QByteArray, QUrl, QCoreApplication, QBuffer, QIODevice
7270
41d09cf20415 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
16 )
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
17 from PyQt6.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 """
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
36 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
37 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
38 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
39 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
40 return ""
4741
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
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
43 def containsSpace(string):
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
44 """
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
45 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
46
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
47 @param string string to be checked
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
48 @type str
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
49 @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
50 @rtype bool
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
51 """
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
52 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
53
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
54
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
55 def ensureUniqueFilename(name, appendFormat="({0})"):
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
56 """
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
57 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
58
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
59 @param name desired file name (string)
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
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
61 (string)
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
62 @return unique file name
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
63 """
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
64 if not os.path.exists(name):
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
65 return name
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
66
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
67 tmpFileName = name
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
68 i = 1
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
69 while os.path.exists(tmpFileName):
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
70 tmpFileName = name
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
71 index = tmpFileName.rfind(".")
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 appendString = appendFormat.format(i)
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
74 if index == -1:
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
75 tmpFileName += appendString
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
76 else:
7270
41d09cf20415 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
77 tmpFileName = (
41d09cf20415 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
78 tmpFileName[:index] + appendString + tmpFileName[index:]
41d09cf20415 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
79 )
4763
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
80 i += 1
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 return tmpFileName
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
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
85 def getFileNameFromUrl(url):
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
86 """
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
87 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
88
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
89 @param url URL (QUrl)
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
90 @return file name (string)
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
91 """
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
92 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
93 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
94 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
95 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
96 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
97 )
4763
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
98 if fileName.find("/") != -1:
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
99 pos = fileName.rfind("/")
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
100 fileName = fileName[pos:]
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
101 fileName = fileName.replace("/", "")
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 fileName = filterCharsFromFilename(fileName)
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 if not fileName:
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
106 fileName = filterCharsFromFilename(url.host().replace(".", "_"))
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
107
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
108 return fileName
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
109
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 def filterCharsFromFilename(name):
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
112 """
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
113 Module function to filter illegal characters.
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
114
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
115 @param name name to be sanitized (string)
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
116 @return sanitized name (string)
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
117 """
7270
41d09cf20415 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
118 return (
41d09cf20415 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
119 name
41d09cf20415 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
120 .replace("/", "_")
41d09cf20415 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
121 .replace("\\", "")
41d09cf20415 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
122 .replace(":", "")
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(">", "")
4763
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
128 .replace("|", "")
7270
41d09cf20415 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
129 )
4783
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
130
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
131
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
132 def pixmapFromByteArray(data):
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 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
135
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
136 @param data data for the pixmap
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
137 @type bytes or QByteArray
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
138 @return extracted pixmap
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
139 @rtype QPixmap
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
140 """
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
141 pixmap = QPixmap()
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
142 barray = QByteArray.fromBase64(data)
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
143 pixmap.loadFromData(barray)
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
144
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
145 return pixmap
4810
f68d0446609e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
146
f68d0446609e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
147
4865
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
148 def pixmapToByteArray(pixmap):
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
149 """
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
150 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
151 as a PNG encoded as base64.
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
152
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
153 @param pixmap pixmap to be converted
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
154 @type QPixmap
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
155 @return byte array containing the pixmap
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
156 @rtype QByteArray
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
157 """
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
158 byteArray = QByteArray()
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
159 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
160 buffer.open(QIODevice.OpenModeFlag.WriteOnly)
4865
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
161 if pixmap.save(buffer, "PNG"):
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
162 return buffer.buffer().toBase64()
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
163
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
164 return QByteArray()
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
165
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
166
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
167 def pixmapToDataUrl(pixmap, mimetype="image/png"):
4865
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
168 """
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
169 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
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
7732
4c9cf117acf6 Fixed some code style issues and one coding issue.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7717
diff changeset
173 @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
174 @type str
4865
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
175 @return data: URL
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
176 @rtype QUrl
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
177 """
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
178 data = bytes(pixmapToByteArray(pixmap)).decode()
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
179 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
180 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
181 else:
4adc526bc4b3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4810
diff changeset
182 return QUrl()
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 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
186 """
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 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
188 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
189
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 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
191 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
192
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 @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
194 @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
195 @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
196 @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
197 @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
198 @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
199 """
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 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
201 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
202
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 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
204 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
205 # 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
206 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
207 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
208
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 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
210 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
211 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
212 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
213
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
4810
f68d0446609e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
215 def getWebEngineVersions():
f68d0446609e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
216 """
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
217 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
218 user agent string.
4810
f68d0446609e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
219
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
220 Note: For PyQt 6.3.1 or newer the data is extracted via some Qt functions.
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
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 @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
223 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
224 @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
225 """
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 try:
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 from PyQt6.QtWebEngineCore import (
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 qWebEngineVersion, 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
229 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
230 )
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
231 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
232 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
233 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
234 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
235 # backwards compatibility for PyQt < 6.3.1
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 from PyQt6.QtWebEngineCore import QWebEngineProfile
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
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 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
239 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
240 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
241 match.group(1)
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 if match else
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 QCoreApplication.translate("WebBrowserTools", "<unknown>")
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 )
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 = 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
246 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
247 match.group(1)
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 if match else
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 QCoreApplication.translate("WebBrowserTools", "<unknown>")
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 )
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 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
252 # not available via the user agent string
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
253
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 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
255
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
256
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 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
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 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
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 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
262 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
263
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 @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
265 @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
266 @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
267 @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
268 """
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 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
270 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
271 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
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 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
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
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 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
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 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
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 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
281 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
282 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
283
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 @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
285 @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
286 @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
287 @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
288 """
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 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
290 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
291 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
292
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 return readAllFileContents(jsFileName)

eric ide

mercurial