Repository: spyder-ide/spyder

Issue:
UI issues with collapse/expand in the profiler
In the profiler, in Spyder 3.0.0dev, when root nodes are collapsed, clicking on the button "Expand one level down" expands the nodes correctly, but clicking one more time does not do anything even they are still levels to expand. Moreover,  clicking on "Collapse one level up" does not do anything either.

In Spyder 2.7, the behaviour is different, but also wrong (expands three level down and collapses two levels up). 

UI issues with collapse/expand in the profiler
In the profiler, in Spyder 3.0.0dev, when root nodes are collapsed, clicking on the button "Expand one level down" expands the nodes correctly, but clicking one more time does not do anything even they are still levels to expand. Moreover,  clicking on "Collapse one level up" does not do anything either.

In Spyder 2.7, the behaviour is different, but also wrong (expands three level down and collapses two levels up). 



Discussion:

Resolving patch:
diff --git a/spyderplugins/widgets/profilergui.py b/spyderplugins/widgets/profilergui.py
--- a/spyderplugins/widgets/profilergui.py
+++ b/spyderplugins/widgets/profilergui.py
@@ -100,13 +100,13 @@ def __init__(self, parent, max_entries=100):
 
         self.collapse_button = create_toolbutton(self,
                                                  icon=ima.icon('collapse'),
-                                                 triggered=lambda dD=-1:
-                                                 self.datatree.change_view(dD),
+                                                 triggered=lambda dD:
+                                                 self.datatree.change_view(-1),
                                                  tip=_('Collapse one level up'))
         self.expand_button = create_toolbutton(self,
                                                icon=ima.icon('expand'),
-                                               triggered=lambda dD=1:
-                                               self.datatree.change_view(dD),
+                                               triggered=lambda dD:
+                                               self.datatree.change_view(1),
                                                tip=_('Expand one level down'))
                                 
         self.save_button = create_toolbutton(self, text_beside_icon=True,
@@ -603,7 +603,7 @@ def get_top_level_items(self):
         return [self.topLevelItem(_i) for _i in range(self.topLevelItemCount())]
     
     def get_items(self, maxlevel):
-        """Return items (excluding top level items)"""
+        """Return all items with a level <= `maxlevel`"""
         itemlist = []
         def add_to_itemlist(item, maxlevel, level=1):
             level += 1
@@ -614,19 +614,20 @@ def add_to_itemlist(item, maxlevel, level=1):
                     add_to_itemlist(citem, maxlevel, level)
         for tlitem in self.get_top_level_items():
             itemlist.append(tlitem)
-            if maxlevel > 1:
+            if maxlevel > 0:
                 add_to_itemlist(tlitem, maxlevel=maxlevel)
         return itemlist
             
     def change_view(self, change_in_depth):
         """Change the view depth by expand or collapsing all same-level nodes"""
         self.current_view_depth += change_in_depth
-        if self.current_view_depth < 1:
-            self.current_view_depth = 1
+        if self.current_view_depth < 0:
+            self.current_view_depth = 0
         self.collapseAll()
-        for item in self.get_items(maxlevel=self.current_view_depth):
-            item.setExpanded(True)
-
+        if self.current_view_depth > 0:
+            for item in self.get_items(maxlevel=self.current_view_depth-1):
+                item.setExpanded(True)
+    
 
 #==============================================================================
 # Tests


Test patch: