17 from PyQt5.QtCore import pyqtSlot, Qt, QTimer |
17 from PyQt5.QtCore import pyqtSlot, Qt, QTimer |
18 from PyQt5.QtGui import QCursor, QBrush |
18 from PyQt5.QtGui import QCursor, QBrush |
19 from PyQt5.QtWidgets import ( |
19 from PyQt5.QtWidgets import ( |
20 QApplication, QTreeWidgetItem, QAbstractItemView, QWidget, QMenu |
20 QApplication, QTreeWidgetItem, QAbstractItemView, QWidget, QMenu |
21 ) |
21 ) |
|
22 |
|
23 from E5Gui.E5Application import e5App |
22 |
24 |
23 import Preferences |
25 import Preferences |
24 |
26 |
25 from .Ui_PythonDisViewer import Ui_PythonDisViewer |
27 from .Ui_PythonDisViewer import Ui_PythonDisViewer |
26 |
28 |
81 self.__disMenu.addSeparator() |
83 self.__disMenu.addSeparator() |
82 self.__disMenu.addAction( |
84 self.__disMenu.addAction( |
83 self.tr('Expand All'), self.__expandAllDis) |
85 self.tr('Expand All'), self.__expandAllDis) |
84 self.__disMenu.addAction( |
86 self.__disMenu.addAction( |
85 self.tr('Collapse All'), self.__collapseAllDis) |
87 self.tr('Collapse All'), self.__collapseAllDis) |
|
88 self.__disMenu.addSeparator() |
|
89 self.__disMenu.addAction( |
|
90 self.tr('Configure...'), self.__configure) |
86 |
91 |
87 self.__codeInfoMenu = QMenu(self.codeInfoWidget) |
92 self.__codeInfoMenu = QMenu(self.codeInfoWidget) |
88 if self.__mode == PythonDisViewerModes.SourceDisassemblyMode: |
93 if self.__mode == PythonDisViewerModes.SourceDisassemblyMode: |
89 self.__codeInfoMenu.addAction( |
94 self.__codeInfoMenu.addAction( |
90 self.tr("Hide"), self.codeInfoWidget.hide) |
95 self.tr("Hide"), self.codeInfoWidget.hide) |
91 self.__codeInfoMenu.addAction( |
96 self.__codeInfoMenu.addAction( |
92 self.tr('Expand All'), self.__expandAllCodeInfo) |
97 self.tr('Expand All'), self.__expandAllCodeInfo) |
93 self.__codeInfoMenu.addAction( |
98 self.__codeInfoMenu.addAction( |
94 self.tr('Collapse All'), self.__collapseAllCodeInfo) |
99 self.tr('Collapse All'), self.__collapseAllCodeInfo) |
|
100 self.__codeInfoMenu.addSeparator() |
|
101 self.__codeInfoMenu.addAction( |
|
102 self.tr('Configure...'), self.__configure) |
95 |
103 |
96 self.__errorColor = QBrush( |
104 self.__errorColor = QBrush( |
97 Preferences.getPython("DisViewerErrorColor")) |
105 Preferences.getPython("DisViewerErrorColor")) |
98 self.__currentInstructionColor = QBrush( |
106 self.__currentInstructionColor = QBrush( |
99 Preferences.getPython("DisViewerCurrentColor")) |
107 Preferences.getPython("DisViewerCurrentColor")) |
100 self.__jumpTargetColor = QBrush( |
108 self.__jumpTargetColor = QBrush( |
101 Preferences.getPython("DisViewerLabeledColor")) |
109 Preferences.getPython("DisViewerLabeledColor")) |
102 |
110 |
103 self.disWidget.itemClicked.connect(self.__disItemClicked) |
111 self.__showCodeInfoDetails = Preferences.getPython( |
|
112 "DisViewerExpandCodeInfoDetails") |
|
113 |
|
114 if self.__mode == PythonDisViewerModes.SourceDisassemblyMode: |
|
115 self.disWidget.itemClicked.connect(self.__disItemClicked) |
104 self.disWidget.itemCollapsed.connect(self.__resizeDisColumns) |
116 self.disWidget.itemCollapsed.connect(self.__resizeDisColumns) |
105 self.disWidget.itemExpanded.connect(self.__resizeDisColumns) |
117 self.disWidget.itemExpanded.connect(self.__resizeDisColumns) |
106 self.disWidget.customContextMenuRequested.connect( |
118 self.disWidget.customContextMenuRequested.connect( |
107 self.__disContextMenuRequested) |
119 self.__disContextMenuRequested) |
108 |
120 |
406 @rtype dict |
417 @rtype dict |
407 """ |
418 """ |
408 return { |
419 return { |
409 "name": co.co_name, |
420 "name": co.co_name, |
410 "filename": co.co_filename, |
421 "filename": co.co_filename, |
|
422 "firstlineno": co.co_firstlineno, |
411 "argcount": co.co_argcount, |
423 "argcount": co.co_argcount, |
412 "posonlyargcount": co.co_posonlyargcount, |
424 "posonlyargcount": co.co_posonlyargcount, |
413 "kwonlyargcount": co.co_kwonlyargcount, |
425 "kwonlyargcount": co.co_kwonlyargcount, |
414 "nlocals": co.co_nlocals, |
426 "nlocals": co.co_nlocals, |
415 "stacksize": co.co_stacksize, |
427 "stacksize": co.co_stacksize, |
416 "flags": dis.pretty_flags(co.co_flags), |
428 "flags": dis.pretty_flags(co.co_flags), |
417 "consts": co.co_consts, |
429 "consts": [str(const) for const in co.co_consts], |
418 "names": co.co_names, |
430 "names": [str(name) for name in co.co_names], |
419 "varnames": co.co_varnames, |
431 "varnames": [str(name) for name in co.co_varnames], |
420 "freevars": co.co_freevars, |
432 "freevars": [str(var) for var in co.co_freevars], |
421 "cellvars": co.co_cellvars, |
433 "cellvars": [str(var) for var in co.co_cellvars], |
422 } |
434 } |
423 |
435 |
424 def __loadDIS(self): |
436 def __loadDIS(self): |
425 """ |
437 """ |
426 Private method to generate the Disassembly from the source of the |
438 Private method to generate the Disassembly from the source of the |
434 self.__createErrorItem(self.tr( |
446 self.__createErrorItem(self.tr( |
435 "No editor has been opened." |
447 "No editor has been opened." |
436 )) |
448 )) |
437 return |
449 return |
438 |
450 |
439 self.disWidget.clear() |
451 self.clear() |
440 self.__editor.clearAllHighlights() |
452 self.__editor.clearAllHighlights() |
|
453 self.codeInfoWidget.hide() |
441 |
454 |
442 source = self.__editor.text() |
455 source = self.__editor.text() |
443 if not source.strip(): |
456 if not source.strip(): |
444 # empty editor or white space only |
457 # empty editor or white space only |
445 self.__createErrorItem(self.tr( |
458 self.__createErrorItem(self.tr( |
623 @param itm reference to the clicked item |
636 @param itm reference to the clicked item |
624 @type QTreeWidgetItem |
637 @type QTreeWidgetItem |
625 @param column column number of the click |
638 @param column column number of the click |
626 @type int |
639 @type int |
627 """ |
640 """ |
628 # TODO: add code to deal with Traceback mode |
|
629 self.__editor.clearAllHighlights() |
641 self.__editor.clearAllHighlights() |
630 |
642 |
631 if itm is not None: |
643 if itm is not None: |
632 startLine = itm.data(0, self.StartLineRole) |
644 startLine = itm.data(0, self.StartLineRole) |
633 endLine = itm.data(0, self.EndLineRole) |
645 endLine = itm.data(0, self.EndLineRole) |
775 @param infoList list of info strings |
791 @param infoList list of info strings |
776 @type list of str |
792 @type list of str |
777 """ |
793 """ |
778 parent = QTreeWidgetItem(self.codeInfoWidget, |
794 parent = QTreeWidgetItem(self.codeInfoWidget, |
779 [title, str(len(infoList))]) |
795 [title, str(len(infoList))]) |
780 # TODO: make this a configuration item |
796 parent.setExpanded(self.__showCodeInfoDetails) |
781 parent.setExpanded(False) |
|
782 |
797 |
783 for index, value in enumerate(infoList): |
798 for index, value in enumerate(infoList): |
784 itm = QTreeWidgetItem(parent, [str(index), str(value)]) |
799 itm = QTreeWidgetItem(parent, [str(index), str(value)]) |
785 itm.setTextAlignment(0, Qt.AlignRight) |
800 itm.setTextAlignment(0, Qt.AlignRight) |
786 |
801 |
789 if codeInfo: |
804 if codeInfo: |
790 QTreeWidgetItem(self.codeInfoWidget, [ |
805 QTreeWidgetItem(self.codeInfoWidget, [ |
791 self.tr("Name"), codeInfo["name"]]) |
806 self.tr("Name"), codeInfo["name"]]) |
792 QTreeWidgetItem(self.codeInfoWidget, [ |
807 QTreeWidgetItem(self.codeInfoWidget, [ |
793 self.tr("Filename"), codeInfo["filename"]]) |
808 self.tr("Filename"), codeInfo["filename"]]) |
|
809 QTreeWidgetItem(self.codeInfoWidget, [ |
|
810 self.tr("First Line"), str(codeInfo["firstlineno"])]) |
794 QTreeWidgetItem(self.codeInfoWidget, [ |
811 QTreeWidgetItem(self.codeInfoWidget, [ |
795 self.tr("Argument Count"), str(codeInfo["argcount"])]) |
812 self.tr("Argument Count"), str(codeInfo["argcount"])]) |
796 QTreeWidgetItem(self.codeInfoWidget, [ |
813 QTreeWidgetItem(self.codeInfoWidget, [ |
797 self.tr("Positional-only Arguments"), |
814 self.tr("Positional-only Arguments"), |
798 str(codeInfo["posonlyargcount"])]) |
815 str(codeInfo["posonlyargcount"])]) |