src/eric7/WebBrowser/GreaseMonkey/GreaseMonkeyAddScriptDialog.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9413
80c06d472826
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
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..
26 """ 26 """
27
27 def __init__(self, manager, script, parent=None): 28 def __init__(self, manager, script, parent=None):
28 """ 29 """
29 Constructor 30 Constructor
30 31
31 @param manager reference to the GreaseMonkey manager 32 @param manager reference to the GreaseMonkey manager
32 (GreaseMonkeyManager) 33 (GreaseMonkeyManager)
33 @param script GreaseMonkey script to be added (GreaseMonkeyScript) 34 @param script GreaseMonkey script to be added (GreaseMonkeyScript)
34 @param parent reference to the parent widget (QWidget) 35 @param parent reference to the parent widget (QWidget)
35 """ 36 """
36 super().__init__(parent) 37 super().__init__(parent)
37 self.setupUi(self) 38 self.setupUi(self)
38 39
39 self.iconLabel.setPixmap( 40 self.iconLabel.setPixmap(UI.PixmapCache.getPixmap("greaseMonkey48"))
40 UI.PixmapCache.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 = ""
46 doesNotRunAt = "" 46 doesNotRunAt = ""
47 47
48 include = script.include() 48 include = script.include()
49 exclude = script.exclude() 49 exclude = script.exclude()
50 50
51 if include: 51 if include:
52 runsAt = self.tr("<p>runs at:<br/><i>{0}</i></p>").format( 52 runsAt = self.tr("<p>runs at:<br/><i>{0}</i></p>").format(
53 "<br/>".join(include)) 53 "<br/>".join(include)
54 54 )
55
55 if exclude: 56 if exclude:
56 doesNotRunAt = self.tr( 57 doesNotRunAt = self.tr("<p>does not run at:<br/><i>{0}</i></p>").format(
57 "<p>does not run at:<br/><i>{0}</i></p>").format( 58 "<br/>".join(exclude)
58 "<br/>".join(exclude)) 59 )
59 60
60 scriptInfoTxt = "<p><b>{0}</b> {1}<br/>{2}</p>{3}{4}".format( 61 scriptInfoTxt = "<p><b>{0}</b> {1}<br/>{2}</p>{3}{4}".format(
61 script.name(), script.version(), script.description(), runsAt, 62 script.name(), script.version(), script.description(), runsAt, doesNotRunAt
62 doesNotRunAt) 63 )
63 self.scriptInfo.setHtml(scriptInfoTxt) 64 self.scriptInfo.setHtml(scriptInfoTxt)
64 65
65 self.accepted.connect(self.__accepted) 66 self.accepted.connect(self.__accepted)
66 67
67 @pyqtSlot() 68 @pyqtSlot()
68 def on_showScriptSourceButton_clicked(self): 69 def on_showScriptSourceButton_clicked(self):
69 """ 70 """
70 Private slot to show an editor window with the source code. 71 Private slot to show an editor window with the source code.
71 """ 72 """
72 from WebBrowser.Tools import WebBrowserTools 73 from WebBrowser.Tools import WebBrowserTools
73 74
74 tmpFileName = WebBrowserTools.ensureUniqueFilename( 75 tmpFileName = WebBrowserTools.ensureUniqueFilename(
75 os.path.join(QDir.tempPath(), "tmp-userscript.js")) 76 os.path.join(QDir.tempPath(), "tmp-userscript.js")
77 )
76 if shutil.copy(self.__script.fileName(), tmpFileName): 78 if shutil.copy(self.__script.fileName(), tmpFileName):
77 from QScintilla.MiniEditor import MiniEditor 79 from QScintilla.MiniEditor import MiniEditor
80
78 editor = MiniEditor(tmpFileName, "JavaScript", self) 81 editor = MiniEditor(tmpFileName, "JavaScript", self)
79 editor.show() 82 editor.show()
80 83
81 def __accepted(self): 84 def __accepted(self):
82 """ 85 """
83 Private slot handling the accepted signal. 86 Private slot handling the accepted signal.
84 """ 87 """
85 if self.__manager.addScript(self.__script): 88 if self.__manager.addScript(self.__script):
86 msg = self.tr( 89 msg = self.tr("<p><b>{0}</b> installed successfully.</p>").format(
87 "<p><b>{0}</b> installed successfully.</p>").format( 90 self.__script.name()
88 self.__script.name()) 91 )
89 success = True 92 success = True
90 else: 93 else:
91 msg = self.tr("<p>Cannot install script.</p>") 94 msg = self.tr("<p>Cannot install script.</p>")
92 success = False 95 success = False
93 96
94 from WebBrowser.WebBrowserWindow import WebBrowserWindow 97 from WebBrowser.WebBrowserWindow import WebBrowserWindow
98
95 if success: 99 if success:
96 WebBrowserWindow.showNotification( 100 WebBrowserWindow.showNotification(
97 UI.PixmapCache.getPixmap("greaseMonkey48"), 101 UI.PixmapCache.getPixmap("greaseMonkey48"),
98 self.tr("GreaseMonkey Script Installation"), 102 self.tr("GreaseMonkey Script Installation"),
99 msg) 103 msg,
104 )
100 else: 105 else:
101 WebBrowserWindow.showNotification( 106 WebBrowserWindow.showNotification(
102 UI.PixmapCache.getPixmap("greaseMonkey48"), 107 UI.PixmapCache.getPixmap("greaseMonkey48"),
103 self.tr("GreaseMonkey Script Installation"), 108 self.tr("GreaseMonkey Script Installation"),
104 msg, 109 msg,
105 kind=NotificationTypes.CRITICAL, 110 kind=NotificationTypes.CRITICAL,
106 timeout=0) 111 timeout=0,
112 )

eric ide

mercurial