src/eric7/WebBrowser/GreaseMonkey/GreaseMonkeyScript.py

branch
eric7
changeset 10485
287a3ae95e00
parent 10475
ee41fab001f2
child 11090
f5f5f5803935
--- a/src/eric7/WebBrowser/GreaseMonkey/GreaseMonkeyScript.py	Sun Jan 07 11:42:41 2024 +0100
+++ b/src/eric7/WebBrowser/GreaseMonkey/GreaseMonkeyScript.py	Sun Jan 07 12:40:00 2024 +0100
@@ -7,6 +7,7 @@
 Module implementing the GreaseMonkey script.
 """
 
+import enum
 import re
 
 from PyQt6.QtCore import (
@@ -24,10 +25,20 @@
 from ..Tools.DelayedFileWatcher import DelayedFileWatcher
 from ..WebBrowserPage import WebBrowserPage
 from ..WebBrowserWindow import WebBrowserWindow
-from .GreaseMonkeyDownloader import GreaseMonkeyDownloader
+from .GreaseMonkeyDownloader import GreaseMonkeyDownloader, GreaseMonkeyDownloadType
 from .GreaseMonkeyJavaScript import bootstrap_js, values_js
 
 
+class GreaseMonkeyScriptStartPoint(enum.Enum):
+    """
+    Class defining the script start points.
+    """
+
+    DocumentStart = 0
+    DocumentEnd = 1
+    DocumentIdle = 2
+
+
 class GreaseMonkeyScript(QObject):
     """
     Class implementing the GreaseMonkey script.
@@ -37,11 +48,6 @@
         updating state
     """
 
-    # TODO: change this to an enum
-    DocumentStart = 0
-    DocumentEnd = 1
-    DocumentIdle = 2
-
     scriptChanged = pyqtSignal()
     updatingChanged = pyqtSignal(bool)
 
@@ -72,7 +78,7 @@
         self.__iconUrl = QUrl()
         self.__downloadUrl = QUrl()
         self.__updateUrl = QUrl()
-        self.__startAt = GreaseMonkeyScript.DocumentEnd
+        self.__startAt = GreaseMonkeyScriptStartPoint.DocumentEnd
 
         self.__script = ""
         self.__fileName = path
@@ -184,7 +190,7 @@
         Public method to get the start point of the script.
 
         @return start point of the script
-        @rtype DocumentStart or DocumentEnd
+        @rtype GreaseMonkeyScriptStartPoint
         """
         return self.__startAt
 
@@ -289,7 +295,7 @@
         self.__iconUrl = QUrl()
         self.__downloadUrl = QUrl()
         self.__updateUrl = QUrl()
-        self.__startAt = GreaseMonkeyScript.DocumentEnd
+        self.__startAt = GreaseMonkeyScriptStartPoint.DocumentEnd
 
         self.__script = ""
         self.__enabled = True
@@ -356,11 +362,11 @@
 
             elif key == "@run-at":
                 if value == "document-end":
-                    self.__startAt = GreaseMonkeyScript.DocumentEnd
+                    self.__startAt = GreaseMonkeyScriptStartPoint.DocumentEnd
                 elif value == "document-start":
-                    self.__startAt = GreaseMonkeyScript.DocumentStart
+                    self.__startAt = GreaseMonkeyScriptStartPoint.DocumentStart
                 elif value == "document-idle":
-                    self.__startAt = GreaseMonkeyScript.DocumentIdle
+                    self.__startAt = GreaseMonkeyScriptStartPoint.DocumentIdle
 
             elif key == "@downloadURL" and self.__downloadUrl.isEmpty():
                 self.__downloadUrl = QUrl(value)
@@ -421,7 +427,7 @@
         downloader = GreaseMonkeyDownloader(
             self.__downloadUrl,
             self.__manager,
-            GreaseMonkeyDownloader.DownloadMainScript,
+            GreaseMonkeyDownloadType.MainScript,
         )
         downloader.updateScript(self.__fileName)
         downloader.finished.connect(lambda: self.__downloaderFinished(downloader))
@@ -474,7 +480,7 @@
                 downloader = GreaseMonkeyDownloader(
                     QUrl(urlStr),
                     self.__manager,
-                    GreaseMonkeyDownloader.DownloadRequireScript,
+                    GreaseMonkeyDownloadType.RequireScript,
                 )
                 downloader.finished.connect(
                     lambda: self.__requireDownloaded(downloader)

eric ide

mercurial