FHPythonUtils / Cli2Gui

Use this module to convert a cli program to a gui
MIT License
88 stars 6 forks source link

add terminal widget [DRAFT] #9

Closed milahu closed 2 years ago

milahu commented 2 years ago

What is the purpose of this pull request? (put an "X" next to item)

What changes did you make? (Give an overview)

add a fully-featured bash terminal to the GUI to show the output of the process and to allow the user to "play" with a bash terminal

Which issue (if any) does this pull request address?

Fixes #8

Is there anything you'd like reviewers to focus on?

FredHappyface commented 2 years ago

Thanks again for the work on this!

Just taken a quick look (aware that is is WIP so feel free to take these comments with a pinch of salt)

One thing that caught my eye was the inclusion of a local pysimplegui. If you've added/ changed functionality then I'd suggest raising that upstream as it may benefit other users too. And if you don't fancy that then can you monkey patch it or add the functionality in a different file (may be worth vendoring depending on the size etc)

Just a forewarning that I won't be accepting a pr with +20k lines as I don't have the time to review that

milahu commented 2 years ago

basically working on linux, tested with autosub

just needed some glue code for the file inputs cos autosub has type=str but cli2gui needs type=argparse.FileType("rb")

glue code ```py def main(): # run the CLI version parser = argparse.ArgumentParser(description="AutoSub") parser.add_argument( "--file", type=argparse.FileType("rb"), # -> value is io.BufferedReader(name="/path/to/file", ...) required=False, help="Input video file" ) # ... args = parser.parse_args() run(args) def run(args): # glue code between cli2gui and main # convert io.BufferedReader to str for file_key in ["file", "model", "scorer"]: file = getattr(args, file_key) if file: name = file.name file.close() setattr(args, file_key, name) # process args.file ... cli2gui_decorate = Cli2Gui( run_function=run, auto_enable=True, program_name="AutoSub", program_description="Generate subtitles for videos using offline speech recognition", ) # The gui function can be used as a GUI entrypoint # Example: python -m mymodule:main.gui def gui(): if len(sys.argv) > 1: # TODO better main() else: gui_main = cli2gui_decorate(main) gui_main() ```

todo: make it work on windows, using busybox-w32

milahu commented 2 years ago

sorry for abandoning this

iirc, the big issues were

for performance, its probably better to render the terminal with alacritty or kitty embedded into some widgets for menus and input forms

related

im still surprised that qt/gtk/tk dont have cross-platform ansi terminal widgets ...

FredHappyface commented 2 years ago

Dw about it

Yeah agreed that there don't appear to be tons of solutions. Though what confuses me about this all is why you wouldn't use use your fav terminal to start the process in the first place?

If you're done with this then I'll probably close the pr

As you probably know you are absolutely welcome to fork this if you want/ need this feature. Just for it to be part of this project it could really do with being platform independent

Thank you for all your time on this though. Definitely appreciated! - it's nice to see that the project is useful to others too

milahu commented 2 years ago

why you wouldn't use use your fav terminal to start the process in the first place?

im thinking of "the user" who starts a gui app, enters his data via gui and expects the process to run as if it was started from a terminal emulator (but gui and terminal should be the same window) as bonus, the user gets features like bash job control, or command history

anyway, closing as abandoned : /