eric6/Debugger/VariablesViewer.py

branch
Variables Viewer
changeset 7012
cc3f83d1a605
parent 6994
681ed8916e69
child 7013
a3904952065b
equal deleted inserted replaced
6995:ee314cf3b1c9 7012:cc3f83d1a605
16 16
17 import ast 17 import ast
18 18
19 from PyQt5.QtCore import (Qt, QAbstractItemModel, QModelIndex, QRegExp, 19 from PyQt5.QtCore import (Qt, QAbstractItemModel, QModelIndex, QRegExp,
20 QCoreApplication, QSortFilterProxyModel, pyqtSignal) 20 QCoreApplication, QSortFilterProxyModel, pyqtSignal)
21 from PyQt5.QtGui import QBrush, QColor, QFontMetrics 21 from PyQt5.QtGui import QBrush, QFontMetrics
22 from PyQt5.QtWidgets import QTreeView, QAbstractItemView, QToolTip, QMenu 22 from PyQt5.QtWidgets import QTreeView, QAbstractItemView, QToolTip, QMenu
23 23
24 from E5Gui.E5Application import e5App 24 from E5Gui.E5Application import e5App
25 25
26 from .Config import ConfigVarTypeDispStrings 26 from .Config import ConfigVarTypeDispStrings
27 from DebugClients.Python.DebugConfig import ConfigQtNames, ConfigKnownQtTypes 27 from DebugClients.Python.DebugConfig import ConfigQtNames, ConfigKnownQtTypes
28 28
29 import Preferences
29 import Utilities 30 import Utilities
30 31
31 SORT_ROLE = Qt.UserRole 32 SORT_ROLE = Qt.UserRole
32 33
33 34
650 except AttributeError: 651 except AttributeError:
651 return ['None', '', '', ''][column] 652 return ['None', '', '', ''][column]
652 653
653 elif role == Qt.BackgroundRole: 654 elif role == Qt.BackgroundRole:
654 if node in node.parent.changedItems: 655 if node in node.parent.changedItems:
655 color = QColor('#70FF66') 656 return self.__bgColorChanged
656 # Set Alpha chanel to get alternating row colors done by Qt
657 color.setAlpha(40)
658 return QBrush(color)
659 elif node in node.parent.newItems: 657 elif node in node.parent.newItems:
660 color = QColor('#FFEEAA') 658 return self.__bgColorNew
661 # Set Alpha chanel to get alternating row colors done by Qt
662 color.setAlpha(40)
663 return QBrush(color)
664 659
665 elif role == Qt.ToolTipRole: 660 elif role == Qt.ToolTipRole:
666 if column == 0: 661 if column == 0:
667 tooltip = node.name + node.indicator 662 tooltip = node.name + node.indicator
668 elif column == 1: 663 elif column == 1:
829 pathlist.append(parent.nameWithId) 824 pathlist.append(parent.nameWithId)
830 parent = parent.parent 825 parent = parent.parent
831 826
832 pathlist.reverse() 827 pathlist.reverse()
833 return tuple(pathlist) 828 return tuple(pathlist)
829
830 def handlePreferencesChanged(self):
831 """
832 Public slot to handle the preferencesChanged signal.
833 """
834 self.__bgColorNew = QBrush(Preferences.getDebugger("BgColorNew"))
835 self.__bgColorChanged = QBrush(
836 Preferences.getDebugger("BgColorChanged"))
837
838 idxStart = self.index(0, 0, QModelIndex())
839 idxEnd = self.index(0, 2, QModelIndex())
840 self.dataChanged.emit(idxStart, idxEnd)
834 841
835 842
836 class ProxyModel(QSortFilterProxyModel): 843 class ProxyModel(QSortFilterProxyModel):
837 """ 844 """
838 Class for handling the sort operations. 845 Class for handling the sort operations.
887 popup a dialog showing the variables parameters in a more readable 894 popup a dialog showing the variables parameters in a more readable
888 form. This is especially useful for lengthy strings. 895 form. This is especially useful for lengthy strings.
889 896
890 This view has two modes for displaying the global and the local 897 This view has two modes for displaying the global and the local
891 variables. 898 variables.
899
900 @signal preferencesChanged() to inform model about new background colours
892 """ 901 """
902 preferencesChanged = pyqtSignal()
903
893 def __init__(self, viewer, globalScope, parent=None): 904 def __init__(self, viewer, globalScope, parent=None):
894 """ 905 """
895 Constructor 906 Constructor
896 907
897 @param viewer reference to the debug viewer object 908 @param viewer reference to the debug viewer object
913 924
914 # Implements sorting and filtering 925 # Implements sorting and filtering
915 self.proxyModel = ProxyModel() 926 self.proxyModel = ProxyModel()
916 # Variable model implements the underlying data model 927 # Variable model implements the underlying data model
917 self.varModel = VariableModel(self, globalScope) 928 self.varModel = VariableModel(self, globalScope)
929 self.preferencesChanged.connect(self.varModel.handlePreferencesChanged)
930 self.preferencesChanged.emit() # Force initialization of colors
918 self.proxyModel.setSourceModel(self.varModel) 931 self.proxyModel.setSourceModel(self.varModel)
919 self.setModel(self.proxyModel) 932 self.setModel(self.proxyModel)
920 933
921 self.expanded.connect( 934 self.expanded.connect(
922 lambda idx: self.proxyModel.setExpanded(idx, True)) 935 lambda idx: self.proxyModel.setExpanded(idx, True))

eric ide

mercurial