9 """ |
9 """ |
10 |
10 |
11 import ast |
11 import ast |
12 |
12 |
13 from PyQt5.QtCore import pyqtSlot, Qt, QTimer |
13 from PyQt5.QtCore import pyqtSlot, Qt, QTimer |
14 from PyQt5.QtGui import QCursor, QBrush |
14 from PyQt5.QtGui import QBrush |
15 from PyQt5.QtWidgets import ( |
15 from PyQt5.QtWidgets import ( |
16 QTreeWidget, QApplication, QTreeWidgetItem, QAbstractItemView, QWidget, |
16 QTreeWidget, QTreeWidgetItem, QAbstractItemView, QWidget, QVBoxLayout |
17 QVBoxLayout |
|
18 ) |
17 ) |
19 |
18 |
20 from ThirdParty.asttokens.asttokens import ASTTokens |
19 from ThirdParty.asttokens.asttokens import ASTTokens |
|
20 |
|
21 from E5Gui.E5OverrideCursor import E5OverrideCursor |
21 |
22 |
22 import Preferences |
23 import Preferences |
23 |
24 |
24 |
25 |
25 class PythonAstViewer(QWidget): |
26 class PythonAstViewer(QWidget): |
227 self.__createErrorItem(self.tr( |
228 self.__createErrorItem(self.tr( |
228 "The current editor does not contain Python source code." |
229 "The current editor does not contain Python source code." |
229 )) |
230 )) |
230 return |
231 return |
231 |
232 |
232 QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) |
233 with E5OverrideCursor(): |
233 try: |
234 try: |
234 # generate the AST |
235 # generate the AST |
235 root = ast.parse(source, self.__editor.getFileName(), "exec") |
236 root = ast.parse(source, self.__editor.getFileName(), "exec") |
236 self.__markTextRanges(root, source) |
237 self.__markTextRanges(root, source) |
237 astValid = True |
238 astValid = True |
238 except Exception as exc: |
239 except Exception as exc: |
239 self.__createErrorItem(str(exc)) |
240 self.__createErrorItem(str(exc)) |
240 astValid = False |
241 astValid = False |
241 |
|
242 if astValid: |
|
243 self.setUpdatesEnabled(False) |
|
244 |
242 |
245 # populate the AST tree |
243 if astValid: |
246 self.__populateNode(self.tr("Module"), root, self.__astWidget) |
244 self.setUpdatesEnabled(False) |
247 self.__selectItemForEditorSelection() |
245 |
248 QTimer.singleShot(0, self.__resizeColumns) |
246 # populate the AST tree |
249 |
247 self.__populateNode(self.tr("Module"), root, self.__astWidget) |
250 self.setUpdatesEnabled(True) |
248 self.__selectItemForEditorSelection() |
251 |
249 QTimer.singleShot(0, self.__resizeColumns) |
252 QApplication.restoreOverrideCursor() |
250 |
|
251 self.setUpdatesEnabled(True) |
253 |
252 |
254 self.__grabFocus() |
253 self.__grabFocus() |
255 |
254 |
256 def __populateNode(self, name, nodeOrFields, parent): |
255 def __populateNode(self, name, nodeOrFields, parent): |
257 """ |
256 """ |