Make dictionary views expandable. Variables Viewer

Thu, 02 May 2019 22:58:33 +0200

author
T.Rzepka <Tobias.Rzepka@gmail.com>
date
Thu, 02 May 2019 22:58:33 +0200
branch
Variables Viewer
changeset 6988
87ad87ef1910
parent 6982
419c20ec6cd3
child 6993
d375f251496a

Make dictionary views expandable.

docs/changelog file | annotate | diff | comparison | revisions
eric6/DebugClients/Python/DebugClientBase.py file | annotate | diff | comparison | revisions
eric6/DebugClients/Python/DebugVariables.py file | annotate | diff | comparison | revisions
eric6/Debugger/VariablesViewer.py file | annotate | diff | comparison | revisions
--- a/docs/changelog	Sun Apr 28 11:14:43 2019 +0200
+++ b/docs/changelog	Thu May 02 22:58:33 2019 +0200
@@ -7,6 +7,7 @@
   -- highlighting of last changed variable(s)
   -- 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
   -- show tooltips on all elements which doesn't fit into current column width
   -- new options in the context menu, e.g. expand / collapse all child nodes
   -- bug fixes, e.g. sort order of mixed list elements, unicode handling, ...
--- a/eric6/DebugClients/Python/DebugClientBase.py	Sun Apr 28 11:14:43 2019 +0200
+++ b/eric6/DebugClients/Python/DebugClientBase.py	Thu May 02 22:58:33 2019 +0200
@@ -181,6 +181,10 @@
     
     # keep these in sync with VariablesViewer.VariableItem.Indicators
     Indicators = ("()", "[]", "{:}", "{}")      # __IGNORE_WARNING_M613__
+    arrayTypes = {
+        'list', 'tuple', 'dict', 'set', 'frozenset', "class 'dict_items'",
+        "class 'dict_keys'", "class 'dict_values'"
+    }
     
     def __init__(self):
         """
@@ -1826,8 +1830,7 @@
                         valtype = valtypestr
                 
                 try:
-                    if valtype in ['list', 'tuple', 'dict', 'set', 'frozenset'
-                                   ]:
+                    if valtype in self.arrayTypes:
                         rvalue = "{0:d}".format(len(value))
                     elif valtype == 'array.array':
                         rvalue = "{0:d}|{1}".format(
--- a/eric6/DebugClients/Python/DebugVariables.py	Sun Apr 28 11:14:43 2019 +0200
+++ b/eric6/DebugClients/Python/DebugVariables.py	Thu May 02 22:58:33 2019 +0200
@@ -247,6 +247,40 @@
     
 
 ############################################################
+## Resolver for dict_items, dict_keys and dict_values
+############################################################
+
+
+class DictViewResolver(ListResolver):
+    """
+    Class used to resolve from dict views.
+    """
+    def resolve(self, var, attribute):
+        """
+        Public method to get an attribute from a variable.
+        
+        @param var variable to extract an attribute or value from
+        @type tuple or list
+        @param attribute id of the value to extract
+        @type str
+        @return value of the attribute
+        @rtype any
+        """
+        return super(DictViewResolver, self).resolve(list(var), attribute)
+    
+    def getDictionary(self, var):
+        """
+        Public method to get the attributes of a variable as a dictionary.
+        
+        @param var variable to be converted
+        @type any
+        @return dictionary containing the variable attributes
+        @rtype dict
+        """
+        return super(DictViewResolver, self).getDictionary(list(var))
+
+
+############################################################
 ## Resolver for Sets and Frozensets
 ############################################################
 
@@ -580,6 +614,7 @@
 defaultResolver = DefaultResolver()
 dictResolver = DictResolver()
 listResolver = ListResolver()
+dictViewResolver = DictViewResolver()
 setResolver = SetResolver()
 ndarrayResolver = NdArrayResolver()
 multiValueDictResolver = MultiValueDictResolver()
@@ -615,12 +650,12 @@
     try:
         _TypeMap.append((long, None))           # __IGNORE_WARNING__
     except Exception:
-        pass    # not available on all python versions
+        pass    # not available on all Python versions
 
     try:
         _TypeMap.append((unicode, None))        # __IGNORE_WARNING__
     except Exception:
-        pass    # not available on all python versions
+        pass    # not available on all Python versions
 
     try:
         import array
@@ -640,6 +675,14 @@
         _TypeMap.insert(0, (MultiValueDict, multiValueDictResolver))
     except ImportError:
         pass  # django may not be installed
+    
+    try:
+        from collections.abc import ItemsView, KeysView, ValuesView
+        _TypeMap.append((ItemsView, dictViewResolver))
+        _TypeMap.append((KeysView, dictViewResolver))
+        _TypeMap.append((ValuesView, dictViewResolver))
+    except ImportError:
+        pass  # not available on all Python versions
 
 
 def getType(obj):
--- a/eric6/Debugger/VariablesViewer.py	Sun Apr 28 11:14:43 2019 +0200
+++ b/eric6/Debugger/VariablesViewer.py	Thu May 02 22:58:33 2019 +0200
@@ -52,7 +52,8 @@
     
     arrayTypes = {'list', 'tuple', 'dict', 'set', 'frozenset',
                   'numpy.ndarray', 'django.MultiValueDict', 'array.array',
-                  'collections.defaultdict'}
+                  'collections.defaultdict', "class 'dict_items'",
+                  "class 'dict_keys'", "class 'dict_values'"}
     
     def __init__(self, parent, dvar, dtype, dvalue):
         """

eric ide

mercurial