-
Notifications
You must be signed in to change notification settings - Fork 780
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pass Additional Information Into App #1030
Comments
Given that a Textual app is always going to be done as a subclass of from textual.app import App, ComposeResult
from textual.widgets import Static
class Greetings(App[None]):
def __init__(self, greeting: str="Hello", to_greet: str="World") -> None:
self.greeting = greeting
self.to_greet = to_greet
super().__init__()
def compose(self) -> ComposeResult:
yield Static(f"{self.greeting}, {self.to_greet}")
if __name__=="__main__":
Greetings().run()
Greetings(to_greet="davep").run()
Greetings("Well hello", "there").run() |
Did we solve your problem? Glad we could help! |
Thanks Dave and Textual Team, Textual has been awesome to work with so far! |
My pleasure; glad to hear you're enjoying it. :-) |
TLDR; As an app developer, I'd like to pass additional information into an
App
instance to allow for some more more complex configuration. This originally came up when I was working on writing a CLI that embeds different textual applications under different commands andargv
became complicated. I'm thinking about the implementation as an additional parameter, likeconfig_object
, that sets an instance attribute to be used downstream.Let's say we have this nice app,
simple_app.py
. We can see that it prints a message depending on what arguments are passed to the python script.But now, I want to import this app into another file and nest it under a command line application,
command_line.py
:argv
becomes a little complicated to manage when being nested on other CLIs. Instead, it would be awesome to do something like this to pass in a more complex configuration object:and subsequently be able to grab that config like this:
Here's how I've implemented this myself using a subclass of
App
- let me know your thoughts. I'd be more than happy to contribute.... and now:
The text was updated successfully, but these errors were encountered: