eric7/WebBrowser/GreaseMonkey/GreaseMonkeyManager.py

branch
eric7
changeset 9162
8b75b1668583
parent 9153
506e35e424d5
equal deleted inserted replaced
9161:90939b08da20 9162:8b75b1668583
10 import os 10 import os
11 import contextlib 11 import contextlib
12 import pathlib 12 import pathlib
13 13
14 from PyQt6.QtCore import ( 14 from PyQt6.QtCore import (
15 pyqtSignal, pyqtSlot, Qt, QObject, QTimer, QFile, QDir, QSettings, 15 pyqtSignal, pyqtSlot, Qt, QObject, QTimer, QDir, QSettings,
16 QMetaObject, QUrl, Q_ARG, QCoreApplication 16 QMetaObject, QUrl, Q_ARG, QCoreApplication
17 ) 17 )
18 from PyQt6.QtWidgets import QDialog 18 from PyQt6.QtWidgets import QDialog
19 19
20 from EricWidgets import EricMessageBox 20 from EricWidgets import EricMessageBox
231 fullName = script.fullName() 231 fullName = script.fullName()
232 if fullName not in self.__disabledScripts: 232 if fullName not in self.__disabledScripts:
233 self.__disabledScripts.append(fullName) 233 self.__disabledScripts.append(fullName)
234 234
235 collection = WebBrowserWindow.webProfile().scripts() 235 collection = WebBrowserWindow.webProfile().scripts()
236 collection.remove(collection.findScript(fullName)) 236 foundScripts = collection.find(fullName)
237 if foundScripts:
238 collection.remove(foundScripts[0])
237 239
238 def addScript(self, script): 240 def addScript(self, script):
239 """ 241 """
240 Public method to add a script. 242 Public method to add a script.
241 243
269 with contextlib.suppress(ValueError): 271 with contextlib.suppress(ValueError):
270 self.__scripts.remove(script) 272 self.__scripts.remove(script)
271 273
272 fullName = script.fullName() 274 fullName = script.fullName()
273 collection = WebBrowserWindow.webProfile().scripts() 275 collection = WebBrowserWindow.webProfile().scripts()
274 collection.remove(collection.findScript(fullName)) 276 foundScripts = collection.find(fullName)
277 if foundScripts:
278 collection.remove(foundScripts[0])
275 279
276 if fullName in self.__disabledScripts: 280 if fullName in self.__disabledScripts:
277 self.__disabledScripts.remove(fullName) 281 self.__disabledScripts.remove(fullName)
278 282
279 if removeFile: 283 if removeFile:
280 QFile.remove(script.fileName()) 284 os.unlink(script.fileName())
281 del script 285 del script
282 286
283 self.scriptsChanged.emit() 287 self.scriptsChanged.emit()
284 return True 288 return True
285 289
335 @param script reference to the changed script 339 @param script reference to the changed script
336 @type GreaseMonkeyScript 340 @type GreaseMonkeyScript
337 """ 341 """
338 fullName = script.fullName() 342 fullName = script.fullName()
339 collection = WebBrowserWindow.webProfile().scripts() 343 collection = WebBrowserWindow.webProfile().scripts()
340 collection.remove(collection.findScript(fullName)) 344 foundScripts = collection.find(fullName)
345 if foundScripts:
346 collection.remove(foundScripts[0])
341 collection.insert(script.webScript()) 347 collection.insert(script.webScript())

eric ide

mercurial