refactor(gui): Implement user feedback for UI layout
This commit is contained in:
128
refactor_gui2_v2.py
Normal file
128
refactor_gui2_v2.py
Normal file
@@ -0,0 +1,128 @@
|
||||
import re
|
||||
import sys
|
||||
|
||||
def main():
|
||||
with open("gui_2.py", "r", encoding="utf-8") as f:
|
||||
content = f.read()
|
||||
|
||||
# Define the new structure for the GUI function
|
||||
new_gui_func_body = """
|
||||
# --- Hubs ---
|
||||
if self.show_windows.get("Context Hub", False):
|
||||
exp, self.show_windows["Context Hub"] = imgui.begin("Context Hub", self.show_windows["Context Hub"])
|
||||
if exp:
|
||||
self._render_projects_panel()
|
||||
imgui.end()
|
||||
|
||||
if self.show_windows.get("Files & Media", False):
|
||||
exp, self.show_windows["Files & Media"] = imgui.begin("Files & Media", self.show_windows["Files & Media"])
|
||||
if exp:
|
||||
if imgui.collapsing_header("Files"):
|
||||
self._render_files_panel()
|
||||
if imgui.collapsing_header("Screenshots"):
|
||||
self._render_screenshots_panel()
|
||||
imgui.end()
|
||||
|
||||
if self.show_windows.get("AI Settings", False):
|
||||
exp, self.show_windows["AI Settings"] = imgui.begin("AI Settings", self.show_windows["AI Settings"])
|
||||
if exp:
|
||||
if imgui.collapsing_header("Provider & Model"):
|
||||
self._render_provider_panel()
|
||||
if imgui.collapsing_header("System Prompts"):
|
||||
self._render_system_prompts_panel()
|
||||
imgui.end()
|
||||
|
||||
if self.show_windows.get("Theme", False):
|
||||
self._render_theme_panel()
|
||||
|
||||
if self.show_windows.get("Discussion Hub", False):
|
||||
exp, self.show_windows["Discussion Hub"] = imgui.begin("Discussion Hub", self.show_windows["Discussion Hub"])
|
||||
if exp:
|
||||
# Top part for the history
|
||||
with imgui.begin_child("HistoryChild", size=(0, -200)):
|
||||
self._render_discussion_panel()
|
||||
|
||||
# Bottom part with tabs for message and response
|
||||
if imgui.begin_tab_bar("MessageResponseTabs"):
|
||||
if imgui.begin_tab_item("Message")[0]:
|
||||
self._render_message_panel()
|
||||
imgui.end_tab_item()
|
||||
if imgui.begin_tab_item("Response")[0]:
|
||||
self._render_response_panel()
|
||||
imgui.end_tab_item()
|
||||
imgui.end_tab_bar()
|
||||
imgui.end()
|
||||
|
||||
if self.show_windows.get("Operations Hub", False):
|
||||
exp, self.show_windows["Operations Hub"] = imgui.begin("Operations Hub", self.show_windows["Operations Hub"])
|
||||
if exp:
|
||||
if imgui.begin_tab_bar("OperationsTabs"):
|
||||
if imgui.begin_tab_item("Tool Calls")[0]:
|
||||
self._render_tool_calls_panel()
|
||||
imgui.end_tab_item()
|
||||
if imgui.begin_tab_item("Comms History")[0]:
|
||||
self._render_comms_history_panel()
|
||||
imgui.end_tab_item()
|
||||
imgui.end_tab_bar()
|
||||
imgui.end()
|
||||
"""
|
||||
|
||||
# Replace the old hub code with the new one
|
||||
start_marker = "# ---- Context Hub"
|
||||
end_marker = "# ---- Diagnostics"
|
||||
|
||||
start_idx = content.find(start_marker)
|
||||
end_idx = content.find(end_marker)
|
||||
|
||||
if start_idx != -1 and end_idx != -1:
|
||||
indented_new_code = "\\n".join([f" {line}" for line in new_gui_func_body.split("\\n")])
|
||||
content = content[:start_idx] + indented_new_code + content[end_idx:]
|
||||
else:
|
||||
print("Could not find the hub markers to replace.")
|
||||
sys.exit(1)
|
||||
|
||||
# Update the _default_windows dictionary to reflect the new layout
|
||||
old_default = """ _default_windows = {
|
||||
"Context Hub": True,
|
||||
"AI Settings Hub": True,
|
||||
"Discussion Hub": True,
|
||||
"Operations Hub": True,
|
||||
"Diagnostics": False,
|
||||
}"""
|
||||
new_default = """ _default_windows = {
|
||||
"Context Hub": True,
|
||||
"Files & Media": True,
|
||||
"AI Settings": True,
|
||||
"Discussion Hub": True,
|
||||
"Operations Hub": True,
|
||||
"Theme": True,
|
||||
"Diagnostics": False,
|
||||
}"""
|
||||
content = content.replace(old_default, new_default)
|
||||
|
||||
theme_method_start = "def _render_theme_panel(self):"
|
||||
theme_method_end_line = "theme.set_scale(scale)"
|
||||
|
||||
theme_start_idx = content.find(theme_method_start)
|
||||
if theme_start_idx != -1:
|
||||
theme_end_idx = content.find(theme_method_end_line, theme_start_idx)
|
||||
if theme_end_idx != -1:
|
||||
theme_end_idx += len(theme_method_end_line)
|
||||
body = content[theme_start_idx + len(theme_method_start) : theme_end_idx]
|
||||
|
||||
new_theme_method = """ def _render_theme_panel(self):
|
||||
exp, self.show_windows["Theme"] = imgui.begin("Theme", self.show_windows["Theme"])
|
||||
if exp:
|
||||
{}
|
||||
imgui.end()
|
||||
""".format(body)
|
||||
old_method_text = content[theme_start_idx : theme_end_idx+1]
|
||||
content = content.replace(old_method_text, new_theme_method)
|
||||
|
||||
with open("gui_2.py", "w", encoding="utf-8") as f:
|
||||
f.write(content)
|
||||
|
||||
print("GUI refactoring V2 complete.")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user