eric6/Debugger/VariablesViewer.py

changeset 7016
47f6b0c3a293
parent 7015
b1a3094b33e1
child 7019
a1b25790bc5c
diff -r b1a3094b33e1 -r 47f6b0c3a293 eric6/Debugger/VariablesViewer.py
--- a/eric6/Debugger/VariablesViewer.py	Sun May 19 12:35:24 2019 +0200
+++ b/eric6/Debugger/VariablesViewer.py	Sun May 19 13:16:30 2019 +0200
@@ -79,18 +79,18 @@
         # Take the additional methods into account for childCount
         self.methodCount = 0
         self.childCount = 0
-        self.currentCount = -1  # -1 indicates to (re)load childs
-        # Indicator that there are childs
-        self.hasChilds = False
+        self.currentCount = -1  # -1 indicates to (re)load children
+        # Indicator that there are children
+        self.hasChildren = False
         # Indicator that item was at least once fully populated
         self.wasPopulated = False
         
-        self.childs = []
+        self.children = []
         # Flag to prevent endless reloading of current item while waiting on
         # a response from debugger
         self.pendigFetch = False
         
-        # Set of childs items, which are displayed the first time or changed
+        # Set of child items, which are displayed the first time or changed
         self.newItems = set()
         self.changedItems = set()
         # Name including its ID if it's a dict, set, etc.
@@ -135,7 +135,8 @@
         """
         Private method to process the type of the variable.
         
-        If type is known to have childs, the corresponding flag is set.
+        If type is known to have children, the corresponding flag is set.
+        
         @param dtype type string
         @type str
         """
@@ -145,23 +146,24 @@
         # Qt related stuff?
         elif (dtype.startswith(ConfigQtNames) and
                 dtype.endswith(ConfigKnownQtTypes)):
-            self.hasChilds = True
+            self.hasChildren = True
             
         elif dtype in ('instance', 'class'):
-            self.hasChilds = True
+            self.hasChildren = True
         
         vtype = ConfigVarTypeDispStrings.get(dtype, dtype)
         # Unkown types should be expandable by default
         if vtype is dtype and dtype not in self.nonExpandableTypes:
-            self.hasChilds = True
+            self.hasChildren = True
         self.type = QCoreApplication.translate("VariablesViewer", vtype)
     
     def __getValue(self, dtype, dvalue):
         """
         Private method to process the variables value.
         
-        Define and limit value, set tooltip text.
-        If type is known to have childs, the corresponding flag is set.
+        Define and limit value, set tooltip text. If type is known to have
+        children, the corresponding flag is set.
+        
         @param dtype type string
         @type str
         @param dvalue value of variable encoded as utf-8
@@ -179,14 +181,14 @@
         if dtype == 'numpy.ndarray':
             self.childCount = int(dvalue.split('x')[0])
             dvalue = VariableItem.noOfItemsStr.format(dvalue)
-            self.hasChilds = True
+            self.hasChildren = True
         elif dtype in VariableItem.arrayTypes:
             self.childCount = int(dvalue)
             dvalue = VariableItem.noOfItemsStr.format(dvalue)
-            self.hasChilds = True
+            self.hasChildren = True
             
         elif dtype == "Shiboken.EnumType":
-            self.hasChilds = True
+            self.hasChildren = True
             
         elif dtype in ['str', 'unicode']:
             if VariableItem.rx_nonprintable.indexIn(dvalue) == -1:
@@ -229,9 +231,9 @@
     @property
     def absolutCount(self):
         """
-        Public property to get the total number of childs.
+        Public property to get the total number of children.
         
-        @return total number of childs
+        @return total number of children
         @rtype int
         """
         return self.childCount + self.methodCount
@@ -247,7 +249,7 @@
         return self.currentCount >= (self.childCount + self.methodCount)
 
 
-class VariableModel(QAbstractItemModel):
+class VariablesModel(QAbstractItemModel):
     """
     Class implementing the data model for QTreeView.
     
@@ -265,7 +267,7 @@
             variables
         @type bool
         """
-        super(VariableModel, self).__init__()
+        super(VariablesModel, self).__init__()
         self.treeView = treeView
         self.proxyModel = treeView.proxyModel
         
@@ -291,7 +293,7 @@
         @type bool
         """
         self.beginResetModel()
-        self.rootNode.childs = []
+        self.rootNode.children = []
         self.rootNode.newItems.clear()
         self.rootNode.changedItems.clear()
         self.rootNode.wasPopulated = False
