beeware / toga

A Python native, OS native GUI toolkit.
https://toga.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
4.2k stars 656 forks source link

Toga-based CLI-to-GUI builder? #2685

Closed twardoch closed 5 days ago

twardoch commented 5 days ago

What is the problem or limitation you are having?

Trogon uses Textual to automatically builds TUIs from Click CLI apps: https://github.com/Textualize/trogon

and even from Typer CLI apps (via click): https://github.com/Textualize/trogon/issues/10#issuecomment-1557125247

I know Toga has its own textual backend plus other backends. So if Trogon were ported to Toga (rather than being based on Textual), one could go Typer -> Click -> Toga -> ...

Describe the solution you'd like

A "port" of Trogon to Toga, as a separate package

Describe alternatives you've considered

I've used Gooey for rapid automatic building of GUI from CLI, but Gooey relies on argparse more-less directly, and while quite feature-rich, it's also a bit antiquated.

Typer uses Click insert the hood but allows very simple declarative CLI definitions and Trogon already does a decent job at building a TUI from Click & Typer, but it's limited to TUI.

Toga looks like a great package for single-source cross-platform TUI+GUI building, and by adapting Trogon to Toga, we could have a very powerful yet extremely simple to use GUI builder that could be easily "injected" into existing Click CLI apps.

Additional context

No response

freakboy3742 commented 5 days ago

I agree that Toga would be a good match for this sort of functionality. Being able to generate a GUI or TUI (or, for that matter, web) frontend for a command line script sounds extremely interesting. There's actually an interesting crossover with #90 - the mechanisms needed to convert a "command line specification" and an abstract definition of settings into a GUI representation should be quite similar.

However, the specific feature (an app bootstrap) wouldn't be part of Toga itself. It makes a lot more sense as something to add as an option on Trogon/Gooey/Typer.

Alternatively, it might make an interesting bootstrap plugin for Briefcase. We've recently added a "bootstrap plugin" API to Briefcase that allows the plugin to inject app logic into a new app. We're using it for testing purposes - injecting "shut down after 2 seconds" logic so we can test that a Briefcase generated app can start; we anticipated someone eventually writing a "Positron" plugin that can convert a website into an app. A similar plugin to convert a click/argparse definition would also be interesting.

However, in either case, there's nothing actionable for Toga; on that basis, I'm going to close this issue. If this is an area where you're interested, I'd strongly encourage you to pursue it - we're happy to provide any assistance or suggestions; and if there's changes that need to be made to Toga or Briefcase to make this more plausible, we're definitely open to those discussions.