Fixes to DirectScrolledList; remove unnecessary inheritance

This commit is contained in:
rdb 2016-04-09 19:21:49 +02:00
parent 7e04042ca4
commit 12af395012
2 changed files with 25 additions and 27 deletions

View File

@ -8,7 +8,6 @@ from direct.directnotify import DirectNotifyGlobal
from direct.task.Task import Task from direct.task.Task import Task
from .DirectFrame import * from .DirectFrame import *
from .DirectButton import * from .DirectButton import *
import types
class DirectScrolledListItem(DirectButton): class DirectScrolledListItem(DirectButton):
@ -49,7 +48,7 @@ class DirectScrolledList(DirectFrame):
def __init__(self, parent = None, **kw): def __init__(self, parent = None, **kw):
assert self.notify.debugStateCall(self) assert self.notify.debugStateCall(self)
self.index = 0 self.index = 0
self.forceHeight = None self.__forceHeight = None
""" If one were to want a scrolledList that makes and adds its items """ If one were to want a scrolledList that makes and adds its items
as needed, simply pass in an items list of strings (type 'str') as needed, simply pass in an items list of strings (type 'str')
@ -115,12 +114,12 @@ class DirectScrolledList(DirectFrame):
def setForceHeight(self): def setForceHeight(self):
assert self.notify.debugStateCall(self) assert self.notify.debugStateCall(self)
self.forceHeight = self["forceHeight"] self.__forceHeight = self["forceHeight"]
def recordMaxHeight(self): def recordMaxHeight(self):
assert self.notify.debugStateCall(self) assert self.notify.debugStateCall(self)
if self.forceHeight is not None: if self.__forceHeight is not None:
self.maxHeight = self.forceHeight self.maxHeight = self.__forceHeight
else: else:
self.maxHeight = 0.0 self.maxHeight = 0.0
for item in self["items"]: for item in self["items"]:
@ -130,24 +129,24 @@ class DirectScrolledList(DirectFrame):
def setScrollSpeed(self): def setScrollSpeed(self):
assert self.notify.debugStateCall(self) assert self.notify.debugStateCall(self)
# Items per second to move # Items per second to move
self.scrollSpeed = self["scrollSpeed"] self.__scrollSpeed = self["scrollSpeed"]
if self.scrollSpeed <= 0: if self.__scrollSpeed <= 0:
self.scrollSpeed = 1 self.__scrollSpeed = 1
def setNumItemsVisible(self): def setNumItemsVisible(self):
assert self.notify.debugStateCall(self) assert self.notify.debugStateCall(self)
# Items per second to move # Items per second to move
self.numItemsVisible = self["numItemsVisible"] self.__numItemsVisible = self["numItemsVisible"]
def destroy(self): def destroy(self):
assert self.notify.debugStateCall(self) assert self.notify.debugStateCall(self)
taskMgr.remove(self.taskName("scroll")) taskMgr.remove(self.taskName("scroll"))
if hasattr(self, "currentSelected"): if hasattr(self, "currentSelected"):
del self.currentSelected del self.currentSelected
if self.incButtonCallback: if self.__incButtonCallback:
self.incButtonCallback = None self.__incButtonCallback = None
if self.decButtonCallback: if self.__decButtonCallback:
self.decButtonCallback = None self.__decButtonCallback = None
self.incButton.destroy() self.incButton.destroy()
self.decButton.destroy() self.decButton.destroy()
DirectFrame.destroy(self) DirectFrame.destroy(self)
@ -169,10 +168,10 @@ 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): if len(self["items"]) == 0:
return 0 return 0
if(type(self["items"][0])!=types.InstanceType): if type(self["items"][0]) == type(''):
self.notify.warning("getItemIndexForItemID: cant find itemID for non-class list items!") self.notify.warning("getItemIndexForItemID: cant find itemID for non-class list items!")
return 0 return 0
@ -309,7 +308,7 @@ class DirectScrolledList(DirectFrame):
def __incButtonDown(self, event): def __incButtonDown(self, event):
assert self.notify.debugStateCall(self) assert self.notify.debugStateCall(self)
task = Task(self.__scrollByTask) task = Task(self.__scrollByTask)
task.setDelay(1.0 / self.scrollSpeed) task.setDelay(1.0 / self.__scrollSpeed)
task.prevTime = 0.0 task.prevTime = 0.0
task.delta = 1 task.delta = 1
taskName = self.taskName("scroll") taskName = self.taskName("scroll")
@ -317,13 +316,13 @@ class DirectScrolledList(DirectFrame):
taskMgr.add(task, taskName) taskMgr.add(task, taskName)
self.scrollBy(task.delta) self.scrollBy(task.delta)
messenger.send('wakeup') messenger.send('wakeup')
if self.incButtonCallback: if self.__incButtonCallback:
self.incButtonCallback() self.__incButtonCallback()
def __decButtonDown(self, event): def __decButtonDown(self, event):
assert self.notify.debugStateCall(self) assert self.notify.debugStateCall(self)
task = Task(self.__scrollByTask) task = Task(self.__scrollByTask)
task.setDelay(1.0 / self.scrollSpeed) task.setDelay(1.0 / self.__scrollSpeed)
task.prevTime = 0.0 task.prevTime = 0.0
task.delta = -1 task.delta = -1
taskName = self.taskName("scroll") taskName = self.taskName("scroll")
@ -331,8 +330,8 @@ class DirectScrolledList(DirectFrame):
taskMgr.add(task, taskName) taskMgr.add(task, taskName)
self.scrollBy(task.delta) self.scrollBy(task.delta)
messenger.send('wakeup') messenger.send('wakeup')
if self.decButtonCallback: if self.__decButtonCallback:
self.decButtonCallback() self.__decButtonCallback()
def __buttonUp(self, event): def __buttonUp(self, event):
assert self.notify.debugStateCall(self) assert self.notify.debugStateCall(self)
@ -345,7 +344,7 @@ class DirectScrolledList(DirectFrame):
Add this string and extraArg to the list Add this string and extraArg to the list
""" """
assert self.notify.debugStateCall(self) assert self.notify.debugStateCall(self)
if(type(item) == types.InstanceType): if type(item) != type(''):
# cant add attribs to non-classes (like strings & ints) # cant add attribs to non-classes (like strings & ints)
item.itemID = self.nextItemID item.itemID = self.nextItemID
self.nextItemID += 1 self.nextItemID += 1
@ -354,7 +353,7 @@ class DirectScrolledList(DirectFrame):
item.reparentTo(self.itemFrame) item.reparentTo(self.itemFrame)
if refresh: if refresh:
self.refresh() self.refresh()
if(type(item) == types.InstanceType): if type(item) != type(''):
return item.itemID # to pass to scrollToItemID return item.itemID # to pass to scrollToItemID
def removeItem(self, item, refresh=1): def removeItem(self, item, refresh=1):
@ -466,11 +465,11 @@ class DirectScrolledList(DirectFrame):
def setIncButtonCallback(self): def setIncButtonCallback(self):
assert self.notify.debugStateCall(self) assert self.notify.debugStateCall(self)
self.incButtonCallback = self["incButtonCallback"] self.__incButtonCallback = self["incButtonCallback"]
def setDecButtonCallback(self): def setDecButtonCallback(self):
assert self.notify.debugStateCall(self) assert self.notify.debugStateCall(self)
self.decButtonCallback = self["decButtonCallback"] self.__decButtonCallback = self["decButtonCallback"]
""" """

View File

@ -4,7 +4,6 @@ __all__ = ['OnscreenText', 'Plain', 'ScreenTitle', 'ScreenPrompt', 'NameConfirm'
from panda3d.core import * from panda3d.core import *
from . import DirectGuiGlobals as DGG from . import DirectGuiGlobals as DGG
from direct.showbase.DirectObject import DirectObject
import sys import sys
## These are the styles of text we might commonly see. They set the ## These are the styles of text we might commonly see. They set the
@ -17,7 +16,7 @@ ScreenPrompt = 3
NameConfirm = 4 NameConfirm = 4
BlackOnWhite = 5 BlackOnWhite = 5
class OnscreenText(DirectObject, NodePath): class OnscreenText(NodePath):
def __init__(self, text = '', def __init__(self, text = '',
style = Plain, style = Plain,