git.lucas.co / cce-designer
graphic design tool
git clone https://git.lucas.co/cce-designer.git

scratch/test_circular_menu.py (3.6K)

  1 import subprocess
  2 import time
  3 import re
  4 import sys
  5 import os
  6 import math
  7 
  8 def run_clearctl(cmd_str):
  9     full_cmd = f"env WAYLAND_DISPLAY=wayland-0 XDG_RUNTIME_DIR=/run/user/1000 /home/lsgalante/.local/bin/clearctl {cmd_str}"
 10     res = subprocess.run(full_cmd, shell=True, capture_output=True, text=True)
 11     return res.stdout.strip()
 12 
 13 def get_window_rect(title):
 14     stdout = run_clearctl("windows")
 15     for line in stdout.splitlines():
 16         if title in line:
 17             m = re.search(r'\bx=(\d+)\s+y=(\d+)\s+w=(\d+)\s+h=(\d+)', line)
 18             if m:
 19                 return int(m.group(1)), int(m.group(2)), int(m.group(3)), int(m.group(4))
 20     return None
 21 
 22 def reset_pointer(window_x, window_y, window_w, window_h):
 23     cx = window_x + window_w // 2
 24     cy = window_y + window_h // 2
 25     print(f"Focusing window at ({cx}, {cy})...")
 26     run_clearctl(f"pointer-move-to {cx} {cy}")
 27     time.sleep(0.2)
 28     run_clearctl("pointer-click left")
 29     time.sleep(0.3)
 30     run_clearctl("key-press Escape")
 31     time.sleep(0.05)
 32     run_clearctl("key-release Escape")
 33     time.sleep(0.2)
 34 
 35 def get_curved_circle_params():
 36     debug_path = "/home/lsgalante/Dropbox/Clear/debug.txt"
 37     if not os.path.exists(debug_path):
 38         return None
 39     with open(debug_path, "r") as f:
 40         lines = f.readlines()
 41     for line in reversed(lines):
 42         # Match curved=Some((298.9297, 279.10547, 180.0))
 43         m = re.search(r'curved=Some\(\(([\d\.-]+),\s*([\d\.-]+),\s*([\d\.-]+)\)\)', line)
 44         if m:
 45             return float(m.group(1)), float(m.group(2)), float(m.group(3))
 46     return None
 47 
 48 title = "Clear Design Interface"
 49 rect = get_window_rect(title)
 50 if not rect:
 51     print(f"Error: Could not find window '{title}'", file=sys.stderr)
 52     sys.exit(1)
 53 
 54 window_x, window_y, window_w, window_h = rect
 55 print(f"Found window '{title}' at x={window_x}, y={window_y}, w={window_w}, h={window_h}")
 56 
 57 reset_pointer(window_x, window_y, window_w, window_h)
 58 
 59 circle_params = get_curved_circle_params()
 60 if not circle_params:
 61     print("Error: Could not read curved circle parameters from debug.txt. Using defaults.", file=sys.stderr)
 62     circle_params = (298.9297, 279.10547, 180.0)
 63 
 64 cx, cy, r = circle_params
 65 print(f"Curved circle center from debug.txt: cx={cx}, cy={cy}, r={r}")
 66 
 67 # View menu midpoint angle:
 68 theta = (5.1339273 + 5.417004) / 2.0
 69 r_mid = r - 17.5
 70 
 71 local_x = cx + r_mid * math.cos(theta)
 72 local_y = cy + r_mid * math.sin(theta)
 73 
 74 border_offset_x = 0
 75 border_offset_y = 0
 76 
 77 scale = 2.0
 78 screen_x = int(window_x + border_offset_x + local_x * scale)
 79 screen_y = int(window_y + border_offset_y + local_y * scale)
 80 
 81 print(f"Targeting client local ({local_x:.2f}, {local_y:.2f}) -> screen ({screen_x}, {screen_y})")
 82 
 83 log_path = "/home/lsgalante/Dropbox/Clear/design-interface.log"
 84 initial_size = 0
 85 if os.path.exists(log_path):
 86     initial_size = os.path.getsize(log_path)
 87 
 88 print(f"Moving pointer to ({screen_x}, {screen_y})...")
 89 print("Move result:", run_clearctl(f"pointer-move-to {screen_x} {screen_y}"))
 90 time.sleep(0.5)
 91 
 92 print("Clicking left...")
 93 print("Click result:", run_clearctl("pointer-click left"))
 94 time.sleep(1.0)
 95 
 96 # Check design-interface.log for new DEBUG output
 97 new_logs = ""
 98 if os.path.exists(log_path):
 99     with open(log_path, "r", errors="ignore") as f:
100         f.seek(initial_size)
101         new_logs = f.read()
102 
103 print("--- New Application Logs ---")
104 print(new_logs)
105 print("----------------------------")
106 
107 screenshot_path = "/home/lsgalante/.gemini/antigravity/brain/9048aec8-21a4-458f-94d4-efe127095c7f/screenshot_circular_view_dropdown.png"
108 print(f"Taking screenshot: {screenshot_path}")
109 subprocess.run(f"env WAYLAND_DISPLAY=wayland-0 XDG_RUNTIME_DIR=/run/user/1000 grim {screenshot_path}", shell=True)
110 print("Done.")