wip better word wrap ux
This commit is contained in:
39
gui.py
39
gui.py
@@ -67,9 +67,9 @@ _SUBHDR_COLOR = (220, 200, 120) # sub-section header
|
||||
|
||||
|
||||
|
||||
def _show_text_viewer(title: str, text: str, app_instance=None):
|
||||
def _show_text_viewer(title: str, text: str):
|
||||
if dpg.does_item_exist("win_text_viewer"):
|
||||
wrap = app_instance.project.get("project", {}).get("word_wrap", False) if app_instance else False
|
||||
wrap = dpg.get_value("project_word_wrap") if dpg.does_item_exist("project_word_wrap") else False
|
||||
dpg.configure_item("win_text_viewer", label=f"Text Viewer - {title}", show=True)
|
||||
if dpg.does_item_exist("text_viewer_content"):
|
||||
dpg.set_value("text_viewer_content", text if text is not None else "")
|
||||
@@ -86,7 +86,7 @@ def _add_text_field(parent: str, label: str, value: str):
|
||||
with dpg.group(horizontal=False, parent=parent):
|
||||
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, app_instance=self), user_data=value)
|
||||
dpg.add_button(label="[+]", callback=lambda s, a, u: _show_text_viewer(label, u), user_data=value)
|
||||
if len(value) > COMMS_CLAMP_CHARS:
|
||||
if wrap:
|
||||
with dpg.child_window(height=80, border=True):
|
||||
@@ -294,7 +294,7 @@ class ConfirmDialog:
|
||||
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, app_instance=self))
|
||||
callback=lambda s, a, u: _show_text_viewer("Confirm Script", dpg.get_value(u))
|
||||
)
|
||||
dpg.add_input_text(
|
||||
tag=f"{self._tag}_script",
|
||||
@@ -745,12 +745,12 @@ class App:
|
||||
dpg.add_button(
|
||||
label="[+ Script]",
|
||||
user_data=script,
|
||||
callback=lambda s, a, u: _show_text_viewer(f"Call Script", u, app_instance=self)
|
||||
callback=lambda s, a, u: _show_text_viewer("Call Script", u)
|
||||
)
|
||||
dpg.add_button(
|
||||
label="[+ Output]",
|
||||
user_data=result,
|
||||
callback=lambda s, a, u: _show_text_viewer(f"Call Output", u, app_instance=self)
|
||||
callback=lambda s, a, u: _show_text_viewer("Call Output", u)
|
||||
)
|
||||
if wrap:
|
||||
with dpg.child_window(height=72, border=True):
|
||||
@@ -988,7 +988,7 @@ class App:
|
||||
|
||||
# ---------------------------------------------------------------- callbacks
|
||||
|
||||
def cb_word_wrap_toggled(self, sender=None, app_data=None):
|
||||
def cb_word_wrap_toggled(self, sender=None, app_data=None):
|
||||
# This function is now also called by _refresh_project_widgets to set initial state
|
||||
if app_data is None:
|
||||
wrap = dpg.get_value("project_word_wrap") if dpg.does_item_exist("project_word_wrap") else False
|
||||
@@ -1352,9 +1352,6 @@ class App:
|
||||
dpg.delete_item("disc_scroll", children_only=True)
|
||||
for i, entry in enumerate(self.disc_entries):
|
||||
collapsed = entry.get("collapsed", False)
|
||||
preview = entry["content"].replace("\n", " ")[:60]
|
||||
if len(entry["content"]) > 60:
|
||||
preview += "..."
|
||||
ts_str = entry.get("ts", "")
|
||||
|
||||
with dpg.group(parent="disc_scroll"):
|
||||
@@ -1382,21 +1379,20 @@ class App:
|
||||
)
|
||||
dpg.add_button(
|
||||
label="[+ Max]",
|
||||
user_data=f"disc_content_{{i}}",
|
||||
callback=lambda s, a, u, idx=i: _show_text_viewer(f"Entry #{{idx+1}}", dpg.get_value(u, app_instance=self) if dpg.does_item_exist(u) else "", app_instance=self)
|
||||
)
|
||||
dpg.add_button(
|
||||
label="Del",
|
||||
width=36,
|
||||
callback=self._make_disc_insert_cb(i),
|
||||
user_data=f"disc_content_{i}",
|
||||
callback=lambda s, a, u, idx=i: _show_text_viewer(f"Entry #{idx+1}", dpg.get_value(u) if dpg.does_item_exist(u) else "")
|
||||
)
|
||||
dpg.add_button(
|
||||
label="Del",
|
||||
width=36,
|
||||
callback=self._make_disc_remove_cb(i),
|
||||
)
|
||||
dpg.add_text(preview, color=(160, 160, 150))
|
||||
else:
|
||||
|
||||
if collapsed:
|
||||
with dpg.group(horizontal=True):
|
||||
dpg.add_spacer(width=28) # Indent text past the expand/collapse button
|
||||
dpg.add_text(entry["content"], wrap=0, color=(200, 200, 200))
|
||||
|
||||
with dpg.group(tag=f"disc_body_{i}", show=not collapsed):
|
||||
dpg.add_input_text(
|
||||
tag=f"disc_content_{i}",
|
||||
@@ -1850,7 +1846,7 @@ class App:
|
||||
dpg.add_button(
|
||||
label="[+ Maximize]",
|
||||
user_data="last_script_text",
|
||||
callback=lambda s, a, u: _show_text_viewer("Last Script", dpg.get_value(u, app_instance=self))
|
||||
callback=lambda s, a, u: _show_text_viewer("Last Script", dpg.get_value(u))
|
||||
)
|
||||
dpg.add_input_text(
|
||||
tag="last_script_text",
|
||||
@@ -1867,7 +1863,7 @@ class App:
|
||||
dpg.add_button(
|
||||
label="[+ Maximize]",
|
||||
user_data="last_script_output",
|
||||
callback=lambda s, a, u: _show_text_viewer("Last Output", dpg.get_value(u, app_instance=self))
|
||||
callback=lambda s, a, u: _show_text_viewer("Last Output", dpg.get_value(u))
|
||||
)
|
||||
dpg.add_input_text(
|
||||
tag="last_script_output",
|
||||
@@ -2051,4 +2047,3 @@ def main():
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user