mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
make TaskManagerPanel compatible with new task manager
This commit is contained in:
parent
c152dfa441
commit
bf6c574747
@ -492,6 +492,10 @@ class TaskManager:
|
|||||||
numFound += self.__tryReplaceTaskMethod(task, oldMethod, newFunction)
|
numFound += self.__tryReplaceTaskMethod(task, oldMethod, newFunction)
|
||||||
return numFound
|
return numFound
|
||||||
|
|
||||||
|
def popupControls(self):
|
||||||
|
from direct.tkpanels import TaskManagerPanel
|
||||||
|
return TaskManagerPanel.TaskManagerPanel(self)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return str(self.mgr)
|
return str(self.mgr)
|
||||||
|
|
||||||
|
@ -162,6 +162,12 @@ class Task:
|
|||||||
TaskManager.notify.error("deprecated task.setPriority() called; use setSort() instead")
|
TaskManager.notify.error("deprecated task.setPriority() called; use setSort() instead")
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def getName(self):
|
||||||
|
return self.name
|
||||||
|
|
||||||
|
def setName(self, name):
|
||||||
|
self.name = name
|
||||||
|
|
||||||
def getDelay(self):
|
def getDelay(self):
|
||||||
return self.delayTime
|
return self.delayTime
|
||||||
|
|
||||||
@ -202,13 +208,12 @@ class Task:
|
|||||||
self.pstatCollector = PStatCollector("Tasks:" + name)
|
self.pstatCollector = PStatCollector("Tasks:" + name)
|
||||||
self.pstatCollector.addLevelNow(1)
|
self.pstatCollector.addLevelNow(1)
|
||||||
|
|
||||||
def finishTask(self, verbose):
|
def finishTask(self):
|
||||||
if hasattr(self, "uponDeath"):
|
if hasattr(self, "uponDeath"):
|
||||||
self.uponDeath(self)
|
self.uponDeath(self)
|
||||||
if verbose:
|
|
||||||
# We regret to announce...
|
|
||||||
messenger.send('TaskManager-removeTask', sentArgs = [self, self.name])
|
|
||||||
del self.uponDeath
|
del self.uponDeath
|
||||||
|
# We regret to announce...
|
||||||
|
messenger.send('TaskManager-removeTask', sentArgs = [self])
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
if hasattr(self, 'name'):
|
if hasattr(self, 'name'):
|
||||||
@ -429,7 +434,6 @@ class TaskManager:
|
|||||||
self.fKeyboardInterrupt = 0
|
self.fKeyboardInterrupt = 0
|
||||||
self.interruptCount = 0
|
self.interruptCount = 0
|
||||||
self.resumeFunc = None
|
self.resumeFunc = None
|
||||||
self.fVerbose = 0
|
|
||||||
# Dictionary of task name to list of tasks with that name
|
# Dictionary of task name to list of tasks with that name
|
||||||
self.nameDict = {}
|
self.nameDict = {}
|
||||||
|
|
||||||
@ -451,10 +455,6 @@ class TaskManager:
|
|||||||
def setStepping(self, value):
|
def setStepping(self, value):
|
||||||
self.stepping = value
|
self.stepping = value
|
||||||
|
|
||||||
def setVerbose(self, value):
|
|
||||||
self.fVerbose = value
|
|
||||||
messenger.send('TaskManager-setVerbose', sentArgs = [value])
|
|
||||||
|
|
||||||
def getTaskDurationWarningThreshold(self):
|
def getTaskDurationWarningThreshold(self):
|
||||||
return self.taskDurationWarningThreshold
|
return self.taskDurationWarningThreshold
|
||||||
|
|
||||||
@ -605,10 +605,9 @@ class TaskManager:
|
|||||||
task.wakeTime = currentTime + delayTime
|
task.wakeTime = currentTime + delayTime
|
||||||
# Push this onto the doLaterList. The heap maintains the sorting.
|
# Push this onto the doLaterList. The heap maintains the sorting.
|
||||||
heappush(self.__doLaterList, task)
|
heappush(self.__doLaterList, task)
|
||||||
if self.fVerbose:
|
|
||||||
# Alert the world, a new task is born!
|
# Alert the world, a new task is born!
|
||||||
messenger.send('TaskManager-spawnDoLater',
|
#messenger.send('TaskManager-spawnDoLater', sentArgs = [task])
|
||||||
sentArgs = [task, task.name, task.id])
|
|
||||||
|
|
||||||
if task.owner:
|
if task.owner:
|
||||||
task.owner._addTask(task)
|
task.owner._addTask(task)
|
||||||
@ -709,10 +708,9 @@ class TaskManager:
|
|||||||
if __debug__:
|
if __debug__:
|
||||||
if self.pStatsTasks and task.name != "igLoop":
|
if self.pStatsTasks and task.name != "igLoop":
|
||||||
task.setupPStats()
|
task.setupPStats()
|
||||||
if self.fVerbose:
|
|
||||||
# Alert the world, a new task is born!
|
# Alert the world, a new task is born!
|
||||||
messenger.send(
|
messenger.send('TaskManager-spawnTask', sentArgs = [task])
|
||||||
'TaskManager-spawnTask', sentArgs = [task, task.name, index])
|
|
||||||
return task
|
return task
|
||||||
|
|
||||||
def remove(self, taskOrName):
|
def remove(self, taskOrName):
|
||||||
@ -745,7 +743,7 @@ class TaskManager:
|
|||||||
# '__removeTasksEqual: removing task: %s' % (task))
|
# '__removeTasksEqual: removing task: %s' % (task))
|
||||||
# Flag the task for removal from the real list
|
# Flag the task for removal from the real list
|
||||||
task.remove()
|
task.remove()
|
||||||
task.finishTask(self.fVerbose)
|
task.finishTask()
|
||||||
return 1
|
return 1
|
||||||
else:
|
else:
|
||||||
return 0
|
return 0
|
||||||
@ -759,7 +757,7 @@ class TaskManager:
|
|||||||
for task in tasks:
|
for task in tasks:
|
||||||
# Flag for removal
|
# Flag for removal
|
||||||
task.remove()
|
task.remove()
|
||||||
task.finishTask(self.fVerbose)
|
task.finishTask()
|
||||||
# Record the number of tasks removed
|
# Record the number of tasks removed
|
||||||
num = len(tasks)
|
num = len(tasks)
|
||||||
# Blow away the nameDict entry completely
|
# Blow away the nameDict entry completely
|
||||||
@ -875,10 +873,9 @@ class TaskManager:
|
|||||||
task.wakeTime = currentTime + task.delayTime
|
task.wakeTime = currentTime + task.delayTime
|
||||||
# Push this onto the doLaterList. The heap maintains the sorting.
|
# Push this onto the doLaterList. The heap maintains the sorting.
|
||||||
heappush(self.__doLaterList, task)
|
heappush(self.__doLaterList, task)
|
||||||
if self.fVerbose:
|
|
||||||
# Alert the world, a new task is born!
|
# Alert the world, a new task is born!
|
||||||
messenger.send('TaskManager-againDoLater',
|
#messenger.send('TaskManager-againDoLater', sentArgs = [task])
|
||||||
sentArgs = [task, task.name, task.id])
|
|
||||||
|
|
||||||
def __stepThroughList(self, taskPriList):
|
def __stepThroughList(self, taskPriList):
|
||||||
# Traverse the taskPriList with an iterator
|
# 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 in show code, it will need finishTask run
|
||||||
# If it was removed by the taskMgr, it will not, but that is ok
|
# If it was removed by the taskMgr, it will not, but that is ok
|
||||||
# because finishTask is safe to call twice
|
# because finishTask is safe to call twice
|
||||||
task.finishTask(self.fVerbose)
|
task.finishTask()
|
||||||
taskPriList.remove(i)
|
taskPriList.remove(i)
|
||||||
self.__removeTaskFromNameDict(task)
|
self.__removeTaskFromNameDict(task)
|
||||||
# Do not increment the iterator
|
# Do not increment the iterator
|
||||||
@ -921,7 +918,7 @@ class TaskManager:
|
|||||||
task.remove()
|
task.remove()
|
||||||
# Note: Should not need to remove from doLaterList here
|
# Note: Should not need to remove from doLaterList here
|
||||||
# because this task is not in the doLaterList
|
# because this task is not in the doLaterList
|
||||||
task.finishTask(self.fVerbose)
|
task.finishTask()
|
||||||
self.__removeTaskFromNameDict(task)
|
self.__removeTaskFromNameDict(task)
|
||||||
else:
|
else:
|
||||||
# assert TaskManager.notify.debug(
|
# assert TaskManager.notify.debug(
|
||||||
|
@ -38,7 +38,6 @@ class TaskManagerPanel(AppShell):
|
|||||||
|
|
||||||
|
|
||||||
def onDestroy(self, event):
|
def onDestroy(self, event):
|
||||||
self.ignore('TaskManager-setVerbose')
|
|
||||||
self.taskMgrWidget.onDestroy()
|
self.taskMgrWidget.onDestroy()
|
||||||
|
|
||||||
class TaskManagerWidget(DirectObject):
|
class TaskManagerWidget(DirectObject):
|
||||||
@ -58,8 +57,6 @@ class TaskManagerWidget(DirectObject):
|
|||||||
self.parent = parent
|
self.parent = parent
|
||||||
# Record taskManager
|
# Record taskManager
|
||||||
self.taskMgr = taskMgr
|
self.taskMgr = taskMgr
|
||||||
# Enable sending of spawn and remove messages
|
|
||||||
self.taskMgr.setVerbose(1)
|
|
||||||
# Init current task
|
# Init current task
|
||||||
self.currentTask = None
|
self.currentTask = None
|
||||||
self.__taskDict = {}
|
self.__taskDict = {}
|
||||||
@ -119,7 +116,6 @@ class TaskManagerWidget(DirectObject):
|
|||||||
# Add hook to spawnTaskEvents
|
# Add hook to spawnTaskEvents
|
||||||
self.accept('TaskManager-spawnTask', self.spawnTaskHook)
|
self.accept('TaskManager-spawnTask', self.spawnTaskHook)
|
||||||
self.accept('TaskManager-removeTask', self.removeTaskHook)
|
self.accept('TaskManager-removeTask', self.removeTaskHook)
|
||||||
self.accept('TaskManager-setVerbose', self.updateTaskMgrVerbose)
|
|
||||||
# Get listbox
|
# Get listbox
|
||||||
listbox = self.taskListBox.component('listbox')
|
listbox = self.taskListBox.component('listbox')
|
||||||
# Bind updates to arrow buttons
|
# Bind updates to arrow buttons
|
||||||
@ -155,13 +151,14 @@ class TaskManagerWidget(DirectObject):
|
|||||||
# Get a list of task names
|
# Get a list of task names
|
||||||
taskNames = []
|
taskNames = []
|
||||||
self.__taskDict = {}
|
self.__taskDict = {}
|
||||||
|
tasks = self.taskMgr.getTasks()
|
||||||
|
tasks.sort(key = lambda t: t.getName())
|
||||||
count = 0
|
count = 0
|
||||||
for taskPriList in self.taskMgr.taskList:
|
for task in tasks:
|
||||||
for task in taskPriList:
|
taskNames.append(task.getName())
|
||||||
if ((task is not None) and (not task.isRemoved())):
|
self.__taskDict[count] = task
|
||||||
taskNames.append(task.name)
|
count += 1
|
||||||
self.__taskDict[count] = task
|
print taskNames
|
||||||
count += 1
|
|
||||||
if taskNames:
|
if taskNames:
|
||||||
self.taskListBox.setlist(taskNames)
|
self.taskListBox.setlist(taskNames)
|
||||||
# And set current index (so keypresses will start with index 0)
|
# And set current index (so keypresses will start with index 0)
|
||||||
@ -171,18 +168,16 @@ class TaskManagerWidget(DirectObject):
|
|||||||
self.setCurrentTask()
|
self.setCurrentTask()
|
||||||
|
|
||||||
def toggleTaskMgrVerbose(self):
|
def toggleTaskMgrVerbose(self):
|
||||||
taskMgr.setVerbose(self.taskMgrVerbose.get())
|
|
||||||
if self.taskMgrVerbose.get():
|
if self.taskMgrVerbose.get():
|
||||||
self.updateTaskListBox()
|
self.updateTaskListBox()
|
||||||
|
|
||||||
def updateTaskMgrVerbose(self, value):
|
def spawnTaskHook(self, task):
|
||||||
self.taskMgrVerbose.set(value)
|
if self.taskMgrVerbose.get():
|
||||||
|
self.updateTaskListBox()
|
||||||
|
|
||||||
def spawnTaskHook(self, task, name, index):
|
def removeTaskHook(self, task):
|
||||||
self.updateTaskListBox()
|
if self.taskMgrVerbose.get():
|
||||||
|
self.updateTaskListBox()
|
||||||
def removeTaskHook(self, task, name):
|
|
||||||
self.updateTaskListBox()
|
|
||||||
|
|
||||||
def removeCurrentTask(self):
|
def removeCurrentTask(self):
|
||||||
if self.currentTask:
|
if self.currentTask:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user