mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-01 01:07:51 -04:00
fix scrollist crash for non-class lists
This commit is contained in:
parent
ff208ad0b8
commit
a0c06b4554
@ -1,6 +1,7 @@
|
|||||||
from DirectFrame import *
|
from DirectFrame import *
|
||||||
from DirectButton import *
|
from DirectButton import *
|
||||||
import Task
|
import Task
|
||||||
|
import types
|
||||||
|
|
||||||
class DirectScrolledList(DirectFrame):
|
class DirectScrolledList(DirectFrame):
|
||||||
def __init__(self, parent = aspect2d, **kw):
|
def __init__(self, parent = aspect2d, **kw):
|
||||||
@ -104,6 +105,13 @@ class DirectScrolledList(DirectFrame):
|
|||||||
#for i in range(len(self["items"])):
|
#for i in range(len(self["items"])):
|
||||||
# print "buttontext[",i,"]",self["items"][i]["text"]
|
# print "buttontext[",i,"]",self["items"][i]["text"]
|
||||||
|
|
||||||
|
if(len(self["items"])==0):
|
||||||
|
return
|
||||||
|
|
||||||
|
if(type(self["items"][0])!=types.InstanceType):
|
||||||
|
print "warning: getItemIndexForItemID: cant find itemID for non-class list items!"
|
||||||
|
return
|
||||||
|
|
||||||
for i in range(len(self["items"])):
|
for i in range(len(self["items"])):
|
||||||
if(self["items"][i].itemID == itemID):
|
if(self["items"][i].itemID == itemID):
|
||||||
return i
|
return i
|
||||||
@ -218,14 +226,18 @@ class DirectScrolledList(DirectFrame):
|
|||||||
"""
|
"""
|
||||||
Add this string and extraArg to the list
|
Add this string and extraArg to the list
|
||||||
"""
|
"""
|
||||||
item.itemID = self.nextItemID
|
if(type(item) == types.InstanceType):
|
||||||
self.nextItemID += 1
|
# cant add attribs to non-classes (like strings & ints)
|
||||||
|
item.itemID = self.nextItemID
|
||||||
|
self.nextItemID += 1
|
||||||
self['items'].append(item)
|
self['items'].append(item)
|
||||||
if type(item) != type(''):
|
if type(item) != type(''):
|
||||||
item.reparentTo(self.itemFrame)
|
item.reparentTo(self.itemFrame)
|
||||||
if refresh:
|
if refresh:
|
||||||
self.refresh()
|
self.refresh()
|
||||||
return item.itemID # to pass to scrollToItemID
|
if(type(item) == types.InstanceType):
|
||||||
|
return item.itemID # to pass to scrollToItemID
|
||||||
|
return
|
||||||
|
|
||||||
def removeItem(self, item, refresh=1):
|
def removeItem(self, item, refresh=1):
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user