Open spookylukey opened 2 years ago
Typer allows you to use Python type annotations to make it easy to create command line interface applications
You may also want to look at plumbum
and click
It would be awesome if I could easily convert a script or program written like this into a simple, easy-to-use GUI
I have a better idea - parse CLI --help
output and generate GUI from it. And if I remember right, there are already apps doing this.
It would be awesome if I could easily convert a script or program written like this into a simple, easy-to-use GUI
I have a better idea - parse CLI
--help
output and generate GUI from it. And if I remember right, there are already apps doing this.
I imagine that parsing --help
output could be quite fragile, and will end up losing information.
However, I have found Gooey does something very similar to this, but for apps using argparse
. It seems like a module for Gooey that works with the Typer API instead of the argparse API would be exactly what I'm looking for.
I imagine that parsing --help output could be quite fragile
The better approach is to specify CLI args in a formal language (conversion by the means of libs), compile it into a binary blob, and embed this blob into binaries. So, to get a spec for CLI args one would just need to lookup an exported symbol and parse the blob. And alternatively, a command to print the blob into stdout.
Any thought of converting to html instead? Perhaps even a framework like React or Vue?
I've been weighing the idea of trying to apply one of these to a Typer project:
The first supports click
, which typer
is directly based on - so that kind of effort would likely be mainly gluing it all together.
The second is very argparse
-based, which I'm unsure if is being used somewhere deep under the hood by click
. Likely not - but it's not totally unlikely that there could be some semi-simple way of taking the click
representation and reshaping it into an argparse
representation. Worth investigating.
Project description
A library that auto-generates a simple GUI interface for simple scripts and programs, based on Python type annotations.
Explanation
Typer allows you to use Python type annotations to make it easy to create command line interface applications, complete with nice auto-generated documentation. For example:
You can then do this, for example:
Now, I love CLIs, but some people prefer GUIs (e.g. my wife), and there are times when she would like to use programs I've written (e.g. for managing family finances). It would be awesome if I could easily convert a script or program written like this into a simple, easy-to-use GUI that:
To do this, you could create a full implementation of the
typer
API, but it would create a GUI instead. So, for example, for the above script you would get:For more complex options, you'd have more complex widget types. For example, if the program defined an argument as an enum, you would present this using a dropdown list to choose from. If an argument was a
Path
, this would probably be a file/directory picker widget etc. If the type annotations specified a list of files, the UI would have a+
button that would allow another instance of the widget to appear, to select multiple files.There are a range of cross-platform GUI libraries for Python you could use e.g.:
Using the library
Let's assume our new project is called
typer_gui
.One way to use the library would be to manually switch from
typer
totyper_gui
. Instead ofimport typer
as above, you would doimport typer_gui as typer
, and that's all you'd need to do, becausetyper_gui
would function as a drop-in replacement fortyper
. Also, you could do:Better than either of these would be to make it easy to use either the CLI or the GUI version, depending on context. If someone runs an app from a terminal, they get the CLI (the GUI libraries would not even be imported, for speed). If they run it by double clicking on the app from a file manager, they get the GUI version:
Challenges and questions
How should you display output from the script, and get any further interactive input?
Relevant Technology
Understanding of how Typer works, and some basic GUI technology.
Complexity and required time
Complexity
Required time (ETA)
Although it would take a lot of work to complete, I think it wouldn't take too long to get something visible that worked for very simple cases, which would be quite helpful for motivation.
Categories