eric6/UI/PythonDisViewer.py

changeset 7711
5e6792b85a8a
parent 7710
9aad21c7765d
child 7712
d8eedc2e5a0a
equal deleted inserted replaced
7710:9aad21c7765d 7711:5e6792b85a8a
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
114 if self.__mode == PythonDisViewerModes.SourceDisassemblyMode: 126 if self.__mode == PythonDisViewerModes.SourceDisassemblyMode:
115 self.__vm.disViewerStateChanged.connect( 127 self.__vm.disViewerStateChanged.connect(
116 self.__disViewerStateChanged) 128 self.__disViewerStateChanged)
117 129
118 self.codeInfoWidget.hide() 130 self.codeInfoWidget.hide()
119
120 self.hide() 131 self.hide()
121 132
122 elif self.__mode == PythonDisViewerModes.TracebackMode: 133 elif self.__mode == PythonDisViewerModes.TracebackMode:
123 self.__styleLabels() 134 self.__styleLabels()
124 135
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(
539 if lastInstructions: 552 if lastInstructions:
540 self.disWidget.scrollToItem( 553 self.disWidget.scrollToItem(
541 lastInstructions[0], 554 lastInstructions[0],
542 QAbstractItemView.PositionAtCenter) 555 QAbstractItemView.PositionAtCenter)
543 556
544 if "codeInfo" in disassembly: 557 if "codeinfo" in disassembly:
545 self.__showCodeInfoData(disassembly["codeInfo"]) 558 self.__showCodeInfoData(disassembly["codeinfo"])
546 559
547 def __resizeDisColumns(self): 560 def __resizeDisColumns(self):
548 """ 561 """
549 Private method to resize the columns of the disassembly widget to 562 Private method to resize the columns of the disassembly widget to
550 suitable values. 563 suitable values.
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)
711 self.__currentInstructionColor = QBrush( 723 self.__currentInstructionColor = QBrush(
712 Preferences.getPython("DisViewerCurrentColor")) 724 Preferences.getPython("DisViewerCurrentColor"))
713 self.__jumpTargetColor = QBrush( 725 self.__jumpTargetColor = QBrush(
714 Preferences.getPython("DisViewerLabeledColor")) 726 Preferences.getPython("DisViewerLabeledColor"))
715 727
728 self.__showCodeInfoDetails = Preferences.getPython(
729 "DisViewerExpandCodeInfoDetails")
730
716 if self.isVisible(): 731 if self.isVisible():
717 self.__loadDIS() 732 self.__loadDIS()
718 733
719 self.__styleLabels() 734 self.__styleLabels()
720 735
746 def clear(self): 761 def clear(self):
747 """ 762 """
748 Public method to clear the display. 763 Public method to clear the display.
749 """ 764 """
750 self.disWidget.clear() 765 self.disWidget.clear()
766 self.codeInfoWidget.clear()
751 767
752 def __showCodeInfo(self): 768 def __showCodeInfo(self):
753 """ 769 """
754 Private slot handling the context menu action to show code info. 770 Private slot handling the context menu action to show code info.
755 """ 771 """
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"])])
858 """ 875 """
859 if self.disWidget.topLevelItemCount() > 0: 876 if self.disWidget.topLevelItemCount() > 0:
860 # don't show context menu on empty list 877 # don't show context menu on empty list
861 coord = self.codeInfoWidget.mapToGlobal(coord) 878 coord = self.codeInfoWidget.mapToGlobal(coord)
862 self.__codeInfoMenu.popup(coord) 879 self.__codeInfoMenu.popup(coord)
880
881 def __configure(self):
882 """
883 Private method to open the configuration dialog.
884 """
885 e5App().getObject("UserInterface").showPreferences(
886 "pythonPage")

eric ide

mercurial