Plugins/PluginTabnanny.py

changeset 53
c3eb7cc1ff8b
parent 40
c2e5472b112c
child 55
b5c84934de9c
equal deleted inserted replaced
52:ba69827929ee 53:c3eb7cc1ff8b
9 9
10 import os 10 import os
11 11
12 from PyQt4.QtCore import QObject, SIGNAL 12 from PyQt4.QtCore import QObject, SIGNAL
13 13
14 from E4Gui.E4Application import e4App 14 from E4Gui.E4Application import e5App
15 15
16 from E4Gui.E4Action import E4Action 16 from E4Gui.E4Action import E4Action
17 17
18 from CheckerPlugins.Tabnanny.TabnannyDialog import TabnannyDialog 18 from CheckerPlugins.Tabnanny.TabnannyDialog import TabnannyDialog
19 19
68 """ 68 """
69 Public method to activate this plugin. 69 Public method to activate this plugin.
70 70
71 @return tuple of None and activation status (boolean) 71 @return tuple of None and activation status (boolean)
72 """ 72 """
73 menu = e4App().getObject("Project").getMenu("Checks") 73 menu = e5App().getObject("Project").getMenu("Checks")
74 if menu: 74 if menu:
75 self.__projectAct = E4Action(self.trUtf8('Check Indentations'), 75 self.__projectAct = E4Action(self.trUtf8('Check Indentations'),
76 self.trUtf8('&Indentations...'), 0, 0, 76 self.trUtf8('&Indentations...'), 0, 0,
77 self,'project_check_indentations') 77 self,'project_check_indentations')
78 self.__projectAct.setStatusTip(\ 78 self.__projectAct.setStatusTip(\
81 """<b>Check Indentations...</b>""" 81 """<b>Check Indentations...</b>"""
82 """<p>This checks Python files""" 82 """<p>This checks Python files"""
83 """ for bad indentations using tabnanny.</p>""" 83 """ for bad indentations using tabnanny.</p>"""
84 )) 84 ))
85 self.connect(self.__projectAct, SIGNAL('triggered()'), self.__projectTabnanny) 85 self.connect(self.__projectAct, SIGNAL('triggered()'), self.__projectTabnanny)
86 e4App().getObject("Project").addE4Actions([self.__projectAct]) 86 e5App().getObject("Project").addE4Actions([self.__projectAct])
87 menu.addAction(self.__projectAct) 87 menu.addAction(self.__projectAct)
88 88
89 self.__editorAct = E4Action(self.trUtf8('Check Indentations'), 89 self.__editorAct = E4Action(self.trUtf8('Check Indentations'),
90 self.trUtf8('&Indentations...'), 0, 0, 90 self.trUtf8('&Indentations...'), 0, 0,
91 self, "") 91 self, "")
94 """<p>This checks Python files""" 94 """<p>This checks Python files"""
95 """ for bad indentations using tabnanny.</p>""" 95 """ for bad indentations using tabnanny.</p>"""
96 )) 96 ))
97 self.connect(self.__editorAct, SIGNAL('triggered()'), self.__editorTabnanny) 97 self.connect(self.__editorAct, SIGNAL('triggered()'), self.__editorTabnanny)
98 98
99 self.connect(e4App().getObject("Project"), SIGNAL("showMenu"), 99 self.connect(e5App().getObject("Project"), SIGNAL("showMenu"),
100 self.__projectShowMenu) 100 self.__projectShowMenu)
101 self.connect(e4App().getObject("ProjectBrowser").getProjectBrowser("sources"), 101 self.connect(e5App().getObject("ProjectBrowser").getProjectBrowser("sources"),
102 SIGNAL("showMenu"), self.__projectBrowserShowMenu) 102 SIGNAL("showMenu"), self.__projectBrowserShowMenu)
103 self.connect(e4App().getObject("ViewManager"), SIGNAL("editorOpenedEd"), 103 self.connect(e5App().getObject("ViewManager"), SIGNAL("editorOpenedEd"),
104 self.__editorOpened) 104 self.__editorOpened)
105 self.connect(e4App().getObject("ViewManager"), SIGNAL("editorClosedEd"), 105 self.connect(e5App().getObject("ViewManager"), SIGNAL("editorClosedEd"),
106 self.__editorClosed) 106 self.__editorClosed)
107 107
108 for editor in e4App().getObject("ViewManager").getOpenEditors(): 108 for editor in e5App().getObject("ViewManager").getOpenEditors():
109 self.__editorOpened(editor) 109 self.__editorOpened(editor)
110 110
111 return None, True 111 return None, True
112 112
113 def deactivate(self): 113 def deactivate(self):
114 """ 114 """
115 Public method to deactivate this plugin. 115 Public method to deactivate this plugin.
116 """ 116 """
117 self.disconnect(e4App().getObject("Project"), SIGNAL("showMenu"), 117 self.disconnect(e5App().getObject("Project"), SIGNAL("showMenu"),
118 self.__projectShowMenu) 118 self.__projectShowMenu)
119 self.disconnect(e4App().getObject("ProjectBrowser").getProjectBrowser("sources"), 119 self.disconnect(e5App().getObject("ProjectBrowser").getProjectBrowser("sources"),
120 SIGNAL("showMenu"), self.__projectBrowserShowMenu) 120 SIGNAL("showMenu"), self.__projectBrowserShowMenu)
121 self.disconnect(e4App().getObject("ViewManager"), SIGNAL("editorOpenedEd"), 121 self.disconnect(e5App().getObject("ViewManager"), SIGNAL("editorOpenedEd"),
122 self.__editorOpened) 122 self.__editorOpened)
123 self.disconnect(e4App().getObject("ViewManager"), SIGNAL("editorClosedEd"), 123 self.disconnect(e5App().getObject("ViewManager"), SIGNAL("editorClosedEd"),
124 self.__editorClosed) 124 self.__editorClosed)
125 125
126 menu = e4App().getObject("Project").getMenu("Checks") 126 menu = e5App().getObject("Project").getMenu("Checks")
127 if menu: 127 if menu:
128 menu.removeAction(self.__projectAct) 128 menu.removeAction(self.__projectAct)
129 129
130 if self.__projectBrowserMenu: 130 if self.__projectBrowserMenu:
131 if self.__projectBrowserAct: 131 if self.__projectBrowserAct:
147 @param menuName name of the menu to be shown (string) 147 @param menuName name of the menu to be shown (string)
148 @param menu reference to the menu (QMenu) 148 @param menu reference to the menu (QMenu)
149 """ 149 """
150 if menuName == "Checks" and self.__projectAct is not None: 150 if menuName == "Checks" and self.__projectAct is not None:
151 self.__projectAct.setEnabled(\ 151 self.__projectAct.setEnabled(\
152 e4App().getObject("Project").getProjectLanguage() == "Python3") 152 e5App().getObject("Project").getProjectLanguage() == "Python3")
153 153
154 def __projectBrowserShowMenu(self, menuName, menu): 154 def __projectBrowserShowMenu(self, menuName, menu):
155 """ 155 """
156 Private slot called, when the the project browser context menu or a submenu is 156 Private slot called, when the the project browser context menu or a submenu is
157 about to be shown. 157 about to be shown.
158 158
159 @param menuName name of the menu to be shown (string) 159 @param menuName name of the menu to be shown (string)
160 @param menu reference to the menu (QMenu) 160 @param menu reference to the menu (QMenu)
161 """ 161 """
162 if menuName == "Checks" and \ 162 if menuName == "Checks" and \
163 e4App().getObject("Project").getProjectLanguage() == "Python3": 163 e5App().getObject("Project").getProjectLanguage() == "Python3":
164 self.__projectBrowserMenu = menu 164 self.__projectBrowserMenu = menu
165 if self.__projectBrowserAct is None: 165 if self.__projectBrowserAct is None:
166 self.__projectBrowserAct = E4Action(self.trUtf8('Check Indentations'), 166 self.__projectBrowserAct = E4Action(self.trUtf8('Check Indentations'),
167 self.trUtf8('&Indentations...'), 0, 0, 167 self.trUtf8('&Indentations...'), 0, 0,
168 self, "") 168 self, "")
178 178
179 def __projectTabnanny(self): 179 def __projectTabnanny(self):
180 """ 180 """
181 Public slot used to check the project files for bad indentations. 181 Public slot used to check the project files for bad indentations.
182 """ 182 """
183 project = e4App().getObject("Project") 183 project = e5App().getObject("Project")
184 project.saveAllScripts() 184 project.saveAllScripts()
185 files = [os.path.join(project.ppath, file) \ 185 files = [os.path.join(project.ppath, file) \
186 for file in project.pdata["SOURCES"] \ 186 for file in project.pdata["SOURCES"] \
187 if file.endswith(tuple(Preferences.getPython("Python3Extensions")))] 187 if file.endswith(tuple(Preferences.getPython("Python3Extensions")))]
188 188
193 def __projectBrowserTabnanny(self): 193 def __projectBrowserTabnanny(self):
194 """ 194 """
195 Private method to handle the tabnanny context menu action of the project 195 Private method to handle the tabnanny context menu action of the project
196 sources browser. 196 sources browser.
197 """ 197 """
198 browser = e4App().getObject("ProjectBrowser").getProjectBrowser("sources") 198 browser = e5App().getObject("ProjectBrowser").getProjectBrowser("sources")
199 itm = browser.model().item(browser.currentIndex()) 199 itm = browser.model().item(browser.currentIndex())
200 try: 200 try:
201 fn = itm.fileName() 201 fn = itm.fileName()
202 except AttributeError: 202 except AttributeError:
203 fn = itm.dirName() 203 fn = itm.dirName()
245 245
246 def __editorTabnanny(self): 246 def __editorTabnanny(self):
247 """ 247 """
248 Private slot to handle the tabnanny context menu action of the editors. 248 Private slot to handle the tabnanny context menu action of the editors.
249 """ 249 """
250 editor = e4App().getObject("ViewManager").activeWindow() 250 editor = e5App().getObject("ViewManager").activeWindow()
251 if editor is not None: 251 if editor is not None:
252 if not editor.checkDirty(): 252 if not editor.checkDirty():
253 return 253 return
254 254
255 self.__editorTabnannyDialog = TabnannyDialog() 255 self.__editorTabnannyDialog = TabnannyDialog()

eric ide

mercurial