113 |
113 |
114 # highlight the corresponding entry |
114 # highlight the corresponding entry |
115 QTimer.singleShot(0, self.__selectItemForEditorSelection) |
115 QTimer.singleShot(0, self.__selectItemForEditorSelection) |
116 QTimer.singleShot(0, self.__grabFocus) |
116 QTimer.singleShot(0, self.__grabFocus) |
117 |
117 |
|
118 def __editorLanguageChanged(self, editor): |
|
119 """ |
|
120 Private slot to handle a change of the editor language. |
|
121 |
|
122 @param editor reference to the editor which changed language |
|
123 @type Editor |
|
124 """ |
|
125 if editor is self.__editor: |
|
126 QTimer.singleShot(0, self.__loadDIS) |
|
127 |
118 def __lastEditorClosed(self): |
128 def __lastEditorClosed(self): |
119 """ |
129 """ |
120 Private slot to handle the last editor closed signal of the view |
130 Private slot to handle the last editor closed signal of the view |
121 manager. |
131 manager. |
122 """ |
132 """ |
130 |
140 |
131 if not self.__vmConnected: |
141 if not self.__vmConnected: |
132 self.__vm.editorChangedEd.connect(self.__editorChanged) |
142 self.__vm.editorChangedEd.connect(self.__editorChanged) |
133 self.__vm.editorSavedEd.connect(self.__editorSaved) |
143 self.__vm.editorSavedEd.connect(self.__editorSaved) |
134 self.__vm.editorDoubleClickedEd.connect(self.__editorDoubleClicked) |
144 self.__vm.editorDoubleClickedEd.connect(self.__editorDoubleClicked) |
|
145 self.__vm.editorLanguageChanged.connect( |
|
146 self.__editorLanguageChanged) |
135 self.__vmConnected = True |
147 self.__vmConnected = True |
136 |
148 |
137 def hide(self): |
149 def hide(self): |
138 """ |
150 """ |
139 Public slot to hide the AST viewer. |
151 Public slot to hide the AST viewer. |
146 if self.__vmConnected: |
158 if self.__vmConnected: |
147 self.__vm.editorChangedEd.disconnect(self.__editorChanged) |
159 self.__vm.editorChangedEd.disconnect(self.__editorChanged) |
148 self.__vm.editorSavedEd.disconnect(self.__editorSaved) |
160 self.__vm.editorSavedEd.disconnect(self.__editorSaved) |
149 self.__vm.editorDoubleClickedEd.disconnect( |
161 self.__vm.editorDoubleClickedEd.disconnect( |
150 self.__editorDoubleClicked) |
162 self.__editorDoubleClicked) |
|
163 self.__vm.editorLanguageChanged.disconnect( |
|
164 self.__editorLanguageChanged) |
151 self.__vmConnected = False |
165 self.__vmConnected = False |
152 |
166 |
153 def shutdown(self): |
167 def shutdown(self): |
154 """ |
168 """ |
155 Public method to perform shutdown actions. |
169 Public method to perform shutdown actions. |
191 """ |
205 """ |
192 Private method to generate the AST from the source of the current |
206 Private method to generate the AST from the source of the current |
193 editor and visualize it. |
207 editor and visualize it. |
194 """ |
208 """ |
195 if not self.__editor: |
209 if not self.__editor: |
|
210 self.__createErrorItem(self.tr( |
|
211 "No editor has been opened." |
|
212 )) |
196 return |
213 return |
197 |
214 |
198 self.__astWidget.clear() |
215 self.__astWidget.clear() |
199 self.__editor.clearAllHighlights() |
216 self.__editor.clearAllHighlights() |
200 |
|
201 if not self.__editor.isPyFile(): |
|
202 self.__createErrorItem(self.tr( |
|
203 "The current editor text does not contain Python source." |
|
204 )) |
|
205 return |
|
206 |
217 |
207 source = self.__editor.text() |
218 source = self.__editor.text() |
208 if not source.strip(): |
219 if not source.strip(): |
209 # empty editor or white space only |
220 # empty editor or white space only |
|
221 self.__createErrorItem(self.tr( |
|
222 "The current editor does not contain any source code." |
|
223 )) |
|
224 return |
|
225 |
|
226 if not self.__editor.isPyFile(): |
|
227 self.__createErrorItem(self.tr( |
|
228 "The current editor does not contain Python source code." |
|
229 )) |
210 return |
230 return |
211 |
231 |
212 QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) |
232 QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) |
213 try: |
233 try: |
214 # generate the AST |
234 # generate the AST |