@@ -312,7 +314,7 @@
         node = self.rootNode
         
         for childName in pathlist or []:
-            for item in node.childs:
+            for item in node.children:
                 if item.nameWithId == childName:
                     node = item
                     break
@@ -356,14 +358,14 @@
             parentIdx = QModelIndex()
             parent.methodCount = len(vlist)
         else:
-            row = parent.parent.childs.index(parent)
+            row = parent.parent.children.index(parent)
             parentIdx = self.createIndex(row, 0, parent)
         
         if itemStartIndex == -3:
             # Item doesn't exist any more
             parentIdx = self.parent(parentIdx)
             self.beginRemoveRows(parentIdx, row, row)
-            del parent.parent.childs[row]
+            del parent.parent.children[row]
             self.endRemoveRows()
             parent.parent.childCount -= 1
             return
@@ -388,11 +390,11 @@
         # Now update the table
         endIndex = idx + len(vlist)
         newChild = None
-        knownChildsCount = len(parent.childs)
+        knownChildrenCount = len(parent.children)
         while idx < endIndex:
             # Fetch next old item from last cycle
             try:
-                child = parent.childs[idx]
+                child = parent.children[idx]
             except IndexError:
                 child = None
             
@@ -407,10 +409,10 @@
             # Append or insert before already existing item
             if child is None or newChild and sort < child.sort:
                 self.beginInsertRows(parentIdx, idx, idx)
-                parent.childs.insert(idx, newItem)
-                if knownChildsCount <= idx and not parent.wasPopulated:
+                parent.children.insert(idx, newItem)
+                if knownChildrenCount <= idx and not parent.wasPopulated:
                     parent.newItems.add(newItem)
-                    knownChildsCount += 1
+                    knownChildrenCount += 1
                 else:
                     parent.changedItems.add(newItem)
                 self.endInsertRows()
@@ -443,10 +445,10 @@
             
             # Remove obsolete item
             self.beginRemoveRows(parentIdx, idx, idx)
-            parent.childs.remove(child)
+            parent.children.remove(child)
             self.endRemoveRows()
             # idx stay unchanged
-            knownChildsCount -= 1
+            knownChildrenCount -= 1
         
         # Remove items which are left over at the end of child list
         if itemStartIndex == -1:
@@ -466,10 +468,10 @@
         @param parentIdx the parent index as QModelIndex
         @type QModelIndex
         """
-        end = len(parent.childs)
+        end = len(parent.children)
         if end > parent.absolutCount:
             self.beginRemoveRows(parentIdx, parent.absolutCount, end)
-            del parent.childs[parent.absolutCount:]
+            del parent.children[parent.absolutCount:]
             self.endRemoveRows()
     
     def resetModifiedMarker(self, parentIdx=QModelIndex(), pathlist=()):
@@ -495,12 +497,12 @@
         posPaths = {x[pll] for x in posPaths if x[:pll] == pathlist}
         
         if posPaths:
-            for child in parent.childs:
-                if child.hasChilds and child.nameWithId in posPaths:
+            for child in parent.children:
+                if child.hasChildren and child.nameWithId in posPaths:
                     if child.currentCount >= 0:
                         # Discard loaded elements and refresh if still expanded
                         child.currentCount = -1
-                        row = parent.childs.index(child)
+                        row = parent.children.index(child)
                         newParentIdx = self.index(row, 0, parentIdx)
                         self.resetModifiedMarker(
                             newParentIdx, pathlist + (child.nameWithId,))
@@ -516,7 +518,7 @@
     
     def columnCount(self, parent=QModelIndex()):
         """
-        Public Qt slot to get the column count.
+        Public method to get the column count.
         
         @param parent the model parent
         @type QModelIndex
@@ -527,7 +529,7 @@
     
     def rowCount(self, parent=QModelIndex()):
         """
-        Public Qt slot to get the row count.
+        Public method to get the row count.
         
         @param parent the model parent
         @type QModelIndex
@@ -539,11 +541,11 @@
         else:
             node = self.rootNode
         
-        return len(node.childs)
+        return len(node.children)
     
     def flags(self, index):
         """
-        Public Qt slot to get the item flags.
+        Public method to get the item flags.
         
         @param index of item
         @type QModelIndex
