Added Methods to remove and destroy items.

This commit is contained in:
Samik Bhowal 2008-10-08 20:45:12 +00:00
parent 24dea4e56a
commit bbf8d832b0
1 changed files with 41 additions and 0 deletions

View File

@ -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):
"""