HTTPChannel_extensions.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. ####################################################################
  2. #Dtool_funcToMethod(func, class)
  3. #del func
  4. #####################################################################
  5. from panda3d import core
  6. from .extension_native_helpers import Dtool_funcToMethod
  7. """
  8. HTTPChannel-extensions module: contains methods to extend functionality
  9. of the HTTPChannel class
  10. """
  11. def spawnTask(self, name = None, callback = None, extraArgs = []):
  12. """Spawns a task to service the download recently requested
  13. via beginGetDocument(), etc., and/or downloadToFile() or
  14. downloadToRam(). If a callback is specified, that function is
  15. called when the download is complete, passing in the extraArgs
  16. given.
  17. Returns the newly-spawned task.
  18. """
  19. if not name:
  20. name = str(self.getUrl())
  21. from direct.task import Task
  22. task = Task.Task(self.doTask)
  23. task.callback = callback
  24. task.callbackArgs = extraArgs
  25. return taskMgr.add(task, name)
  26. if hasattr(core, 'HTTPChannel'):
  27. Dtool_funcToMethod(spawnTask, core.HTTPChannel)
  28. del spawnTask
  29. #####################################################################
  30. def doTask(self, task):
  31. from direct.task import Task
  32. if self.run():
  33. return Task.cont
  34. if task.callback:
  35. task.callback(*task.callbackArgs)
  36. return Task.done
  37. if hasattr(core, 'HTTPChannel'):
  38. Dtool_funcToMethod(doTask, core.HTTPChannel)
  39. del doTask
  40. #####################################################################