eric6/WebBrowser/GreaseMonkey/GreaseMonkeyScript.py

Wed, 30 Dec 2020 11:00:44 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 30 Dec 2020 11:00:44 +0100
branch
maintenance
changeset 7924
8a96736d465e
parent 7836
2f0d208b8137
child 8143
2c730d5fd177
permissions
-rw-r--r--

Updated copyright for 2021.

1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7924
8a96736d465e Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7836
diff changeset
3 # Copyright (c) 2012 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing the GreaseMonkey script.
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
7775
4a1db75550bd Changed code to not use deprecated 'QRegExp' anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
10 import re
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2302
diff changeset
11
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
12 from PyQt5.QtCore import (
7775
4a1db75550bd Changed code to not use deprecated 'QRegExp' anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
13 pyqtSignal, pyqtSlot, QObject, QUrl, QByteArray, QCryptographicHash
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
14 )
6145
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
15 from PyQt5.QtGui import QIcon, QPixmap, QImage
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
16 from PyQt5.QtNetwork import QNetworkRequest, QNetworkReply
4766
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
17 from PyQt5.QtWebEngineWidgets import QWebEngineScript
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
4766
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
19 from .GreaseMonkeyJavaScript import bootstrap_js, values_js
5715
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
20 from .GreaseMonkeyDownloader import GreaseMonkeyDownloader
4766
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
21
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
22 from ..Tools.DelayedFileWatcher import DelayedFileWatcher
5001
08eaee907686 Prepared the QWebEingine based web browser for the new runJavaScript() method as of Qt 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
23 from ..WebBrowserPage import WebBrowserPage
6145
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
24 from ..WebBrowserWindow import WebBrowserWindow
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26
4766
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
27 class GreaseMonkeyScript(QObject):
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 """
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 Class implementing the GreaseMonkey script.
5726
e1dbd217214a Fixed a few source docu issues (forgotten signals and exceptions).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5715
diff changeset
30
e1dbd217214a Fixed a few source docu issues (forgotten signals and exceptions).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5715
diff changeset
31 @signal scriptChanged() emitted to indicate a script change
e1dbd217214a Fixed a few source docu issues (forgotten signals and exceptions).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5715
diff changeset
32 @signal updatingChanged(bool) emitted to indicate a change of the
e1dbd217214a Fixed a few source docu issues (forgotten signals and exceptions).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5715
diff changeset
33 updating state
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 """
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 DocumentStart = 0
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 DocumentEnd = 1
4809
4daf93888029 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
diff changeset
37 DocumentIdle = 2
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38
4766
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
39 scriptChanged = pyqtSignal()
5715
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
40 updatingChanged = pyqtSignal(bool)
4766
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
41
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 def __init__(self, manager, path):
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 """
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 Constructor
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 @param manager reference to the manager object (GreaseMonkeyManager)
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 @param path path of the Javascript file (string)
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 """
4766
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
49 super(GreaseMonkeyScript, self).__init__(manager)
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
50
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 self.__manager = manager
4766
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
52 self.__fileWatcher = DelayedFileWatcher(parent=None)
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 self.__name = ""
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 self.__namespace = "GreaseMonkeyNS"
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 self.__description = ""
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 self.__version = ""
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 self.__include = []
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 self.__exclude = []
5715
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
61 self.__require = []
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62
6145
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
63 self.__icon = QIcon()
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
64 self.__iconUrl = QUrl()
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 self.__downloadUrl = QUrl()
4766
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
66 self.__updateUrl = QUrl()
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 self.__startAt = GreaseMonkeyScript.DocumentEnd
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 self.__script = ""
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 self.__fileName = path
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 self.__enabled = True
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 self.__valid = False
4766
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
73 self.__noFrames = False
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74
5715
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
75 self.__updating = False
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
76
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
77 self.__downloaders = []
6145
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
78 self.__iconReplies = []
5715
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
79
4766
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
80 self.__parseScript()
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
81
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
82 self.__fileWatcher.delayedFileChanged.connect(
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
83 self.__watchedFileChanged)
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 def isValid(self):
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 """
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 Public method to check the validity of the script.
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 @return flag indicating a valid script (boolean)
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 """
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 return self.__valid
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 def name(self):
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 """
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 Public method to get the name of the script.
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 @return name of the script (string)
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 """
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 return self.__name
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 def nameSpace(self):
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 """
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 Public method to get the name space of the script.
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 @return name space of the script (string)
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 """
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 return self.__namespace
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 def fullName(self):
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 """
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 Public method to get the full name of the script.
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 @return full name of the script (string)
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 """
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 return "{0}/{1}".format(self.__namespace, self.__name)
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 def description(self):
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 """
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 Public method to get the description of the script.
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 @return description of the script (string)
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 """
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 return self.__description
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 def version(self):
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 """
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 Public method to get the version of the script.
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 @return version of the script (string)
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 """
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131 return self.__version
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132
6145
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
133 def icon(self):
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
134 """
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
135 Public method to get the icon of the script.
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
136
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
137 @return script icon
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
138 @rtype QIcon
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
139 """
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
140 return self.__icon
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
141
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
142 def iconUrl(self):
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
143 """
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
144 Public method to get the icon URL of the script.
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
145
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
146 @return icon URL of the script (QUrl)
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
147 """
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
148 return QUrl(self.__iconUrl)
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
149
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150 def downloadUrl(self):
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151 """
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 Public method to get the download URL of the script.
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 @return download URL of the script (QUrl)
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 """
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156 return QUrl(self.__downloadUrl)
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157
4766
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
158 def updateUrl(self):
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
159 """
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
160 Public method to get the update URL of the script.
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
161
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
162 @return update URL of the script (QUrl)
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
163 """
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
164 return QUrl(self.__updateUrl)
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
165
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 def startAt(self):
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167 """
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168 Public method to get the start point of the script.
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170 @return start point of the script (DocumentStart or DocumentEnd)
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171 """
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172 return self.__startAt
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173
4766
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
174 def noFrames(self):
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
175 """
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
176 Public method to get the noFrames flag.
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
177
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
178 @return flag indicating to not run on sub frames
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
179 @rtype bool
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
180 """
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
181 return self.__noFrames
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
182
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183 def isEnabled(self):
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 """
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185 Public method to check, if the script is enabled.
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187 @return flag indicating an enabled state (boolean)
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188 """
4766
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
189 return self.__enabled and self.__valid
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
190
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
191 def setEnabled(self, enable):
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
192 """
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
193 Public method to enable a script.
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
194
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
195 @param enable flag indicating the new enabled state (boolean)
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
196 """
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
197 self.__enabled = enable
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
198
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
199 def include(self):
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
200 """
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
201 Public method to get the list of included URLs.
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
202
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
203 @return list of included URLs (list of strings)
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
204 """
4809
4daf93888029 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
diff changeset
205 return self.__include[:]
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
206
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
207 def exclude(self):
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
208 """
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
209 Public method to get the list of excluded URLs.
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
210
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
211 @return list of excluded URLs (list of strings)
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
212 """
4809
4daf93888029 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
diff changeset
213 return self.__exclude[:]
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
214
5715
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
215 def require(self):
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
216 """
5715
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
217 Public method to get the list of required scripts.
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
218
5715
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
219 @return list of required scripts (list of strings)
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
220 """
5715
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
221 return self.__require[:]
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
222
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
223 def fileName(self):
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
224 """
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
225 Public method to get the path of the Javascript file.
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
226
5715
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
227 @return path of the Javascript file (string)
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
228 """
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
229 return self.__fileName
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
230
5715
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
231 def isUpdating(self):
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
232 """
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
233 Public method to get the updating flag.
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
234
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
235 @return updating flag
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
236 @rtype bool
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
237 """
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
238 return self.__updating
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
239
4766
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
240 @pyqtSlot(str)
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
241 def __watchedFileChanged(self, fileName):
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
242 """
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
243 Private slot handling changes of the script file.
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
244
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
245 @param fileName path of the script file
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
246 @type str
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
247 """
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
248 if self.__fileName == fileName:
5715
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
249 self.__reloadScript()
4766
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
250
4886
b56735d36159 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4809
diff changeset
251 def __parseScript(self):
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
252 """
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
253 Private method to parse the given script and populate the data
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
254 structure.
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
255 """
4766
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
256 self.__name = ""
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
257 self.__namespace = "GreaseMonkeyNS"
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
258 self.__description = ""
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
259 self.__version = ""
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
260
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
261 self.__include = []
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
262 self.__exclude = []
5715
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
263 self.__require = []
4766
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
264
6145
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
265 self.__icon = QIcon()
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
266 self.__iconUrl = QUrl()
4766
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
267 self.__downloadUrl = QUrl()
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
268 self.__updateUrl = QUrl()
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
269 self.__startAt = GreaseMonkeyScript.DocumentEnd
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
270
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
271 self.__script = ""
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
272 self.__enabled = True
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
273 self.__valid = False
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
274 self.__noFrames = False
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
275
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
276 try:
7785
9978016560ec Changed code to use context manager 'open()' for file operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7775
diff changeset
277 with open(self.__fileName, "r", encoding="utf-8") as f:
9978016560ec Changed code to use context manager 'open()' for file operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7775
diff changeset
278 fileData = f.read()
7836
2f0d208b8137 Changed code to not use the OSError aliases (IOError, EnvironmentError, socket.error and select.error) anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7785
diff changeset
279 except OSError:
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
280 # silently ignore because it shouldn't happen
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
281 return
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
282
4766
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
283 if self.__fileName not in self.__fileWatcher.files():
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
284 self.__fileWatcher.addPath(self.__fileName)
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
285
7775
4a1db75550bd Changed code to not use deprecated 'QRegExp' anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
286 rx = re.compile("// ==UserScript==(.*)// ==/UserScript==")
4a1db75550bd Changed code to not use deprecated 'QRegExp' anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
287 match = rx.search(fileData)
4a1db75550bd Changed code to not use deprecated 'QRegExp' anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
288 if match is None:
4a1db75550bd Changed code to not use deprecated 'QRegExp' anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
289 # invalid script file
4a1db75550bd Changed code to not use deprecated 'QRegExp' anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
290 return
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
291
7775
4a1db75550bd Changed code to not use deprecated 'QRegExp' anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
292 metaDataBlock = match.group(1).strip()
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
293 if metaDataBlock == "":
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
294 # invalid script file
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
295 return
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
296
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
297 for line in metaDataBlock.splitlines():
4766
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
298 if not line.strip():
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
299 continue
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
300
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
301 if not line.startswith("// @"):
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
302 continue
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
303
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
304 line = line[3:].replace("\t", " ")
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
305 index = line.find(" ")
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
306
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
307 key = line[:index].strip()
6145
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
308 if index > 0:
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
309 value = line[index + 1:].strip()
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
310 else:
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
311 value = ""
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
312
6145
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
313 if not key:
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
314 continue
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
315
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
316 if key == "@name":
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
317 self.__name = value
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
318
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
319 elif key == "@namespace":
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
320 self.__namespace = value
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
321
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
322 elif key == "@description":
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
323 self.__description = value
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
324
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
325 elif key == "@version":
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
326 self.__version = value
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
327
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
328 elif key in ["@include", "@match"]:
4809
4daf93888029 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
diff changeset
329 self.__include.append(value)
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
330
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
331 elif key in ["@exclude", "@exclude_match"]:
4809
4daf93888029 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
diff changeset
332 self.__exclude.append(value)
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
333
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
334 elif key == "@require":
5715
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
335 self.__require.append(value)
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
336
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
337 elif key == "@run-at":
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
338 if value == "document-end":
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
339 self.__startAt = GreaseMonkeyScript.DocumentEnd
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
340 elif value == "document-start":
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
341 self.__startAt = GreaseMonkeyScript.DocumentStart
4809
4daf93888029 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
diff changeset
342 elif value == "document-idle":
4daf93888029 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
diff changeset
343 self.__startAt = GreaseMonkeyScript.DocumentIdle
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
344
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
345 elif key == "@downloadURL" and self.__downloadUrl.isEmpty():
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
346 self.__downloadUrl = QUrl(value)
4766
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
347
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
348 elif key == "@updateURL" and self.__updateUrl.isEmpty():
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
349 self.__updateUrl = QUrl(value)
6145
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
350
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
351 elif key == "@icon":
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
352 self.__iconUrl = QUrl(value)
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
353
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
354 elif key == "@noframes":
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
355 self.__noFrames = True
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
356
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
357 self.__iconUrl = self.__downloadUrl.resolved(self.__iconUrl)
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
358
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
359 if not self.__include:
4809
4daf93888029 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
diff changeset
360 self.__include.append("*")
4766
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
361
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
362 nspace = bytes(QCryptographicHash.hash(
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
363 QByteArray(self.fullName().encode("utf-8")),
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
364 QCryptographicHash.Md4).toHex()).decode("ascii")
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
365 valuesScript = values_js.format(nspace)
7201
6b42677d7043 Modified sources to be in line with the minimum Qt/PyQt requirement (v 5.9.0).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
366 self.__script = "(function(){{{0}\n{1}\n{2}\n}})();".format(
6b42677d7043 Modified sources to be in line with the minimum Qt/PyQt requirement (v 5.9.0).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
367 valuesScript, self.__manager.requireScripts(self.__require),
6b42677d7043 Modified sources to be in line with the minimum Qt/PyQt requirement (v 5.9.0).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
368 fileData
6b42677d7043 Modified sources to be in line with the minimum Qt/PyQt requirement (v 5.9.0).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
369 )
4766
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
370 self.__valid = True
6145
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
371
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
372 self.__downloadIcon()
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
373 self.__downloadRequires()
4763
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
374
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
375 def webScript(self):
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
376 """
4766
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
377 Public method to create a script object.
4763
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
378
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
379 @return prepared script object
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
380 @rtype QWebEngineScript
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
381 """
4766
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
382 script = QWebEngineScript()
5650
4c52f07c186e Some fixes for the Web Browser NG related to Qt 5.8.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
383 script.setSourceCode("{0}\n{1}".format(
4c52f07c186e Some fixes for the Web Browser NG related to Qt 5.8.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
384 bootstrap_js, self.__script
4c52f07c186e Some fixes for the Web Browser NG related to Qt 5.8.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
385 ))
4766
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
386 script.setName(self.fullName())
5001
08eaee907686 Prepared the QWebEingine based web browser for the new runJavaScript() method as of Qt 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
387 script.setWorldId(WebBrowserPage.SafeJsWorld)
4766
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
388 script.setRunsOnSubFrames(not self.__noFrames)
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
389 return script
4809
4daf93888029 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
diff changeset
390
5715
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
391 def updateScript(self):
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
392 """
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
393 Public method to updated the script.
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
394 """
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
395 if not self.__downloadUrl.isValid() or self.__updating:
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
396 return
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
397
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
398 self.__updating = True
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
399 self.updatingChanged.emit(self.__updating)
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
400
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
401 downloader = GreaseMonkeyDownloader(
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
402 self.__downloadUrl,
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
403 self.__manager,
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
404 GreaseMonkeyDownloader.DownloadMainScript)
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
405 downloader.updateScript(self.__fileName)
6120
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
406 downloader.finished.connect(
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
407 lambda: self.__downloaderFinished(downloader))
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
408 downloader.error.connect(
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
409 lambda: self.__downloaderError(downloader))
5715
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
410 self.__downloaders.append(downloader)
4809
4daf93888029 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
diff changeset
411
5715
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
412 self.__downloadRequires()
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
413
6120
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
414 def __downloaderFinished(self, downloader):
5715
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
415 """
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
416 Private slot to handle a finished download.
6120
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
417
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
418 @param downloader reference to the downloader object
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
419 @type GreaseMonkeyDownloader
5715
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
420 """
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
421 if downloader in self.__downloaders:
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
422 self.__downloaders.remove(downloader)
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
423 self.__updating = False
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
424 self.updatingChanged.emit(self.__updating)
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
425
6120
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
426 def __downloaderError(self, downloader):
5715
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
427 """
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
428 Private slot to handle a downloader error.
6120
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
429
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
430 @param downloader reference to the downloader object
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
431 @type GreaseMonkeyDownloader
5715
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
432 """
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
433 if downloader in self.__downloaders:
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
434 self.__downloaders.remove(downloader)
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
435 self.__updating = False
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
436 self.updatingChanged.emit(self.__updating)
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
437
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
438 def __reloadScript(self):
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
439 """
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
440 Private method to reload the script.
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
441 """
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
442 self.__parseScript()
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
443
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
444 self.__manager.removeScript(self, False)
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
445 self.__manager.addScript(self)
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
446
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
447 self.scriptChanged.emit()
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
448
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
449 def __downloadRequires(self):
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
450 """
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
451 Private method to download the required scripts.
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
452 """
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
453 for urlStr in self.__require:
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
454 if not self.__manager.requireScripts([urlStr]):
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
455 downloader = GreaseMonkeyDownloader(
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
456 QUrl(urlStr),
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
457 self.__manager,
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
458 GreaseMonkeyDownloader.DownloadRequireScript)
6120
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
459 downloader.finished.connect(
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
460 lambda: self.__requireDownloaded(downloader))
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
461 downloader.error.connect(
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
462 lambda: self.__requireDownloadError(downloader))
5715
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
463 self.__downloaders.append(downloader)
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
464
6120
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
465 def __requireDownloaded(self, downloader):
5715
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
466 """
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
467 Private slot to handle a finished download of a required script.
6120
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
468
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
469 @param downloader reference to the downloader object
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
470 @type GreaseMonkeyDownloader
5715
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
471 """
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
472 if downloader in self.__downloaders:
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
473 self.__downloaders.remove(downloader)
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
474
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
475 self.__reloadScript()
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
476
6120
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
477 def __requireDownloadError(self, downloader):
5715
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
478 """
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
479 Private slot to handle a downloader error.
6120
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
480
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
481 @param downloader reference to the downloader object
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
482 @type GreaseMonkeyDownloader
5715
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
483 """
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
484 if downloader in self.__downloaders:
cbcca230679f Updated the GreaseMonkey handler to better work with QWebEngine as of Qt 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5650
diff changeset
485 self.__downloaders.remove(downloader)
6145
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
486
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
487 def __downloadIcon(self):
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
488 """
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
489 Private slot to download the script icon.
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
490 """
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
491 if self.__iconUrl.isValid():
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
492 request = QNetworkRequest(self.__iconUrl)
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
493 reply = WebBrowserWindow.networkManager().get(request)
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
494 reply.finished.connect(lambda: self.__iconDownloaded(reply))
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
495 self.__iconReplies.append(reply)
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
496
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
497 def __iconDownloaded(self, reply):
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
498 """
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
499 Private slot to handle a finished download of a script icon.
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
500
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
501 @param reply reference to the network reply
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
502 @type QNetworkReply
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
503 """
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
504 if reply in self.__iconReplies:
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
505 self.__iconReplies.remove(reply)
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
506
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
507 reply.deleteLater()
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
508 if reply.error() == QNetworkReply.NoError:
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
509 self.__icon = QPixmap.fromImage(QImage.fromData(reply.readAll()))

eric ide

mercurial