ok
This commit is contained in:
47
scripts/patch_selectable_metrics.py
Normal file
47
scripts/patch_selectable_metrics.py
Normal file
@@ -0,0 +1,47 @@
|
||||
|
||||
import sys
|
||||
import re
|
||||
|
||||
def patch_gui(file_path):
|
||||
with open(file_path, 'r', encoding='utf-8', newline='') as f:
|
||||
content = f.read()
|
||||
|
||||
# 1. Patch _render_provider_panel Session ID
|
||||
content = content.replace(
|
||||
' imgui.text(f"Session ID: {sid}")',
|
||||
' imgui.text("Session ID:"); imgui.same_line(); self._render_selectable_label("gemini_cli_sid", sid, width=200)'
|
||||
)
|
||||
|
||||
# 2. Patch _render_token_budget_panel Session Telemetry
|
||||
content = content.replace(
|
||||
' imgui.text_colored(C_RES, f"Tokens: {total:,} (In: {usage[\'input_tokens\']:,} Out: {usage[\'output_tokens\']:,})")',
|
||||
' self._render_selectable_label("session_telemetry_tokens", f"Tokens: {total:,} (In: {usage[\'input_tokens\']:,} Out: {usage[\'output_tokens\']:,})", width=-1, color=C_RES)'
|
||||
)
|
||||
|
||||
# 3. Patch _render_token_budget_panel MMA Tier Costs table
|
||||
# This is trickier, let's find the loop
|
||||
tier_table_pattern = re.compile(
|
||||
r'(for tier, stats in self\.mma_tier_usage\.items\(\):\s+.*?imgui\.table_set_column_index\(0\); )imgui\.text\(tier\)(\s+imgui\.table_set_column_index\(1\); )imgui\.text\(model\.split\(\'-\'\)\[0\]\)(\s+imgui\.table_set_column_index\(2\); )imgui\.text\(f"\{tokens:,\}"\)(\s+imgui\.table_set_column_index\(3\); )imgui\.text_colored\(imgui\.ImVec4\(0\.2, 0\.9, 0\.2, 1\), f"\$\{cost:\.4f\}"\)',
|
||||
re.DOTALL
|
||||
)
|
||||
|
||||
def tier_replacement(match):
|
||||
return (match.group(1) + 'self._render_selectable_label(f"tier_{tier}", tier, width=-1)' +
|
||||
match.group(2) + 'self._render_selectable_label(f"model_{tier}", model.split("-")[0], width=-1)' +
|
||||
match.group(3) + 'self._render_selectable_label(f"tokens_{tier}", f"{tokens:,}", width=-1)' +
|
||||
match.group(4) + 'self._render_selectable_label(f"cost_{tier}", f"${cost:.4f}", width=-1, color=imgui.ImVec4(0.2, 0.9, 0.2, 1))')
|
||||
|
||||
content = tier_table_pattern.sub(tier_replacement, content)
|
||||
|
||||
# 4. Patch _render_token_budget_panel Session Total
|
||||
content = content.replace(
|
||||
' imgui.text_colored(imgui.ImVec4(0, 1, 0, 1), f"Session Total: ${tier_total:.4f}")',
|
||||
' self._render_selectable_label("session_total_cost", f"Session Total: ${tier_total:.4f}", width=-1, color=imgui.ImVec4(0, 1, 0, 1))'
|
||||
)
|
||||
|
||||
with open(file_path, 'w', encoding='utf-8', newline='') as f:
|
||||
f.write(content)
|
||||
print("Successfully patched src/gui_2.py for selectable metrics")
|
||||
|
||||
if __name__ == "__main__":
|
||||
patch_gui("src/gui_2.py")
|
||||
@@ -13,9 +13,27 @@ try:
|
||||
with urllib.request.urlopen(req) as response:
|
||||
with zipfile.ZipFile(io.BytesIO(response.read())) as z:
|
||||
for info in z.infolist():
|
||||
if info.filename.endswith("Inter-Regular.ttf") or info.filename.endswith("Inter-Bold.ttf"):
|
||||
info.filename = os.path.basename(info.filename)
|
||||
targets = ["Inter-Regular.ttf", "Inter-Bold.ttf", "Inter-Italic.ttf", "Inter-BoldItalic.ttf"]
|
||||
filename = os.path.basename(info.filename)
|
||||
if filename in targets:
|
||||
info.filename = filename
|
||||
z.extract(info, "assets/fonts/")
|
||||
print(f"Extracted {info.filename}")
|
||||
except Exception as e:
|
||||
print(f"Failed to get Inter: {e}")
|
||||
|
||||
maple_url = "https://github.com/subframe7536/maple-font/releases/download/v6.4/MapleMono-ttf.zip"
|
||||
print(f"Downloading Maple Mono from {maple_url}")
|
||||
try:
|
||||
req = urllib.request.Request(maple_url, headers={'User-Agent': 'Mozilla/5.0'})
|
||||
with urllib.request.urlopen(req) as response:
|
||||
with zipfile.ZipFile(io.BytesIO(response.read())) as z:
|
||||
for info in z.infolist():
|
||||
targets = ["MapleMono-Regular.ttf", "MapleMono-Bold.ttf", "MapleMono-Italic.ttf", "MapleMono-BoldItalic.ttf"]
|
||||
filename = os.path.basename(info.filename)
|
||||
if filename in targets:
|
||||
info.filename = filename
|
||||
z.extract(info, "assets/fonts/")
|
||||
print(f"Extracted {info.filename}")
|
||||
except Exception as e:
|
||||
print(f"Failed to get Maple Mono: {e}")
|
||||
|
||||
35
scripts/tasks/test_link.py
Normal file
35
scripts/tasks/test_link.py
Normal file
@@ -0,0 +1,35 @@
|
||||
import os
|
||||
import subprocess
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
|
||||
def test_link():
|
||||
project_root = Path(os.getcwd())
|
||||
temp_workspace = project_root / "tests" / "artifacts" / "test_link_workspace"
|
||||
if temp_workspace.exists():
|
||||
shutil.rmtree(temp_workspace)
|
||||
temp_workspace.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
src_assets = project_root / "assets"
|
||||
dest_assets = temp_workspace / "assets"
|
||||
|
||||
print(f"Linking {src_assets} to {dest_assets}")
|
||||
if os.name == 'nt':
|
||||
res = subprocess.run(["cmd", "/c", "mklink", "/D", str(dest_assets), str(src_assets)], capture_output=True, text=True)
|
||||
print(f"Exit code: {res.returncode}")
|
||||
print(f"Stdout: {res.stdout}")
|
||||
print(f"Stderr: {res.stderr}")
|
||||
else:
|
||||
os.symlink(src_assets, dest_assets)
|
||||
|
||||
if dest_assets.exists():
|
||||
print("Link exists")
|
||||
if (dest_assets / "fonts" / "Inter-Regular.ttf").exists():
|
||||
print("Font file accessible via link")
|
||||
else:
|
||||
print("Font file NOT accessible")
|
||||
else:
|
||||
print("Link does NOT exist")
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_link()
|
||||
40
scripts/tasks/test_markdown.py
Normal file
40
scripts/tasks/test_markdown.py
Normal file
@@ -0,0 +1,40 @@
|
||||
from imgui_bundle import imgui, immapp, imgui_md
|
||||
import sys
|
||||
|
||||
def gui():
|
||||
imgui.text("Markdown Test")
|
||||
imgui.separator()
|
||||
|
||||
md = """
|
||||
# Header 1
|
||||
## Header 2
|
||||
This is **bold** and *italic*.
|
||||
|
||||
* List item 1
|
||||
* List list 2
|
||||
|
||||
[Google](https://google.com)
|
||||
|
||||
```python
|
||||
def hello():
|
||||
print("world")
|
||||
```
|
||||
|
||||
<div class="test-div">This is inside a div</div>
|
||||
"""
|
||||
imgui_md.render(md)
|
||||
|
||||
def on_html_div(div_class: str, opening: bool):
|
||||
print(f"HTML DIV: class={div_class}, opening={opening}")
|
||||
if opening:
|
||||
imgui.push_style_color(imgui.Col_.text.value, imgui.ImColor(255, 0, 0, 255).value)
|
||||
else:
|
||||
imgui.pop_style_color()
|
||||
|
||||
def main():
|
||||
options = imgui_md.MarkdownOptions()
|
||||
options.callbacks.on_html_div = on_html_div
|
||||
immapp.run(gui, with_markdown_options=options, window_size=(600, 600))
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user