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 |