better text panel ux
This commit is contained in:
74
gui.py
74
gui.py
@@ -66,10 +66,20 @@ _NUM_COLOR = (180, 255, 180) # numbers / token counts
|
||||
_SUBHDR_COLOR = (220, 200, 120) # sub-section header
|
||||
|
||||
|
||||
|
||||
def _show_text_viewer(title: str, text: str):
|
||||
if dpg.does_item_exist("win_text_viewer"):
|
||||
dpg.set_value("text_viewer_content", text if text is not None else "")
|
||||
dpg.configure_item("win_text_viewer", label=f"Text Viewer - {title}", show=True)
|
||||
dpg.focus_item("win_text_viewer")
|
||||
|
||||
|
||||
def _add_text_field(parent: str, label: str, value: str):
|
||||
"""Render a labelled text value; long values get a scrollable box."""
|
||||
with dpg.group(horizontal=False, parent=parent):
|
||||
dpg.add_text(f"{label}:", color=_LABEL_COLOR)
|
||||
with dpg.group(horizontal=True):
|
||||
dpg.add_text(f"{label}:", color=_LABEL_COLOR)
|
||||
dpg.add_button(label="[+]", callback=lambda s, a, u: _show_text_viewer(label, u), user_data=value)
|
||||
if len(value) > COMMS_CLAMP_CHARS:
|
||||
dpg.add_input_text(
|
||||
default_value=value,
|
||||
@@ -250,7 +260,7 @@ class ConfirmDialog:
|
||||
def show(self):
|
||||
"""Called from main thread only. Wrapped in try/except to prevent thread lockups."""
|
||||
try:
|
||||
w, h = 700, 440
|
||||
w, h = 700, 480
|
||||
vp_w = dpg.get_viewport_width()
|
||||
vp_h = dpg.get_viewport_height()
|
||||
px = max(0, (vp_w - w) // 2)
|
||||
@@ -268,6 +278,13 @@ class ConfirmDialog:
|
||||
dpg.add_text("The AI wants to run the following PowerShell script:")
|
||||
dpg.add_text(f"base_dir: {self._base_dir}", color=(200, 200, 100))
|
||||
dpg.add_separator()
|
||||
with dpg.group(horizontal=True):
|
||||
dpg.add_text("Script:")
|
||||
dpg.add_button(
|
||||
label="[+ Maximize]",
|
||||
user_data=f"{self._tag}_script",
|
||||
callback=lambda s, a, u: _show_text_viewer("Confirm Script", dpg.get_value(u))
|
||||
)
|
||||
dpg.add_input_text(
|
||||
tag=f"{self._tag}_script",
|
||||
default_value=self._script,
|
||||
@@ -702,7 +719,18 @@ class App:
|
||||
for i, (script, result) in enumerate(self._tool_log, 1):
|
||||
with dpg.group(parent="tool_log_scroll"):
|
||||
first_line = script.strip().splitlines()[0][:80] if script.strip() else "(empty)"
|
||||
dpg.add_text(f"Call #{i}: {first_line}", color=(140, 200, 255))
|
||||
with dpg.group(horizontal=True):
|
||||
dpg.add_text(f"Call #{i}: {first_line}", color=(140, 200, 255))
|
||||
dpg.add_button(
|
||||
label="[+ Script]",
|
||||
user_data=script,
|
||||
callback=lambda s, a, u: _show_text_viewer(f"Call Script", u)
|
||||
)
|
||||
dpg.add_button(
|
||||
label="[+ Output]",
|
||||
user_data=result,
|
||||
callback=lambda s, a, u: _show_text_viewer(f"Call Output", u)
|
||||
)
|
||||
dpg.add_input_text(
|
||||
default_value=result,
|
||||
multiline=True,
|
||||
@@ -1738,21 +1766,33 @@ class App:
|
||||
label="Last Script Output",
|
||||
tag="win_script_output",
|
||||
show=False,
|
||||
width=700,
|
||||
height=500,
|
||||
width=800,
|
||||
height=600,
|
||||
pos=(100, 100),
|
||||
no_collapse=True
|
||||
):
|
||||
dpg.add_text("Script:")
|
||||
with dpg.group(horizontal=True):
|
||||
dpg.add_text("Script:")
|
||||
dpg.add_button(
|
||||
label="[+ Maximize]",
|
||||
user_data="last_script_text",
|
||||
callback=lambda s, a, u: _show_text_viewer("Last Script", dpg.get_value(u))
|
||||
)
|
||||
dpg.add_input_text(
|
||||
tag="last_script_text",
|
||||
multiline=True,
|
||||
readonly=True,
|
||||
width=-1,
|
||||
height=150,
|
||||
height=200,
|
||||
)
|
||||
dpg.add_separator()
|
||||
dpg.add_text("Output:")
|
||||
with dpg.group(horizontal=True):
|
||||
dpg.add_text("Output:")
|
||||
dpg.add_button(
|
||||
label="[+ Maximize]",
|
||||
user_data="last_script_output",
|
||||
callback=lambda s, a, u: _show_text_viewer("Last Output", dpg.get_value(u))
|
||||
)
|
||||
dpg.add_input_text(
|
||||
tag="last_script_output",
|
||||
multiline=True,
|
||||
@@ -1761,6 +1801,24 @@ class App:
|
||||
height=-1,
|
||||
)
|
||||
|
||||
# ---- Global Text Viewer Popup ----
|
||||
with dpg.window(
|
||||
label="Text Viewer",
|
||||
tag="win_text_viewer",
|
||||
show=False,
|
||||
width=900,
|
||||
height=700,
|
||||
pos=(150, 150),
|
||||
no_collapse=True
|
||||
):
|
||||
dpg.add_input_text(
|
||||
tag="text_viewer_content",
|
||||
multiline=True,
|
||||
readonly=True,
|
||||
width=-1,
|
||||
height=-1,
|
||||
)
|
||||
|
||||
def run(self):
|
||||
dpg.create_context()
|
||||
dpg.configure_app(docking=True, docking_space=True, init_file="dpg_layout.ini")
|
||||
|
||||
Reference in New Issue
Block a user