mirror of
https://github.com/infiniteCable2/openpilot.git
synced 2026-10-01 03:53:41 +08:00
ui: switch spinner and text window back to standalone process (#35470)
switch spinner and text window back to standalone process
This commit is contained in:
+7
-19
@@ -1,13 +1,12 @@
|
||||
#!/usr/bin/env python3
|
||||
import re
|
||||
import time
|
||||
import sys
|
||||
import pyray as rl
|
||||
from openpilot.system.hardware import HARDWARE, PC
|
||||
from openpilot.system.ui.lib.text_measure import measure_text_cached
|
||||
from openpilot.system.ui.lib.button import gui_button, ButtonStyle
|
||||
from openpilot.system.ui.lib.scroll_panel import GuiScrollPanel
|
||||
from openpilot.system.ui.lib.application import gui_app
|
||||
from openpilot.system.ui.lib.window import BaseWindow
|
||||
|
||||
MARGIN = 50
|
||||
SPACING = 40
|
||||
@@ -46,7 +45,7 @@ def wrap_text(text, font_size, max_width):
|
||||
return lines
|
||||
|
||||
|
||||
class TextWindowRenderer:
|
||||
class TextWindow:
|
||||
def __init__(self, text: str):
|
||||
self._textarea_rect = rl.Rectangle(MARGIN, MARGIN, gui_app.width - MARGIN * 2, gui_app.height - MARGIN * 2)
|
||||
self._wrapped_lines = wrap_text(text, FONT_SIZE, self._textarea_rect.width - 20)
|
||||
@@ -73,20 +72,9 @@ class TextWindowRenderer:
|
||||
HARDWARE.reboot()
|
||||
return ret
|
||||
|
||||
|
||||
class TextWindow(BaseWindow[TextWindowRenderer]):
|
||||
def __init__(self, text: str):
|
||||
self._text = text
|
||||
super().__init__("Text")
|
||||
|
||||
def _create_renderer(self):
|
||||
return TextWindowRenderer(self._text)
|
||||
|
||||
def wait_for_exit(self):
|
||||
while self._thread.is_alive():
|
||||
time.sleep(0.01)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
with TextWindow(DEMO_TEXT):
|
||||
time.sleep(30)
|
||||
text = sys.argv[1] if len(sys.argv) > 1 else DEMO_TEXT
|
||||
gui_app.init_window("Text Viewer")
|
||||
text_window = TextWindow(text)
|
||||
for _ in gui_app.render():
|
||||
text_window.render()
|
||||
|
||||
Reference in New Issue
Block a user