@@ -557,21 +559,21 @@
     
     def hasChildren(self, parent=QModelIndex()):
         """
-        Public Qt slot to get a flag if parent has childs.
+        Public method to get a flag if parent has children.
         
         @param parent the model parent
         @type QModelIndex
-        @return flag if parent has childs
+        @return flag indicating parent has children
         @rtype bool
         """
         if not parent.isValid():
-            return self.rootNode.childs != []
+            return self.rootNode.children != []
         
-        return parent.internalPointer().hasChilds
+        return parent.internalPointer().hasChildren
     
     def index(self, row, column, parent=QModelIndex()):
         """
-        Public Qt slot to get the index of item at row:column of parent.
+        Public method to get the index of item at row:column of parent.
         
         @param row number of rows
         @type int
@@ -590,11 +592,11 @@
         else:
             node = parent.internalPointer()
         
-        return self.createIndex(row, column, node.childs[row])
+        return self.createIndex(row, column, node.children[row])
     
     def parent(self, child):
         """
-        Public Qt slot to get the parent of the given child.
+        Public method to get the parent of the given child.
         
         @param child the model child node
         @type QModelIndex
@@ -613,12 +615,12 @@
         if parentNode == self.rootNode:
             return QModelIndex()
         
-        row = parentNode.parent.childs.index(parentNode)
+        row = parentNode.parent.children.index(parentNode)
         return self.createIndex(row, 0, parentNode)
     
     def data(self, index, role=Qt.DisplayRole):
         """
-        Public Qt slot get the role data of item.
+        Public method get the role data of item.
         
         @param index the model index
         @type QModelIndex
@@ -697,7 +699,7 @@
     
     def headerData(self, section, orientation, role=Qt.DisplayRole):
         """
-        Public Qt slot get the header names.
+        Public method get the header names.
         
         @param section the header section (row/coulumn)
         @type int
@@ -736,15 +738,15 @@
         if parent is None:
             parent = self.rootNode
         
-        for child in parent.childs:
-            if not child.hasChilds:
+        for child in parent.children:
+            if not child.hasChildren:
                 continue
             
             if pathlist + (child.nameWithId,) in self.openItems:
                 if child.populated:
                     index = None
                 else:
-                    idx = parent.childs.index(child)
+                    idx = parent.children.index(child)
                     index = self.createIndex(idx, 0, child)
                     self.expand.emit(index)
                 
@@ -840,7 +842,7 @@
         self.dataChanged.emit(idxStart, idxEnd)
 
 
-class ProxyModel(QSortFilterProxyModel):
+class VariablesProxyModel(QSortFilterProxyModel):
     """
     Class for handling the sort operations.
     """
@@ -851,25 +853,26 @@
         @param parent the parent model index
         @type QModelIndex
         """
-        super(ProxyModel, self).__init__(parent)
+        super(VariablesProxyModel, self).__init__(parent)
         self.setSortRole(SORT_ROLE)
     
     def hasChildren(self, parent):
         """
-        Public Qt slot to get a flag if parent has childs.
+        Public method to get a flag if parent has children.
         
         The given model index has to be transformed to the underlying source
         model to get the correct result.
+        
         @param parent the model parent
         @type QModelIndex
-        @return flag if parent has childs
+        @return flag if parent has children
         @rtype bool
         """
         return self.sourceModel().hasChildren(self.mapToSource(parent))
     
     def setExpanded(self, index, state):
         """
-        Public Qt slot to get a flag if parent has childs.
+        Public slot to get a flag if parent has children.
         
         The given model index has to be transformed to the underlying source
         model to get the correct result.
@@ -889,7 +892,7 @@
     debugged in a tree. Compound types will be shown with
     their main entry first. Once the subtree has been expanded, the
     individual entries will be shown. Double clicking an entry will
-    expand or collapse the item, if it has childs and the double click
+    expand or collapse the item, if it has children and the double click
     was performed on the first column of the tree, otherwise it'll
     popup a dialog showing the variables parameters in a more readable
     form. This is especially useful for lengthy strings.
@@ -923,9 +926,9 @@
         self.setUniformRowHeights(True)
         
         # Implements sorting and filtering
-        self.proxyModel = ProxyModel()
+        self.proxyModel = VariablesProxyModel()
         # Variable model implements the underlying data model
-        self.varModel = VariableModel(self, globalScope)
+        self.varModel = VariablesModel(self, globalScope)
         self.preferencesChanged.connect(self.varModel.handlePreferencesChanged)
         self.preferencesChanged.emit()  # Force initialization of colors
         self.proxyModel.setSourceModel(self.varModel)
