parent
e6742151aa
commit
900564fecc
5 changed files with 74 additions and 162 deletions
@ -1,52 +0,0 @@ |
|||||||
import os |
|
||||||
import subprocess |
|
||||||
from openpilot.common.basedir import BASEDIR |
|
||||||
|
|
||||||
|
|
||||||
class Spinner: |
|
||||||
def __init__(self): |
|
||||||
try: |
|
||||||
self.spinner_proc = subprocess.Popen(["./spinner.py"], |
|
||||||
stdin=subprocess.PIPE, |
|
||||||
cwd=os.path.join(BASEDIR, "system", "ui"), |
|
||||||
close_fds=True) |
|
||||||
except OSError: |
|
||||||
self.spinner_proc = None |
|
||||||
|
|
||||||
def __enter__(self): |
|
||||||
return self |
|
||||||
|
|
||||||
def update(self, spinner_text: str): |
|
||||||
if self.spinner_proc is not None: |
|
||||||
self.spinner_proc.stdin.write(spinner_text.encode('utf8') + b"\n") |
|
||||||
try: |
|
||||||
self.spinner_proc.stdin.flush() |
|
||||||
except BrokenPipeError: |
|
||||||
pass |
|
||||||
|
|
||||||
def update_progress(self, cur: float, total: float): |
|
||||||
self.update(str(round(100 * cur / total))) |
|
||||||
|
|
||||||
def close(self): |
|
||||||
if self.spinner_proc is not None: |
|
||||||
self.spinner_proc.kill() |
|
||||||
try: |
|
||||||
self.spinner_proc.communicate(timeout=2.) |
|
||||||
except subprocess.TimeoutExpired: |
|
||||||
print("WARNING: failed to kill spinner") |
|
||||||
self.spinner_proc = None |
|
||||||
|
|
||||||
def __del__(self): |
|
||||||
self.close() |
|
||||||
|
|
||||||
def __exit__(self, exc_type, exc_value, traceback): |
|
||||||
self.close() |
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__": |
|
||||||
import time |
|
||||||
with Spinner() as s: |
|
||||||
s.update("Spinner text") |
|
||||||
time.sleep(5.0) |
|
||||||
print("gone") |
|
||||||
time.sleep(5.0) |
|
@ -1,63 +0,0 @@ |
|||||||
#!/usr/bin/env python3 |
|
||||||
import os |
|
||||||
import time |
|
||||||
import subprocess |
|
||||||
from openpilot.common.basedir import BASEDIR |
|
||||||
|
|
||||||
|
|
||||||
class TextWindow: |
|
||||||
def __init__(self, text): |
|
||||||
try: |
|
||||||
self.text_proc = subprocess.Popen(["./text.py", text], |
|
||||||
stdin=subprocess.PIPE, |
|
||||||
cwd=os.path.join(BASEDIR, "system", "ui"), |
|
||||||
close_fds=True) |
|
||||||
except OSError: |
|
||||||
self.text_proc = None |
|
||||||
|
|
||||||
def get_status(self): |
|
||||||
if self.text_proc is not None: |
|
||||||
self.text_proc.poll() |
|
||||||
return self.text_proc.returncode |
|
||||||
return None |
|
||||||
|
|
||||||
def __enter__(self): |
|
||||||
return self |
|
||||||
|
|
||||||
def close(self): |
|
||||||
if self.text_proc is not None: |
|
||||||
self.text_proc.terminate() |
|
||||||
self.text_proc = None |
|
||||||
|
|
||||||
def wait_for_exit(self): |
|
||||||
if self.text_proc is not None: |
|
||||||
while True: |
|
||||||
if self.get_status() == 1: |
|
||||||
return |
|
||||||
time.sleep(0.1) |
|
||||||
|
|
||||||
def __del__(self): |
|
||||||
self.close() |
|
||||||
|
|
||||||
def __exit__(self, exc_type, exc_value, traceback): |
|
||||||
self.close() |
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__": |
|
||||||
text = """Traceback (most recent call last): |
|
||||||
File "./controlsd.py", line 608, in <module> |
|
||||||
main() |
|
||||||
File "./controlsd.py", line 604, in main |
|
||||||
controlsd_thread(sm, pm, logcan) |
|
||||||
File "./controlsd.py", line 455, in controlsd_thread |
|
||||||
1/0 |
|
||||||
ZeroDivisionError: division by zero""" |
|
||||||
print(text) |
|
||||||
|
|
||||||
with TextWindow(text) as s: |
|
||||||
for _ in range(100): |
|
||||||
if s.get_status() == 1: |
|
||||||
print("Got exit button") |
|
||||||
break |
|
||||||
time.sleep(0.1) |
|
||||||
print("gone") |
|
Loading…
Reference in new issue