14 from PyQt6.QtCore import pyqtSlot, QDir |
14 from PyQt6.QtCore import pyqtSlot, QDir |
15 from PyQt6.QtWidgets import QDialog |
15 from PyQt6.QtWidgets import QDialog |
16 |
16 |
17 from .Ui_GreaseMonkeyAddScriptDialog import Ui_GreaseMonkeyAddScriptDialog |
17 from .Ui_GreaseMonkeyAddScriptDialog import Ui_GreaseMonkeyAddScriptDialog |
18 |
18 |
19 import UI.PixmapCache |
19 from eric7.EricGui import EricPixmapCache |
20 from UI.NotificationWidget import NotificationTypes |
20 from eric7.UI.NotificationWidget import NotificationTypes |
21 |
21 |
22 |
22 |
23 class GreaseMonkeyAddScriptDialog(QDialog, Ui_GreaseMonkeyAddScriptDialog): |
23 class GreaseMonkeyAddScriptDialog(QDialog, Ui_GreaseMonkeyAddScriptDialog): |
24 """ |
24 """ |
25 Class implementing a dialog for adding GreaseMonkey scripts.. |
25 Class implementing a dialog for adding GreaseMonkey scripts.. |
35 @param parent reference to the parent widget (QWidget) |
35 @param parent reference to the parent widget (QWidget) |
36 """ |
36 """ |
37 super().__init__(parent) |
37 super().__init__(parent) |
38 self.setupUi(self) |
38 self.setupUi(self) |
39 |
39 |
40 self.iconLabel.setPixmap(UI.PixmapCache.getPixmap("greaseMonkey48")) |
40 self.iconLabel.setPixmap(EricPixmapCache.getPixmap("greaseMonkey48")) |
41 |
41 |
42 self.__manager = manager |
42 self.__manager = manager |
43 self.__script = script |
43 self.__script = script |
44 |
44 |
45 runsAt = "" |
45 runsAt = "" |
68 @pyqtSlot() |
68 @pyqtSlot() |
69 def on_showScriptSourceButton_clicked(self): |
69 def on_showScriptSourceButton_clicked(self): |
70 """ |
70 """ |
71 Private slot to show an editor window with the source code. |
71 Private slot to show an editor window with the source code. |
72 """ |
72 """ |
73 from WebBrowser.Tools import WebBrowserTools |
73 from eric7.WebBrowser.Tools import WebBrowserTools |
74 |
74 |
75 tmpFileName = WebBrowserTools.ensureUniqueFilename( |
75 tmpFileName = WebBrowserTools.ensureUniqueFilename( |
76 os.path.join(QDir.tempPath(), "tmp-userscript.js") |
76 os.path.join(QDir.tempPath(), "tmp-userscript.js") |
77 ) |
77 ) |
78 if shutil.copy(self.__script.fileName(), tmpFileName): |
78 if shutil.copy(self.__script.fileName(), tmpFileName): |
79 from QScintilla.MiniEditor import MiniEditor |
79 from eric7.QScintilla.MiniEditor import MiniEditor |
80 |
80 |
81 editor = MiniEditor(tmpFileName, "JavaScript", self) |
81 editor = MiniEditor(tmpFileName, "JavaScript", self) |
82 editor.show() |
82 editor.show() |
83 |
83 |
84 def __accepted(self): |
84 def __accepted(self): |
92 success = True |
92 success = True |
93 else: |
93 else: |
94 msg = self.tr("<p>Cannot install script.</p>") |
94 msg = self.tr("<p>Cannot install script.</p>") |
95 success = False |
95 success = False |
96 |
96 |
97 from WebBrowser.WebBrowserWindow import WebBrowserWindow |
97 from eric7.WebBrowser.WebBrowserWindow import WebBrowserWindow |
98 |
98 |
99 if success: |
99 if success: |
100 WebBrowserWindow.showNotification( |
100 WebBrowserWindow.showNotification( |
101 UI.PixmapCache.getPixmap("greaseMonkey48"), |
101 EricPixmapCache.getPixmap("greaseMonkey48"), |
102 self.tr("GreaseMonkey Script Installation"), |
102 self.tr("GreaseMonkey Script Installation"), |
103 msg, |
103 msg, |
104 ) |
104 ) |
105 else: |
105 else: |
106 WebBrowserWindow.showNotification( |
106 WebBrowserWindow.showNotification( |
107 UI.PixmapCache.getPixmap("greaseMonkey48"), |
107 EricPixmapCache.getPixmap("greaseMonkey48"), |
108 self.tr("GreaseMonkey Script Installation"), |
108 self.tr("GreaseMonkey Script Installation"), |
109 msg, |
109 msg, |
110 kind=NotificationTypes.CRITICAL, |
110 kind=NotificationTypes.CRITICAL, |
111 timeout=0, |
111 timeout=0, |
112 ) |
112 ) |