@@ -986,7 +989,7 @@
         Public method to show variables in a list.
         
         @param vlist the list of variables to be displayed. Each
-                listentry is a tuple of three values.
+                list entry is a tuple of three values.
                 <ul>
                 <li>the variable name (string)</li>
                 <li>the variables type (string)</li>
@@ -1005,7 +1008,7 @@
         
         @param vlist the list of subitems to be displayed.
                 The first element gives the path of the
-                parent variable. Each other listentry is
+                parent variable. Each other list entry is
                 a tuple of three values.
                 <ul>
                 <li>the variable name (string)</li>
@@ -1024,7 +1027,7 @@
     
     def verticalScrollbarValueChanged(self, value):
         """
-        Public Qt slot informing about the scrollbar change.
+        Public slot informing about the scrollbar change.
         
         @param value current value of the vertical scrollbar
         @type int
@@ -1034,7 +1037,7 @@
     
     def resizeEvent(self, event):
         """
-        Protected Qt slot informing about the widget size change.
+        Protected slot informing about the widget size change.
         
         @param event information
         @type QResizeEvent
@@ -1050,7 +1053,7 @@
         @type QModelIndex
         """
         node = self.proxyModel.mapToSource(index).internalPointer()
-        if node.hasChilds and index.column() == 0:
+        if node.hasChildren and index.column() == 0:
             state = self.isExpanded(index)
             self.setExpanded(index, not state)
         else:
@@ -1073,24 +1076,22 @@
         self.menu = QMenu()
         self.menu.addAction(self.tr("Show Details..."), self.__showDetails)
         self.menu.addSeparator()
-        self.menu.addAction(self.tr("Expand childs"), self.__expandChilds)
-        self.menu.addAction(self.tr("Collapse childs"), self.__collapseChilds)
-        self.menu.addAction(self.tr("Collapse all"), self.collapseAll)
+        self.menu.addAction(self.tr("Expand"), self.__expandChildren)
+        self.menu.addAction(self.tr("Collapse"), self.__collapseChildren)
+        self.menu.addAction(self.tr("Collapse All"), self.collapseAll)
         self.menu.addSeparator()
         self.menu.addAction(self.tr("Refresh"), self.__refreshView)
         self.menu.addSeparator()
         self.menu.addAction(self.tr("Configure..."), self.__configure)
-        self.menu.addAction(
-            QCoreApplication.translate('DebugUI', 'Varia&bles Type Filter...'),
-            self.__configureFilter)
+        self.menu.addAction(self.tr("Variables Type Filter..."),
+                            self.__configureFilter)
         
         self.backMenu = QMenu()
         self.backMenu.addAction(self.tr("Refresh"), self.__refreshView)
         self.backMenu.addSeparator()
         self.backMenu.addAction(self.tr("Configure..."), self.__configure)
-        self.backMenu.addAction(
-            QCoreApplication.translate('DebugUI', 'Varia&bles Type Filter...'),
-            self.__configureFilter)
+        self.backMenu.addAction(self.tr("Variables Type Filter..."),
+                                self.__configureFilter)
     
     def __showContextMenu(self, coord):
         """
@@ -1105,27 +1106,27 @@
         else:
             self.backMenu.popup(gcoord)
     
-    def __expandChilds(self):
+    def __expandChildren(self):
         """
-        Private slot to expand all childs of current parent.
+        Private slot to expand all child items of current parent.
         """
         index = self.currentIndex()
         node = self.proxyModel.mapToSource(index).internalPointer()
-        for child in node.childs:
-            if child.hasChilds:
-                row = node.childs.index(child)
+        for child in node.children:
+            if child.hasChildren:
+                row = node.children.index(child)
                 idx = self.varModel.createIndex(row, 0, child)
                 idx = self.proxyModel.mapFromSource(idx)
                 self.expand(idx)
     
-    def __collapseChilds(self):
+    def __collapseChildren(self):
         """
-        Private slot to collapse all childs of current parent.
+        Private slot to collapse all child items of current parent.
         """
         index = self.currentIndex()
         node = self.proxyModel.mapToSource(index).internalPointer()
-        for child in node.childs:
-            row = node.childs.index(child)
+        for child in node.children:
+            row = node.children.index(child)
             idx = self.varModel.createIndex(row, 0, child)
             idx = self.proxyModel.mapFromSource(idx)
             if self.isExpanded(idx):

eric ide

mercurial