-
Hello, I'm writing a TUI module submitting and getting messages from other modules. I have been trying to register the message exchange function in some main module dynamically, like from tui import TextualApp
from contexts import message_exchange_function
# if name is main
app = TextualApp()
app.register_on_input_submitted(lambda input: message_exchange_function(input))
app.run() I've consulted docs of worker and skimmed some issues, but they only gave examples when the function is a class/instance method. Is this the only way recommended? Is there some way to decouple the tui and contexts module somewhat? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
It's not very clear from your question what it is you actually want to do, or what the connection is to workers. Do you think you could try rewording your question and adding some more detail? |
Beta Was this translation helpful? Give feedback.
-
Hello again @davep and very sorry for disturbance as well as any confusion in my amateurish expression. I'm actually thinking about something like such a situation:
, in which I try to mount something dynamically onto a tab with a ContextManager like a TextIOWrapper or a TCP connection. I want it to handle the context just like in a |
Beta Was this translation helpful? Give feedback.
You appear to be wanting to close a file you've opened for writing at the app level, it's not clear to me why you wouldn't simply call
close
on the resulting handle. As for how and where you'd do that: it's also unclear to me why you'd open it at the app level, but then want to close it down at an individual widget level.I'm still not really clear what it is you're asking or why the mention of context managers and
with
; but given the code you've shown, suggesting you want a resource open for the lifetime of the application and you want to tidy up when you leave, honestly I think I'd personally create/clean outside of the application. For example: