From bbf8d832b0bfc9aa460bb9ce8560ec39681067ff Mon Sep 17 00:00:00 2001 From: Samik Bhowal Date: Wed, 8 Oct 2008 20:45:12 +0000 Subject: [PATCH] Added Methods to remove and destroy items. --- direct/src/gui/DirectScrolledList.py | 41 ++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/direct/src/gui/DirectScrolledList.py b/direct/src/gui/DirectScrolledList.py index 69ff74b6e6..a40b0040e1 100644 --- a/direct/src/gui/DirectScrolledList.py +++ b/direct/src/gui/DirectScrolledList.py @@ -366,6 +366,24 @@ class DirectScrolledList(DirectFrame): return 1 else: 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): """ @@ -392,6 +410,29 @@ class DirectScrolledList(DirectFrame): self.refresh() 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): """