eric6/WebBrowser/GreaseMonkey/GreaseMonkeyConfiguration/GreaseMonkeyConfigurationDialog.py

Wed, 25 Sep 2019 18:48:22 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 25 Sep 2019 18:48:22 +0200
changeset 7268
a28338eaf694
parent 7229
53054eb5b15a
child 7360
9190402e4505
permissions
-rw-r--r--

Continued to resolve code style issue M841.

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
6645
ad476851d7e0 Updated copyright for 2019.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6145
diff changeset
3 # Copyright (c) 2012 - 2019 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 scripts configuration dialog.
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
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2403
diff changeset
10
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
11 from PyQt5.QtCore import pyqtSlot, Qt, QUrl
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
12 from PyQt5.QtGui import QDesktopServices
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
13 from PyQt5.QtWidgets import QDialog, QListWidgetItem
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 from E5Gui import E5MessageBox
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
17 from .Ui_GreaseMonkeyConfigurationDialog import (
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
18 Ui_GreaseMonkeyConfigurationDialog
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
19 )
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 import UI.PixmapCache
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
24 class GreaseMonkeyConfigurationDialog(
3035
36e9f388958b Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3022
diff changeset
25 QDialog, Ui_GreaseMonkeyConfigurationDialog):
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 """
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 Class implementing the GreaseMonkey scripts configuration dialog.
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 ScriptVersionRole = Qt.UserRole
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 ScriptDescriptionRole = Qt.UserRole + 1
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 ScriptRole = Qt.UserRole + 2
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 def __init__(self, manager, parent=None):
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 Constructor
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36
2954
bf0215fe12d1 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
37 @param manager reference to the manager object (GreaseMonkeyManager)
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 @param parent reference to the parent widget (QWidget)
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 """
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2403
diff changeset
40 super(GreaseMonkeyConfigurationDialog, self).__init__(parent)
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 self.setupUi(self)
4278
ccd1e13cb9bd Fixed issues where dialogs could not be minimized on some desktop environments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
42 self.setWindowFlags(Qt.Window)
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
44 self.iconLabel.setPixmap(
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
45 UI.PixmapCache.getPixmap("greaseMonkey48.png"))
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 self.__manager = manager
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 self.__loadScripts()
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 self.scriptsList.removeItemRequested.connect(self.__removeItem)
2318
3a3ee7cc2ad6 Changed some signal handlings (disconnect).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
52 self.scriptsList.itemChanged.connect(self.__itemChanged)
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 @pyqtSlot()
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 def on_openDirectoryButton_clicked(self):
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 """
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 Private slot to open the GreaseMonkey scripts directory.
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 """
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
59 QDesktopServices.openUrl(
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
60 QUrl.fromLocalFile(self.__manager.scriptsDirectory()))
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 @pyqtSlot(str)
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 def on_downloadLabel_linkActivated(self, link):
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 """
4305
2f3813e763a3 Changed the user script link in the grease monkey dialog because userscript.org is done.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4278
diff changeset
65 Private slot to open the greasyfork.org web site.
2954
bf0215fe12d1 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
66
bf0215fe12d1 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
67 @param link URL (string)
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 """
4763
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
69 from WebBrowser.WebBrowserWindow import WebBrowserWindow
4305
2f3813e763a3 Changed the user script link in the grease monkey dialog because userscript.org is done.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4278
diff changeset
70 if not link or "userscript.org" in link:
2f3813e763a3 Changed the user script link in the grease monkey dialog because userscript.org is done.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4278
diff changeset
71 # userscript.org is down, default to Greasy Fork.
2f3813e763a3 Changed the user script link in the grease monkey dialog because userscript.org is done.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4278
diff changeset
72 link = "https://greasyfork.org/"
4763
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
73 WebBrowserWindow.mainWindow().newTab(QUrl(link))
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 self.close()
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 @pyqtSlot(QListWidgetItem)
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 def on_scriptsList_itemDoubleClicked(self, item):
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 """
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 Private slot to show information about the selected script.
2954
bf0215fe12d1 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
80
bf0215fe12d1 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
81 @param item reference to the double clicked item (QListWidgetItem)
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 """
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 script = self.__getScript(item)
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 if script is not None:
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
85 from .GreaseMonkeyConfigurationScriptInfoDialog import (
2403
e3d7a861547c Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2318
diff changeset
86 GreaseMonkeyConfigurationScriptInfoDialog
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
87 )
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 infoDlg = GreaseMonkeyConfigurationScriptInfoDialog(script, self)
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 infoDlg.exec_()
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 def __loadScripts(self):
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 Private method to load all the available scripts.
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 for script in self.__manager.allScripts():
6145
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
96 itm = QListWidgetItem(self.scriptsList)
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
97 itm.setText(script.name())
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
98 icon = script.icon()
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
99 if icon.isNull:
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
100 icon = UI.PixmapCache.getIcon("greaseMonkeyScript.png")
dfe864318196 GreaseMonkey: Added support for script icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
101 itm.setIcon(icon)
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
102 itm.setData(
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
103 GreaseMonkeyConfigurationDialog.ScriptVersionRole,
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 script.version())
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
105 itm.setData(
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
106 GreaseMonkeyConfigurationDialog.ScriptDescriptionRole,
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 script.description())
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 itm.setFlags(itm.flags() | Qt.ItemIsUserCheckable)
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 if script.isEnabled():
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 itm.setCheckState(Qt.Checked)
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 else:
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 itm.setCheckState(Qt.Unchecked)
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 itm.setData(GreaseMonkeyConfigurationDialog.ScriptRole, script)
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 self.scriptsList.addItem(itm)
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 self.scriptsList.sortItems()
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 itemMoved = True
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 while itemMoved:
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 itemMoved = False
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 for row in range(self.scriptsList.count()):
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 topItem = self.scriptsList.item(row)
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 bottomItem = self.scriptsList.item(row + 1)
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 if topItem is None or bottomItem is None:
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 continue
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
127 if (
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
128 topItem.checkState() == Qt.Unchecked and
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
129 bottomItem.checkState == Qt.Checked
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
130 ):
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131 itm = self.scriptsList.takeItem(row + 1)
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 self.scriptsList.insertItem(row, itm)
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133 itemMoved = True
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135 def __getScript(self, itm):
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 """
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 Private method to get the script for the given item.
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139 @param itm item to get script for (QListWidgetItem)
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140 @return reference to the script object (GreaseMonkeyScript)
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141 """
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142 if itm is None:
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143 return None
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145 script = itm.data(GreaseMonkeyConfigurationDialog.ScriptRole)
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 return script
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 def __removeItem(self, itm):
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149 """
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150 Private slot to remove a script item.
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 @param itm item to be removed (QListWidgetItem)
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 script = self.__getScript(itm)
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 if script is None:
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156 return
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157
3020
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3002
diff changeset
158 removeIt = E5MessageBox.yesNo(
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3002
diff changeset
159 self,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
160 self.tr("Remove Script"),
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
161 self.tr(
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
162 """<p>Are you sure you want to remove <b>{0}</b>?</p>""")
3035
36e9f388958b Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3022
diff changeset
163 .format(script.name()))
1953
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 if removeIt and self.__manager.removeScript(script):
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165 self.scriptsList.takeItem(self.scriptsList.row(itm))
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 del itm
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 def __itemChanged(self, itm):
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 Private slot to handle changes of a script item.
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 @param itm changed item (QListWidgetItem)
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173 """
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174 script = self.__getScript(itm)
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175 if script is None:
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176 return
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178 if itm.checkState() == Qt.Checked:
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179 self.__manager.enableScript(script)
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180 else:
26aa6fd94dc2 Added support for GreaseMonkey scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181 self.__manager.disableScript(script)

eric ide

mercurial