From 907c9541a919f28e728821d1959bef3442ac8f96 Mon Sep 17 00:00:00 2001 From: David Rose Date: Wed, 29 Oct 2008 15:24:08 +0000 Subject: [PATCH] getTasksMatching --- direct/src/task/TaskNew.py | 7 +++++++ direct/src/task/TaskOrig.py | 17 +++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/direct/src/task/TaskNew.py b/direct/src/task/TaskNew.py index 60a214dc2c..77121c81ee 100644 --- a/direct/src/task/TaskNew.py +++ b/direct/src/task/TaskNew.py @@ -222,6 +222,13 @@ class TaskManager: indicated name. """ return self.__makeTaskList(self.mgr.findTasks(taskName)) + def getTasksMatching(self, taskPattern): + """Returns a list of all tasks, active or sleeping, with a + name that matches the pattern, which can include standard + shell globbing characters like *, ?, and []. """ + + return self.__makeTaskList(self.mgr.findTasksMatching(GlobPattern(taskPattern))) + def getAllTasks(self): """Returns list of all tasks, active and sleeping, in arbitrary order. """ diff --git a/direct/src/task/TaskOrig.py b/direct/src/task/TaskOrig.py index 2d41276cc6..67342ea747 100644 --- a/direct/src/task/TaskOrig.py +++ b/direct/src/task/TaskOrig.py @@ -536,6 +536,23 @@ class TaskManager: return [task for task in self.nameDict.get(taskName, []) #grab all tasks with name if not task._removed] #filter removed tasks + def getTasksMatching(self, taskPattern): + """getTasksMatching(self, string taskPattern) + + Returns tasks whose names match the pattern, which can include + standard shell globbing characters like *, ?, and []. + """ + keyList = filter( + lambda key: fnmatch.fnmatchcase(key, taskPattern), + self.nameDict.keys()) + + result = [] + for key in keyList: + for task in self.nameDict.get(key, []): + if not task._removed: + result.append(task) + return result + def __doLaterFilter(self): # Filter out all the tasks that have been removed like a mark and # sweep garbage collector. Returns the number of tasks that have