make TaskManagerPanel compatible with new task manager

This commit is contained in:
David Rose 2008-10-11 14:17:53 +00:00
parent c152dfa441
commit bf6c574747
3 changed files with 39 additions and 43 deletions

View File

@ -492,6 +492,10 @@ class TaskManager:
numFound += self.__tryReplaceTaskMethod(task, oldMethod, newFunction)
return numFound
def popupControls(self):
from direct.tkpanels import TaskManagerPanel
return TaskManagerPanel.TaskManagerPanel(self)
def __repr__(self):
return str(self.mgr)

View File

@ -162,6 +162,12 @@ class Task:
TaskManager.notify.error("deprecated task.setPriority() called; use setSort() instead")
pass
def getName(self):
return self.name
def setName(self, name):
self.name = name
def getDelay(self):
return self.delayTime
@ -202,13 +208,12 @@ class Task:
self.pstatCollector = PStatCollector("Tasks:" + name)
self.pstatCollector.addLevelNow(1)
def finishTask(self, verbose):
def finishTask(self):
if hasattr(self, "uponDeath"):
self.uponDeath(self)
if verbose:
# We regret to announce...
messenger.send('TaskManager-removeTask', sentArgs = [self, self.name])
del self.uponDeath
# We regret to announce...
messenger.send('TaskManager-removeTask', sentArgs = [self])
def __repr__(self):
if hasattr(self, 'name'):
@ -429,7 +434,6 @@ class TaskManager:
self.fKeyboardInterrupt = 0
self.interruptCount = 0
self.resumeFunc = None
self.fVerbose = 0
# Dictionary of task name to list of tasks with that name
self.nameDict = {}
@ -451,10 +455,6 @@ class TaskManager:
def setStepping(self, value):
self.stepping = value
def setVerbose(self, value):
self.fVerbose = value
messenger.send('TaskManager-setVerbose', sentArgs = [value])
def getTaskDurationWarningThreshold(self):
return self.taskDurationWarningThreshold
@ -605,10 +605,9 @@ class TaskManager:
task.wakeTime = currentTime + delayTime
# Push this onto the doLaterList. The heap maintains the sorting.
heappush(self.__doLaterList, task)
if self.fVerbose:
# Alert the world, a new task is born!
messenger.send('TaskManager-spawnDoLater',
sentArgs = [task, task.name, task.id])
# Alert the world, a new task is born!
#messenger.send('TaskManager-spawnDoLater', sentArgs = [task])
if task.owner:
task.owner._addTask(task)
@ -709,10 +708,9 @@ class TaskManager:
if __debug__:
if self.pStatsTasks and task.name != "igLoop":
task.setupPStats()
if self.fVerbose:
# Alert the world, a new task is born!
messenger.send(
'TaskManager-spawnTask', sentArgs = [task, task.name, index])
# Alert the world, a new task is born!
messenger.send('TaskManager-spawnTask', sentArgs = [task])
return task
def remove(self, taskOrName):
@ -745,7 +743,7 @@ class TaskManager:
# '__removeTasksEqual: removing task: %s' % (task))
# Flag the task for removal from the real list
task.remove()
task.finishTask(self.fVerbose)
task.finishTask()
return 1
else:
return 0
@ -759,7 +757,7 @@ class TaskManager:
for task in tasks:
# Flag for removal
task.remove()
task.finishTask(self.fVerbose)
task.finishTask()
# Record the number of tasks removed
num = len(tasks)
# Blow away the nameDict entry completely
@ -875,10 +873,9 @@ class TaskManager:
task.wakeTime = currentTime + task.delayTime
# Push this onto the doLaterList. The heap maintains the sorting.
heappush(self.__doLaterList, task)
if self.fVerbose:
# Alert the world, a new task is born!
messenger.send('TaskManager-againDoLater',
sentArgs = [task, task.name, task.id])
# Alert the world, a new task is born!
#messenger.send('TaskManager-againDoLater', sentArgs = [task])
def __stepThroughList(self, taskPriList):
# Traverse the taskPriList with an iterator
@ -895,7 +892,7 @@ class TaskManager:
# If it was removed in show code, it will need finishTask run
# If it was removed by the taskMgr, it will not, but that is ok
# because finishTask is safe to call twice
task.finishTask(self.fVerbose)
task.finishTask()
taskPriList.remove(i)
self.__removeTaskFromNameDict(task)
# Do not increment the iterator
@ -921,7 +918,7 @@ class TaskManager:
task.remove()
# Note: Should not need to remove from doLaterList here
# because this task is not in the doLaterList
task.finishTask(self.fVerbose)
task.finishTask()
self.__removeTaskFromNameDict(task)
else:
# assert TaskManager.notify.debug(

View File

@ -38,7 +38,6 @@ class TaskManagerPanel(AppShell):
def onDestroy(self, event):
self.ignore('TaskManager-setVerbose')
self.taskMgrWidget.onDestroy()
class TaskManagerWidget(DirectObject):
@ -58,8 +57,6 @@ class TaskManagerWidget(DirectObject):
self.parent = parent
# Record taskManager
self.taskMgr = taskMgr
# Enable sending of spawn and remove messages
self.taskMgr.setVerbose(1)
# Init current task
self.currentTask = None
self.__taskDict = {}
@ -119,7 +116,6 @@ class TaskManagerWidget(DirectObject):
# Add hook to spawnTaskEvents
self.accept('TaskManager-spawnTask', self.spawnTaskHook)
self.accept('TaskManager-removeTask', self.removeTaskHook)
self.accept('TaskManager-setVerbose', self.updateTaskMgrVerbose)
# Get listbox
listbox = self.taskListBox.component('listbox')
# Bind updates to arrow buttons
@ -155,13 +151,14 @@ class TaskManagerWidget(DirectObject):
# Get a list of task names
taskNames = []
self.__taskDict = {}
tasks = self.taskMgr.getTasks()
tasks.sort(key = lambda t: t.getName())
count = 0
for taskPriList in self.taskMgr.taskList:
for task in taskPriList:
if ((task is not None) and (not task.isRemoved())):
taskNames.append(task.name)
self.__taskDict[count] = task
count += 1
for task in tasks:
taskNames.append(task.getName())
self.__taskDict[count] = task
count += 1
print taskNames
if taskNames:
self.taskListBox.setlist(taskNames)
# And set current index (so keypresses will start with index 0)
@ -171,18 +168,16 @@ class TaskManagerWidget(DirectObject):
self.setCurrentTask()
def toggleTaskMgrVerbose(self):
taskMgr.setVerbose(self.taskMgrVerbose.get())
if self.taskMgrVerbose.get():
self.updateTaskListBox()
def updateTaskMgrVerbose(self, value):
self.taskMgrVerbose.set(value)
def spawnTaskHook(self, task):
if self.taskMgrVerbose.get():
self.updateTaskListBox()
def spawnTaskHook(self, task, name, index):
self.updateTaskListBox()
def removeTaskHook(self, task, name):
self.updateTaskListBox()
def removeTaskHook(self, task):
if self.taskMgrVerbose.get():
self.updateTaskListBox()
def removeCurrentTask(self):
if self.currentTask: