Mon, 13 May 2019 22:29:15 +0200
Colors for highlighting are configurable through Debugger->General
--- a/docs/changelog Fri May 03 23:01:00 2019 +0200 +++ b/docs/changelog Mon May 13 22:29:15 2019 +0200 @@ -6,6 +6,7 @@ big arrays, dicts, etc. because elements are lazy loaded -- highlighting of till unloaded (yellow background) and last changed variable(s) (green background) + -- colors for highlighting are configurable through Debugger->General -- expand / collapse variables with childs on double click on first column, in all other cases display detail window -- handling of dict views improved. They could be expanded like lists
--- a/eric6/Debugger/DebugViewer.py Fri May 03 23:01:00 2019 +0200 +++ b/eric6/Debugger/DebugViewer.py Mon May 13 22:29:15 2019 +0200 @@ -45,8 +45,10 @@ the exception logger. Additionally a list of all threads is shown. @signal sourceFile(string, int) emitted to open a source file at a line + @signal preferencesChanged() emitted to react on changed preferences """ sourceFile = pyqtSignal(str, int) + preferencesChanged = pyqtSignal() def __init__(self, debugServer, docked, vm, parent=None): """ @@ -168,6 +170,10 @@ self.setLocalsFilterButton.clicked.connect(self.setLocalsFilter) self.localsFilterEdit.returnPressed.connect(self.setLocalsFilter) + self.preferencesChanged.connect(self.handlePreferencesChanged) + self.preferencesChanged.connect(self.globalsViewer.preferencesChanged) + self.preferencesChanged.connect(self.localsViewer.preferencesChanged) + from .CallStackViewer import CallStackViewer # add the call stack viewer self.callStackViewer = CallStackViewer(self.debugServer) @@ -246,7 +252,7 @@ self.__autoViewSource = Preferences.getDebugger("AutoViewSourceCode") self.sourceButton.setVisible(not self.__autoViewSource) - def preferencesChanged(self): + def handlePreferencesChanged(self): """ Public slot to handle the preferencesChanged signal. """
--- a/eric6/Debugger/VariablesViewer.py Fri May 03 23:01:00 2019 +0200 +++ b/eric6/Debugger/VariablesViewer.py Mon May 13 22:29:15 2019 +0200 @@ -18,7 +18,7 @@ from PyQt5.QtCore import (Qt, QAbstractItemModel, QModelIndex, QRegExp, QCoreApplication, QSortFilterProxyModel, pyqtSignal) -from PyQt5.QtGui import QBrush, QColor, QFontMetrics +from PyQt5.QtGui import QBrush, QFontMetrics from PyQt5.QtWidgets import QTreeView, QAbstractItemView, QToolTip, QMenu from E5Gui.E5Application import e5App @@ -26,6 +26,7 @@ from .Config import ConfigVarTypeDispStrings from DebugClients.Python.DebugConfig import ConfigQtNames, ConfigKnownQtTypes +import Preferences import Utilities SORT_ROLE = Qt.UserRole @@ -652,15 +653,9 @@ elif role == Qt.BackgroundRole: if node in node.parent.changedItems: - color = QColor('#70FF66') - # Set Alpha chanel to get alternating row colors done by Qt - color.setAlpha(40) - return QBrush(color) + return self.__bgColorChanged elif node in node.parent.newItems: - color = QColor('#FFEEAA') - # Set Alpha chanel to get alternating row colors done by Qt - color.setAlpha(40) - return QBrush(color) + return self.__bgColorNew elif role == Qt.ToolTipRole: if column == 0: @@ -831,6 +826,18 @@ pathlist.reverse() return tuple(pathlist) + + def handlePreferencesChanged(self): + """ + Public slot to handle the preferencesChanged signal. + """ + self.__bgColorNew = QBrush(Preferences.getDebugger("BgColorNew")) + self.__bgColorChanged = QBrush( + Preferences.getDebugger("BgColorChanged")) + + idxStart = self.index(0, 0, QModelIndex()) + idxEnd = self.index(0, 2, QModelIndex()) + self.dataChanged.emit(idxStart, idxEnd) class ProxyModel(QSortFilterProxyModel): @@ -889,7 +896,11 @@ This view has two modes for displaying the global and the local variables. + + @signal preferencesChanged() to inform model about new background colours """ + preferencesChanged = pyqtSignal() + def __init__(self, viewer, globalScope, parent=None): """ Constructor @@ -915,6 +926,8 @@ self.proxyModel = ProxyModel() # Variable model implements the underlying data model self.varModel = VariableModel(self, globalScope) + self.preferencesChanged.connect(self.varModel.handlePreferencesChanged) + self.preferencesChanged.emit() # Force initialization of colors self.proxyModel.setSourceModel(self.varModel) self.setModel(self.proxyModel)
--- a/eric6/Preferences/ConfigurationPages/ConfigurationPageBase.py Fri May 03 23:01:00 2019 +0200 +++ b/eric6/Preferences/ConfigurationPages/ConfigurationPageBase.py Mon May 13 22:29:15 2019 +0200 @@ -9,7 +9,7 @@ from __future__ import unicode_literals -from PyQt5.QtCore import pyqtSlot +from PyQt5.QtCore import pyqtSlot, pyqtSignal from PyQt5.QtGui import QIcon, QPixmap, QColor from PyQt5.QtWidgets import QWidget, QColorDialog, QFontDialog @@ -17,7 +17,11 @@ class ConfigurationPageBase(QWidget): """ Class implementing the base class for all configuration pages. + + @signal colourChanged(str, QColor) To inform about a new colour selection """ + colourChanged = pyqtSignal(str, QColor) + def __init__(self): """ Constructor @@ -68,6 +72,7 @@ button.setProperty("hasAlpha", hasAlpha) button.clicked.connect(lambda: self.__selectColourSlot(button)) self.__coloursDict[colourKey] = [colour, byName] + self.colourChanged.emit(colourKey, colour) @pyqtSlot() def __selectColourSlot(self, button): @@ -80,20 +85,26 @@ colorKey = button.property("colorKey") hasAlpha = button.property("hasAlpha") + colDlg = QColorDialog(self) if hasAlpha: - colour = QColorDialog.getColor( - self.__coloursDict[colorKey][0], self, "", - QColorDialog.ShowAlphaChannel) - else: - colour = QColorDialog.getColor(self.__coloursDict[colorKey][0], - self) - if colour.isValid(): + colDlg.setOptions(QColorDialog.ShowAlphaChannel) + # Set current colour last to avoid conflicts with alpha channel + colDlg.setCurrentColor(self.__coloursDict[colorKey][0]) + colDlg.currentColorChanged.connect( + lambda col: self.colourChanged.emit(colorKey, col)) + colDlg.exec_() + + if colDlg.result() == colDlg.Accepted: + colour = colDlg.selectedColor() size = button.iconSize() pm = QPixmap(size.width(), size.height()) pm.fill(colour) button.setIcon(QIcon(pm)) self.__coloursDict[colorKey][0] = colour + # Update colour selection + self.colourChanged.emit(colorKey, self.__coloursDict[colorKey][0]) + def saveColours(self, prefMethod): """ Public method to save the colour selections. @@ -129,4 +140,4 @@ "{0} {1}".format(font.family(), font.pointSize())) else: font = fontVar - return font + return font # __IGNORE_WARNING_M834__
--- a/eric6/Preferences/ConfigurationPages/DebuggerGeneralPage.py Fri May 03 23:01:00 2019 +0200 +++ b/eric6/Preferences/ConfigurationPages/DebuggerGeneralPage.py Mon May 13 22:29:15 2019 +0200 @@ -11,7 +11,8 @@ import socket -from PyQt5.QtCore import QRegExp, pyqtSlot +from PyQt5.QtCore import Qt, QAbstractItemModel, QModelIndex, QRegExp, pyqtSlot +from PyQt5.QtGui import QBrush, QColor from PyQt5.QtWidgets import QLineEdit, QInputDialog from PyQt5.QtNetwork import QNetworkInterface, QAbstractSocket, QHostAddress @@ -143,11 +144,20 @@ Preferences.getDebugger("BreakAlways")) self.exceptionShellCheckBox.setChecked( Preferences.getDebugger("ShowExceptionInShell")) + self.maxSizeSpinBox.setValue( + Preferences.getDebugger("MaxVariableSize")) + # Set the colours for debug viewer backgrounds + self.previewMdl = PreviewModel() + self.preView.setModel(self.previewMdl) + self.colourChanged.connect(self.previewMdl.setColor) + self.initColour("BgColorNew", self.backgroundNewButton, + Preferences.getDebugger, hasAlpha=True) + self.initColour("BgColorChanged", self.backgroundChangedButton, + Preferences.getDebugger, hasAlpha=True) + self.autoViewSourcecodeCheckBox.setChecked( Preferences.getDebugger("AutoViewSourceCode")) - self.maxSizeSpinBox.setValue( - Preferences.getDebugger("MaxVariableSize")) - + def save(self): """ Public slot to save the Debugger General (1) configuration. @@ -232,11 +242,14 @@ "ShowExceptionInShell", self.exceptionShellCheckBox.isChecked()) Preferences.setDebugger( + "MaxVariableSize", + self.maxSizeSpinBox.value()) + # Store background colors for debug viewer + self.saveColours(Preferences.setDebugger) + + Preferences.setDebugger( "AutoViewSourceCode", self.autoViewSourcecodeCheckBox.isChecked()) - Preferences.setDebugger( - "MaxVariableSize", - self.maxSizeSpinBox.value()) def on_allowedHostsList_currentItemChanged(self, current, previous): """ @@ -304,7 +317,123 @@ """ a valid IP v4 or IP v6 address.""" """ Aborting...</p>""") .format(allowedHost)) + + +class PreviewModel(QAbstractItemModel): + """ + Class to show an example of the selected background colours for the debug + viewer. + """ + def __init__(self): + """ + Constructor + """ + super(PreviewModel, self).__init__() + self.bgColorNew = QBrush(QColor('#FFFFFF')) + self.bgColorChanged = QBrush(QColor('#FFFFFF')) + def setColor(self, key, bgcolour): + """ + Public slot to update the background colour indexed by key. + + @param key the name of background + @type str + @param bgcolour the new background colour + @type QColor + """ + if key == 'BgColorNew': + self.bgColorNew = QBrush(bgcolour) + else: + self.bgColorChanged = QBrush(bgcolour) + + # Force update of preview view + idxStart = self.index(0, 0, QModelIndex()) + idxEnd = self.index(0, 2, QModelIndex()) + self.dataChanged.emit(idxStart, idxEnd) + + def index(self, row, column, parent=QModelIndex()): + """ + Public Qt slot to get the index of item at row:column of parent. + + @param row number of rows + @rtype int + @param column number of columns + @type int + @param parent the model parent + @type QModelIndex + @return new model index for child + @rtype QModelIndex + """ + if not self.hasIndex(row, column, parent): + return QModelIndex() + + return self.createIndex(row, column, None) + + def parent(self, child): + """ + Public Qt slot to get the parent of the given child. + + @param child the model child node + @type QModelIndex + @return new model index for parent + @rtype QModelIndex + """ + return QModelIndex() + + def columnCount(self, parent=QModelIndex()): + """ + Public Qt slot to get the column count. + + @param parent the model parent + @type QModelIndex + @return number of columns + @rtype int + """ + return 1 + + def rowCount(self, parent=QModelIndex()): + """ + Public Qt slot to get the row count. + + @param parent the model parent + @type QModelIndex + @return number of rows + @rtype int + """ + return 4 + + def flags(self, index): + """ + Public Qt slot to get the item flags. + + @param index of item + @type QModelIndex + @return item flags + @rtype QtCore.Qt.ItemFlag + """ + return Qt.ItemIsEnabled | Qt.ItemIsSelectable + + def data(self, index, role=Qt.DisplayRole): + """ + Public Qt slot get the role data of item. + + @param index the model index + @type QModelIndex + @param role the requested data role + @type QtCore.Qt.ItemDataRole + @return role data of item + @rtype str, QBrush or None + """ + if role == Qt.DisplayRole: + return self.tr('Variable name') + elif role == Qt.BackgroundRole: + if index.row() >= 2: + return self.bgColorChanged + else: + return self.bgColorNew + + return None + def create(dlg): """ @@ -313,5 +442,7 @@ @param dlg reference to the configuration dialog @return reference to the instantiated page (ConfigurationPageBase) """ - page = DebuggerGeneralPage() - return page + return DebuggerGeneralPage() + +# +# eflag: noqa = M822
--- a/eric6/Preferences/ConfigurationPages/DebuggerGeneralPage.ui Fri May 03 23:01:00 2019 +0200 +++ b/eric6/Preferences/ConfigurationPages/DebuggerGeneralPage.ui Mon May 13 22:29:15 2019 +0200 @@ -572,6 +572,9 @@ <string>Variables Viewer</string> </property> <layout class="QVBoxLayout" name="verticalLayout_6"> + <property name="spacing"> + <number>9</number> + </property> <item> <layout class="QHBoxLayout" name="horizontalLayout"> <item> @@ -622,6 +625,124 @@ </layout> </item> <item> + <widget class="QGroupBox" name="groupBox_2"> + <property name="title"> + <string>Background Colours</string> + </property> + <layout class="QHBoxLayout" name="horizontalLayout_3" stretch="2,1"> + <item> + <layout class="QGridLayout" name="gridLayout_3"> + <property name="topMargin"> + <number>8</number> + </property> + <property name="bottomMargin"> + <number>8</number> + </property> + <property name="verticalSpacing"> + <number>16</number> + </property> + <item row="1" column="1"> + <widget class="QPushButton" name="backgroundChangedButton"> + <property name="minimumSize"> + <size> + <width>100</width> + <height>0</height> + </size> + </property> + <property name="maximumSize"> + <size> + <width>100</width> + <height>16777215</height> + </size> + </property> + <property name="toolTip"> + <string>Select the background colour for changed items.</string> + </property> + <property name="text"> + <string/> + </property> + </widget> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="label_bgChangedItems"> + <property name="text"> + <string>Background colour of changed elements:</string> + </property> + </widget> + </item> + <item row="0" column="0"> + <widget class="QLabel" name="label_bgFirstLoaded"> + <property name="text"> + <string>Background colour of first opened elements:</string> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QPushButton" name="backgroundNewButton"> + <property name="minimumSize"> + <size> + <width>100</width> + <height>0</height> + </size> + </property> + <property name="maximumSize"> + <size> + <width>100</width> + <height>16777215</height> + </size> + </property> + <property name="toolTip"> + <string>Select the background colour for elements which are loaded for the first time.</string> + </property> + <property name="text"> + <string/> + </property> + </widget> + </item> + <item row="0" column="2"> + <spacer name="horizontalSpacer_4"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> + <item> + <widget class="QListView" name="preView"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Expanding" vsizetype="Ignored"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="focusPolicy"> + <enum>Qt::NoFocus</enum> + </property> + <property name="verticalScrollBarPolicy"> + <enum>Qt::ScrollBarAlwaysOff</enum> + </property> + <property name="horizontalScrollBarPolicy"> + <enum>Qt::ScrollBarAlwaysOff</enum> + </property> + <property name="editTriggers"> + <set>QAbstractItemView::NoEditTriggers</set> + </property> + <property name="alternatingRowColors"> + <bool>true</bool> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item> <widget class="QGroupBox" name="groupBox_10"> <property name="title"> <string>Local Variables Viewer</string> @@ -688,6 +809,8 @@ <tabstop>exceptionBreakCheckBox</tabstop> <tabstop>exceptionShellCheckBox</tabstop> <tabstop>maxSizeSpinBox</tabstop> + <tabstop>backgroundNewButton</tabstop> + <tabstop>backgroundChangedButton</tabstop> <tabstop>autoViewSourcecodeCheckBox</tabstop> </tabstops> <resources/>
--- a/eric6/Preferences/__init__.py Fri May 03 23:01:00 2019 +0200 +++ b/eric6/Preferences/__init__.py Mon May 13 22:29:15 2019 +0200 @@ -116,6 +116,8 @@ "NetworkInterface": "127.0.0.1", "AutoViewSourceCode": False, "MaxVariableSize": 0, # Bytes, 0 = no limit + "BgColorNew": QColor("#28FFEEAA"), + "BgColorChanged": QColor("#2870FF66"), } debuggerDefaults["AllowedHosts"] = ["127.0.0.1", "::1%0"] if sys.version_info[0] == 2: