I’m new to panda3d and trying to figure out something that I thought would be simple, but it’s giving me a hard time.
I have a simple application where I want to register the user’s name with a DirectEntry at the beginning of a coroutine. I choice to use a coroutine because several tasks and steps need to be completed in order without blocking the main tread. Because the user ID is important to wait for in this coroutine I want to await a event or task or something, so the application can properly capture the user name before continuing doing the various tasks. However I can’t seem to make it work and neither could find this problem on the forums. I tried to make it with with await messenger.future('even_name') but this is not working. I can’t figure out how to make it work with a Task either. Somebody has some tips on this?
Regrettably, it does not seem that messenger.future is working for custom-generated events with messenger.send. I suggest filing a bug report for this on the issue tracker.
However, I think in this case I would prefer using explicit futures for this anyway. One possible approach is:
async def main_coroutine(self):
text = OnscreenText(text="name:")
fut = AsyncFuture()
entry = DirectEntry(focus=1, command=lambda text, fut=fut:fut.set_result(text))
user_name = await fut
print(user_name)
This indeed solves it, thank you. I will also report a bug report for this on the issue tracker.
One more follow up question, could I have found more information on this fut parameter myself in the documentation? I can’t find it at all in the documentation, and if I look at the python implementation of DirectEntry it’s also not there, how is this code working?
edit: or is this more fundamental to Python’s Async/coroutine/task programming scheme’s?