10 from __future__ import unicode_literals # __IGNORE_WARNING__ |
10 from __future__ import unicode_literals # __IGNORE_WARNING__ |
11 |
11 |
12 import os |
12 import os |
13 |
13 |
14 from PyQt4.QtCore import QObject, QTranslator, QCoreApplication |
14 from PyQt4.QtCore import QObject, QTranslator, QCoreApplication |
15 from PyQt4.QtGui import QAction |
15 from PyQt4.QtGui import QAction, QMenu |
16 |
16 |
17 from E5Gui.E5Application import e5App |
17 from E5Gui.E5Application import e5App |
18 |
18 |
19 import Preferences |
19 import Preferences |
20 |
20 |
21 # Start-Of-Header |
21 # Start-Of-Header |
22 name = "Print Remover Plug-in" |
22 name = "Print Remover Plug-in" |
23 author = "Detlev Offenbach <detlev@die-offenbachs.de>" |
23 author = "Detlev Offenbach <detlev@die-offenbachs.de>" |
24 autoactivate = True |
24 autoactivate = True |
25 deactivateable = True |
25 deactivateable = True |
26 version = "0.5.0" |
26 version = "0.6.0" |
27 className = "PrintRemoverPlugin" |
27 className = "PrintRemoverPlugin" |
28 packageName = "PrintRemover" |
28 packageName = "PrintRemover" |
29 shortDescription = "Remove print() like debug statements." |
29 shortDescription = "Remove print() like debug statements." |
30 longDescription = \ |
30 longDescription = \ |
31 """This plug-in implements a tool to remove lines starting with""" \ |
31 """This plug-in implements a tool to remove lines starting with""" \ |
191 @param value the value to be set |
194 @param value the value to be set |
192 """ |
195 """ |
193 Preferences.Prefs.settings.setValue( |
196 Preferences.Prefs.settings.setValue( |
194 self.PreferencesKey + "/" + key, value) |
197 self.PreferencesKey + "/" + key, value) |
195 |
198 |
|
199 def __initMenu(self): |
|
200 """ |
|
201 Private method to initialize the menu. |
|
202 """ |
|
203 self.__menu = QMenu("Remove Outputs") |
|
204 self.__menu.setEnabled(False) |
|
205 self.__menu.aboutToShow.connect(self.__showMenu) |
|
206 |
196 def __populateMenu(self, name, menu): |
207 def __populateMenu(self, name, menu): |
197 """ |
208 """ |
198 Private slot to populate the tools menu with our entries. |
209 Private slot to populate the tools menu with our entries. |
199 |
210 |
200 @param name name of the menu (string) |
211 @param name name of the menu (string) |
206 editor = e5App().getObject("ViewManager").activeWindow() |
217 editor = e5App().getObject("ViewManager").activeWindow() |
207 |
218 |
208 if not menu.isEmpty(): |
219 if not menu.isEmpty(): |
209 menu.addSeparator() |
220 menu.addSeparator() |
210 |
221 |
211 # TODO: change this to a dynamically built submenu |
222 act = menu.addMenu(self.__menu) |
212 for string in self.getPreferences("StartswithStrings"): |
223 act.setEnabled(editor is not None) |
213 act = menu.addAction( |
|
214 self.tr("Remove '{0}'").format(string), |
|
215 self.__removeLine) |
|
216 act.setData(string) |
|
217 act.setEnabled(editor is not None) |
|
218 |
224 |
219 def __editorOpened(self, editor): |
225 def __editorOpened(self, editor): |
220 """ |
226 """ |
221 Private slot called, when a new editor was opened. |
227 Private slot called, when a new editor was opened. |
222 |
228 |
223 @param editor reference to the new editor (QScintilla.Editor) |
229 @param editor reference to the new editor (QScintilla.Editor) |
224 """ |
230 """ |
225 # TODO: change this to a dynamically built submenu |
|
226 menu = editor.getMenu("Tools") |
231 menu = editor.getMenu("Tools") |
227 if menu is not None: |
232 if menu is not None: |
228 self.__editors[editor] = [] |
233 self.__editors[editor] = [] |
229 if not menu.isEmpty(): |
234 if not menu.isEmpty(): |
230 act = menu.addSeparator() |
235 act = menu.addSeparator() |
231 self.__editors[editor].append(act) |
236 self.__editors[editor].append(act) |
232 for string in self.getPreferences("StartswithStrings"): |
237 act = menu.addMenu(self.__menu) |
233 act = menu.addAction( |
238 self.__menu.setEnabled(True) |
|
239 self.__editors[editor].append(act) |
|
240 |
|
241 def __editorClosed(self, editor): |
|
242 """ |
|
243 Private slot called, when an editor was closed. |
|
244 |
|
245 @param editor reference to the editor (QScintilla.Editor) |
|
246 """ |
|
247 try: |
|
248 del self.__editors[editor] |
|
249 if not self.__editors: |
|
250 self.__menu.setEnabled(False) |
|
251 except KeyError: |
|
252 pass |
|
253 |
|
254 def __showMenu(self): |
|
255 """ |
|
256 Private slot to build the menu hierarchy. |
|
257 """ |
|
258 self.__menu.clear() |
|
259 for string in self.getPreferences("StartswithStrings"): |
|
260 if string == '--Separator--': |
|
261 self.__menu.addSeparator() |
|
262 else: |
|
263 act = self.__menu.addAction( |
234 self.tr("Remove '{0}'").format(string), |
264 self.tr("Remove '{0}'").format(string), |
235 self.__removeLine) |
265 self.__removeLine) |
236 act.setData(string) |
266 act.setData(string) |
237 self.__editors[editor].append(act) |
|
238 |
|
239 def __editorClosed(self, editor): |
|
240 """ |
|
241 Private slot called, when an editor was closed. |
|
242 |
|
243 @param editor reference to the editor (QScintilla.Editor) |
|
244 """ |
|
245 try: |
|
246 del self.__editors[editor] |
|
247 except KeyError: |
|
248 pass |
|
249 |
267 |
250 def __removeLine(self): |
268 def __removeLine(self): |
251 """ |
269 """ |
252 Private slot to remove lines starting with the selected pattern. |
270 Private slot to remove lines starting with the selected pattern. |
253 """ |
271 """ |