--- 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