12 from PyQt4.QtCore import pyqtSlot, Qt, QUrl |
12 from PyQt4.QtCore import pyqtSlot, Qt, QUrl |
13 from PyQt4.QtGui import QDialog, QListWidgetItem, QDesktopServices |
13 from PyQt4.QtGui import QDialog, QListWidgetItem, QDesktopServices |
14 |
14 |
15 from E5Gui import E5MessageBox |
15 from E5Gui import E5MessageBox |
16 |
16 |
17 from .Ui_GreaseMonkeyConfigurationDialog import Ui_GreaseMonkeyConfigurationDialog |
17 from .Ui_GreaseMonkeyConfigurationDialog import \ |
|
18 Ui_GreaseMonkeyConfigurationDialog |
18 |
19 |
19 import UI.PixmapCache |
20 import UI.PixmapCache |
20 |
21 |
21 |
22 |
22 class GreaseMonkeyConfigurationDialog(QDialog, Ui_GreaseMonkeyConfigurationDialog): |
23 class GreaseMonkeyConfigurationDialog( |
|
24 QDialog, Ui_GreaseMonkeyConfigurationDialog): |
23 """ |
25 """ |
24 Class implementing the GreaseMonkey scripts configuration dialog. |
26 Class implementing the GreaseMonkey scripts configuration dialog. |
25 """ |
27 """ |
26 ScriptVersionRole = Qt.UserRole |
28 ScriptVersionRole = Qt.UserRole |
27 ScriptDescriptionRole = Qt.UserRole + 1 |
29 ScriptDescriptionRole = Qt.UserRole + 1 |
29 |
31 |
30 def __init__(self, manager, parent=None): |
32 def __init__(self, manager, parent=None): |
31 """ |
33 """ |
32 Constructor |
34 Constructor |
33 |
35 |
|
36 @param manager reference to the manager object (GreaseMonkeyManager) |
34 @param parent reference to the parent widget (QWidget) |
37 @param parent reference to the parent widget (QWidget) |
35 """ |
38 """ |
36 super(GreaseMonkeyConfigurationDialog, self).__init__(parent) |
39 super(GreaseMonkeyConfigurationDialog, self).__init__(parent) |
37 self.setupUi(self) |
40 self.setupUi(self) |
38 |
41 |
39 self.iconLabel.setPixmap(UI.PixmapCache.getPixmap("greaseMonkey48.png")) |
42 self.iconLabel.setPixmap( |
|
43 UI.PixmapCache.getPixmap("greaseMonkey48.png")) |
40 |
44 |
41 self.__manager = manager |
45 self.__manager = manager |
42 |
46 |
43 self.__loadScripts() |
47 self.__loadScripts() |
44 |
48 |
48 @pyqtSlot() |
52 @pyqtSlot() |
49 def on_openDirectoryButton_clicked(self): |
53 def on_openDirectoryButton_clicked(self): |
50 """ |
54 """ |
51 Private slot to open the GreaseMonkey scripts directory. |
55 Private slot to open the GreaseMonkey scripts directory. |
52 """ |
56 """ |
53 QDesktopServices.openUrl(QUrl.fromLocalFile(self.__manager.scriptsDirectory())) |
57 QDesktopServices.openUrl( |
|
58 QUrl.fromLocalFile(self.__manager.scriptsDirectory())) |
54 |
59 |
55 @pyqtSlot(str) |
60 @pyqtSlot(str) |
56 def on_downloadLabel_linkActivated(self, link): |
61 def on_downloadLabel_linkActivated(self, link): |
57 """ |
62 """ |
58 Private slot to open the userscript.org web site. |
63 Private slot to open the userscript.org web site. |
|
64 |
|
65 @param link URL (string) |
59 """ |
66 """ |
60 import Helpviewer.HelpWindow |
67 import Helpviewer.HelpWindow |
61 Helpviewer.HelpWindow.HelpWindow.mainWindow().newTab( |
68 Helpviewer.HelpWindow.HelpWindow.mainWindow().newTab( |
62 QUrl("http://www.userscript.org")) |
69 QUrl("http://www.userscript.org")) |
63 self.close() |
70 self.close() |
64 |
71 |
65 @pyqtSlot(QListWidgetItem) |
72 @pyqtSlot(QListWidgetItem) |
66 def on_scriptsList_itemDoubleClicked(self, item): |
73 def on_scriptsList_itemDoubleClicked(self, item): |
67 """ |
74 """ |
68 Private slot to show information about the selected script. |
75 Private slot to show information about the selected script. |
|
76 |
|
77 @param item reference to the double clicked item (QListWidgetItem) |
69 """ |
78 """ |
70 script = self.__getScript(item) |
79 script = self.__getScript(item) |
71 if script is not None: |
80 if script is not None: |
72 from .GreaseMonkeyConfigurationScriptInfoDialog import \ |
81 from .GreaseMonkeyConfigurationScriptInfoDialog import \ |
73 GreaseMonkeyConfigurationScriptInfoDialog |
82 GreaseMonkeyConfigurationScriptInfoDialog |
77 def __loadScripts(self): |
86 def __loadScripts(self): |
78 """ |
87 """ |
79 Private method to load all the available scripts. |
88 Private method to load all the available scripts. |
80 """ |
89 """ |
81 for script in self.__manager.allScripts(): |
90 for script in self.__manager.allScripts(): |
82 itm = QListWidgetItem(UI.PixmapCache.getIcon("greaseMonkeyScript.png"), |
91 itm = QListWidgetItem( |
|
92 UI.PixmapCache.getIcon("greaseMonkeyScript.png"), |
83 script.name(), self.scriptsList) |
93 script.name(), self.scriptsList) |
84 itm.setData(GreaseMonkeyConfigurationDialog.ScriptVersionRole, |
94 itm.setData(GreaseMonkeyConfigurationDialog.ScriptVersionRole, |
85 script.version()) |
95 script.version()) |
86 itm.setData(GreaseMonkeyConfigurationDialog.ScriptDescriptionRole, |
96 itm.setData(GreaseMonkeyConfigurationDialog.ScriptDescriptionRole, |
87 script.description()) |
97 script.description()) |
133 if script is None: |
143 if script is None: |
134 return |
144 return |
135 |
145 |
136 removeIt = E5MessageBox.yesNo(self, |
146 removeIt = E5MessageBox.yesNo(self, |
137 self.trUtf8("Remove Script"), |
147 self.trUtf8("Remove Script"), |
138 self.trUtf8("""<p>Are you sure you want to remove <b>{0}</b>?</p>""") |
148 self.trUtf8( |
|
149 """<p>Are you sure you want to remove <b>{0}</b>?</p>""") |
139 .format(script.name())) |
150 .format(script.name())) |
140 if removeIt and self.__manager.removeScript(script): |
151 if removeIt and self.__manager.removeScript(script): |
141 self.scriptsList.takeItem(self.scriptsList.row(itm)) |
152 self.scriptsList.takeItem(self.scriptsList.row(itm)) |
142 del itm |
153 del itm |
143 |
154 |