From 865a7730c4b1746626175e669dacfe620e54e020 Mon Sep 17 00:00:00 2001 From: Edvard Rejthar Date: Wed, 11 Sep 2024 16:29:28 +0200 Subject: [PATCH] WIP --- docs/index.md | 1 + mininterface/__init__.py | 31 +++++++++++++++++++------------ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/docs/index.md b/docs/index.md index a63f972..cf06db6 100644 --- a/docs/index.md +++ b/docs/index.md @@ -223,5 +223,6 @@ m.form(my_dictionary) + diff --git a/mininterface/__init__.py b/mininterface/__init__.py index 1a4491c..10e18ac 100644 --- a/mininterface/__init__.py +++ b/mininterface/__init__.py @@ -112,19 +112,26 @@ class Env: You cay context manager the function by a `with` statement. The stdout will be redirected to the interface (ex. a GUI window). - TODO add wrap example - - Undocumented experimental: The `env_class` may be a function as well. We invoke its parameters. - However, as Mininterface.env stores the output of the function instead of the Argparse namespace, - methods like `Mininterface.form(None)` (to ask for editing the env values) will work unpredictibly. - Also, the config file seems to be fetched only for positional (missing) parameters, - and ignored for keyword (filled) parameters. - It seems to be this is the tyro's deal and hence it might start working any time. - If not, we might help it this way: - `if isinstance(config, FunctionType): config = lambda: config(**kwargs["default"])` - - Undocumented experimental: `default` keyword argument for tyro may serve for default values instead of a config file. + + ```python + with run(Env) as m: + print(f"Your important number is {m.env.important_number}") + boolean = m.is_yes("Is that alright?") + ``` + + ![Small window with the text 'Your important number'](asset/hello-with-statement.webp "With statement to redirect the output") + ![The same in terminal'](asset/hello-with-statement-tui.avif "With statement in TUI fallback") """ + # Undocumented experimental: The `env_class` may be a function as well. We invoke its parameters. + # However, as Mininterface.env stores the output of the function instead of the Argparse namespace, + # methods like `Mininterface.form(None)` (to ask for editing the env values) will work unpredictibly. + # Also, the config file seems to be fetched only for positional (missing) parameters, + # and ignored for keyword (filled) parameters. + # It seems to be this is the tyro's deal and hence it might start working any time. + # If not, we might help it this way: + # `if isinstance(config, FunctionType): config = lambda: config(**kwargs["default"])` + # + # Undocumented experimental: `default` keyword argument for tyro may serve for default values instead of a config file. # Prepare the config file if config_file is True and not kwargs.get("default") and env_class: