FHPythonUtils / Cli2Gui

Use this module to convert a cli program to a gui
MIT License
90 stars 7 forks source link

Feature: virtual terminal #8

Closed milahu closed 2 years ago

milahu commented 2 years ago

Feature

add a virtual terminal widget, so we can show the live stdout and stderr of the run function

Is your feature request related to a problem? Please describe

problem: when running the app without a terminal, then stdout/stderr are not visible

Describe the solution you'd like

challenges:

example: capture stdout with io.TextIOBase https://stackoverflow.com/questions/51527750/capture-print-output-from-multiple-threads-in-python

```py import threading import time import sys import io class demo_copy_stdout(): def __init__(self): def run_function(): for i in range(0, 100): print(*sys.argv, i) time.sleep(1) self.run_function = run_function def main_function_wrapper(*argv): sys.argv = argv # set arguments # note: run_function takes no arguments return self.run_function() print("main_thread create") self.main_thread = threading.Thread(target=main_function_wrapper, args=("toy.py", "hello",)) class CopyStdout(io.TextIOBase): def __init__(self, target): self.target = target #self.stringio = io.StringIO() def write(self, s): writecount = self.target.write(s) written = s[:writecount] #self.stringio.write(written) # TODO send to GUI with open("stdout.txt", "a") as f: f.write(written) return writecount print("copying stdout to tee.txt") original_stdout = sys.stdout sys.stdout = CopyStdout(sys.stdout) print("main_thread start") self.main_thread.start() # run if True: print("main_thread wait ...") self.main_thread.join() # wait print("main_thread done") sys.stdout = original_stdout # stop copying stdout x = demo_copy_stdout() ```

Describe alternatives you've considered

Additional context

milahu commented 2 years ago

ps. im working on this : )

Screenshot_2022-04-08_13-12-09 cli2gui terminal

the input tab is the old interface with all the input elements, to set arguments

the output tab is a fully-featured bash terminal (todo: on windows run busybox-w32)

when the user hits start, the GUI switches to the output tab and shows all output from the process

FredHappyface commented 2 years ago

Wow that looks awesome thanks for making a start on it. I was going to add it to the backlog as there's a couple other projects I'm focusing on right now

I'm assuming this is compatible with pysimplegui?

Cheers 😊

milahu commented 2 years ago

I'm assuming this is compatible with pysimplegui?

yes, this is implemented in psg

FredHappyface commented 2 years ago

Closing for the following reasons:

  1. Challenges implementing this in a cross-platform way https://github.com/FHPythonUtils/Cli2Gui/pull/9#issuecomment-1165966140
  2. Probably out of scope. I'd encourage an end user to use their fav terminal to start the process in the first place (though there are drawbacks to this)