Browse Source

Added Methods to remove and destroy items.

Samik Bhowal 17 years ago
parent
commit
bbf8d832b0
1 changed files with 41 additions and 0 deletions
  1. 41 0
      direct/src/gui/DirectScrolledList.py

+ 41 - 0
direct/src/gui/DirectScrolledList.py

@@ -366,6 +366,24 @@ class DirectScrolledList(DirectFrame):
             return 1
             return 1
         else:
         else:
             return 0
             return 0
+        
+    def removeAndDestroyItem(self, item, refresh = 1):
+        """
+        Remove and destroy this item from the panel.
+        """
+        assert self.notify.debugStateCall(self)
+        if item in self["items"]:
+            if hasattr(self, "currentSelected") and self.currentSelected is item:
+                del self.currentSelected
+            if (hasattr(item, 'destroy') and callable(item.destroy)):
+                item.destroy()
+            self["items"].remove(item)
+            if type(item) != type(''):
+                item.reparentTo(hidden)
+            self.refresh()
+            return 1
+        else:
+            return 0
 
 
     def removeAllItems(self, refresh=1):
     def removeAllItems(self, refresh=1):
         """
         """
@@ -392,6 +410,29 @@ class DirectScrolledList(DirectFrame):
             self.refresh()
             self.refresh()
             
             
         return retval
         return retval
+    
+    def removeAndDestroyAllItems(self, refresh = 1):
+        """
+        Remove and destroy all items from the panel.
+        Warning 2006_10_19 tested only in the trolley metagame
+        """
+        assert self.notify.debugStateCall(self)
+        retval = 0
+        while len (self["items"]):
+            item = self['items'][0]
+            if hasattr(self, "currentSelected") and self.currentSelected is item:
+                del self.currentSelected
+            if (hasattr(item, 'destroy') and callable(item.destroy)):
+                item.destroy()
+            self["items"].remove(item)
+            if type(item) != type(''):
+                #RAU possible leak here, let's try to do the right thing 
+                #item.reparentTo(hidden)
+                item.removeNode()
+            retval = 1
+        if (refresh):
+            self.refresh()            
+        return retval
 
 
     def refresh(self):
     def refresh(self):
         """
         """