|
|
import tkinter as tk
|
|
|
from tkinter import messagebox
|
|
|
from PIL import ImageTk, Image
|
|
|
import logging
|
|
|
import json
|
|
|
import os
|
|
|
from appearance import appearance_manager
|
|
|
from settings import Settings
|
|
|
|
|
|
|
|
|
import win32gui
|
|
|
import win32con
|
|
|
import win32api
|
|
|
from ctypes import windll, byref, sizeof, c_int
|
|
|
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
|
|
print("Loading control_ui.py")
|
|
|
|
|
|
|
|
|
class Control_UI:
|
|
|
def __init__(self, root, force_translate, switch_area, settings):
|
|
|
self.root = root
|
|
|
self.force_translate = force_translate
|
|
|
self.switch_area_callback = switch_area
|
|
|
self.settings = settings
|
|
|
|
|
|
|
|
|
self.x = None
|
|
|
self.y = None
|
|
|
|
|
|
|
|
|
self.current_preset = 1
|
|
|
self.max_presets = 5
|
|
|
self.presets = self.load_presets()
|
|
|
|
|
|
|
|
|
self.area_states = {"A": True, "B": False, "C": False}
|
|
|
|
|
|
|
|
|
self.load_current_area_states()
|
|
|
|
|
|
|
|
|
self.ui_cache = {
|
|
|
"position_x": None,
|
|
|
"position_y": None,
|
|
|
"current_area": self.get_current_area_string(),
|
|
|
}
|
|
|
|
|
|
self.setup_window()
|
|
|
self.setup_buttons()
|
|
|
self.setup_bindings()
|
|
|
self.load_current_preset()
|
|
|
|
|
|
|
|
|
self.root.update_idletasks()
|
|
|
|
|
|
|
|
|
hwnd = windll.user32.GetParent(self.root.winfo_id())
|
|
|
style = win32gui.GetWindowLong(hwnd, win32con.GWL_STYLE)
|
|
|
style &= ~win32con.WS_CAPTION
|
|
|
style &= ~win32con.WS_THICKFRAME
|
|
|
win32gui.SetWindowLong(hwnd, win32con.GWL_STYLE, style)
|
|
|
|
|
|
rgnw = self.root.winfo_width()
|
|
|
rgnh = self.root.winfo_height()
|
|
|
region = win32gui.CreateRoundRectRgn(0, 0, rgnw, rgnh, 15, 15)
|
|
|
win32gui.SetWindowRgn(hwnd, region, True)
|
|
|
|
|
|
|
|
|
self.update_button_highlights()
|
|
|
|
|
|
|
|
|
self.has_unsaved_changes = False
|
|
|
self.pending_preset = None
|
|
|
|
|
|
def setup_window(self):
|
|
|
"""ตั้งค่าหน้าต่าง UI"""
|
|
|
self.root.title("Control Panel")
|
|
|
self.root.geometry("240x200")
|
|
|
self.root.overrideredirect(True)
|
|
|
self.root.attributes("-alpha", 0.95)
|
|
|
self.root.attributes("-topmost", True)
|
|
|
|
|
|
self.main_frame = tk.Frame(
|
|
|
self.root,
|
|
|
bg="#1a1a1a",
|
|
|
highlightthickness=0,
|
|
|
highlightbackground="#1a1a1a",
|
|
|
)
|
|
|
self.main_frame.pack(fill=tk.BOTH, expand=True, padx=0, pady=0)
|
|
|
|
|
|
self.position_below_main_ui()
|
|
|
|
|
|
def load_presets(self):
|
|
|
"""โหลด presets จาก settings"""
|
|
|
presets = self.settings.get("area_presets", None)
|
|
|
if not presets:
|
|
|
|
|
|
presets = [
|
|
|
{"name": f"Preset {i+1}", "areas": "A+B" if i == 0 else "C"}
|
|
|
for i in range(self.max_presets)
|
|
|
]
|
|
|
self.settings.set("area_presets", presets)
|
|
|
return presets
|
|
|
|
|
|
def save_preset(self):
|
|
|
"""บันทึก preset ปัจจุบันพร้อมพิกัด"""
|
|
|
current_areas = self.get_current_area_string()
|
|
|
|
|
|
|
|
|
coordinates = {}
|
|
|
for area in current_areas.split("+"):
|
|
|
area_coords = self.settings.get_translate_area(area)
|
|
|
if area_coords:
|
|
|
coordinates[area] = area_coords
|
|
|
|
|
|
|
|
|
self.settings.save_preset(self.current_preset, current_areas, coordinates)
|
|
|
self.has_unsaved_changes = False
|
|
|
self.show_save_feedback()
|
|
|
|
|
|
def load_current_preset(self):
|
|
|
"""โหลด preset พร้อมพิกัด"""
|
|
|
if self.current_preset <= len(self.presets):
|
|
|
preset = self.presets[self.current_preset - 1]
|
|
|
|
|
|
|
|
|
areas = preset["areas"].split("+")
|
|
|
for area in ["A", "B", "C"]:
|
|
|
self.area_states[area] = area in areas
|
|
|
|
|
|
|
|
|
if "coordinates" in preset:
|
|
|
for area, coords in preset["coordinates"].items():
|
|
|
self.settings.set_translate_area(
|
|
|
coords["start_x"],
|
|
|
coords["start_y"],
|
|
|
coords["end_x"],
|
|
|
coords["end_y"],
|
|
|
area,
|
|
|
)
|
|
|
|
|
|
self.update_button_highlights()
|
|
|
self.update_preset_display()
|
|
|
|
|
|
def update_preset_display(self):
|
|
|
"""อัพเดทการแสดงผลหมายเลข preset"""
|
|
|
if hasattr(self, "preset_label"):
|
|
|
self.preset_label.config(text=f"P{self.current_preset}")
|
|
|
|
|
|
def show_save_feedback(self):
|
|
|
"""แสดงข้อความ feedback เมื่อบันทึก preset"""
|
|
|
feedback = tk.Toplevel(self.root)
|
|
|
feedback.overrideredirect(True)
|
|
|
feedback.configure(bg="black")
|
|
|
x = self.root.winfo_x() + self.save_button.winfo_x()
|
|
|
y = self.root.winfo_y() + self.save_button.winfo_y()
|
|
|
tk.Label(
|
|
|
feedback,
|
|
|
text=f"Saved to P{self.current_preset}!",
|
|
|
fg="lime",
|
|
|
bg="black",
|
|
|
font=("Nasalization Rg", 8),
|
|
|
).pack(padx=10, pady=5)
|
|
|
feedback.geometry(f"+{x+30}+{y}")
|
|
|
feedback.after(1000, feedback.destroy)
|
|
|
|
|
|
def create_button(self, parent, command, **kwargs):
|
|
|
"""สร้างปุ่มที่มี style ตามที่กำหนด"""
|
|
|
base_config = {
|
|
|
"bg": "#1a1a1a",
|
|
|
"fg": "#AAAAAA",
|
|
|
"activebackground": "#1a1a1a",
|
|
|
"activeforeground": "#FFFFFF",
|
|
|
"bd": 0,
|
|
|
"relief": "flat",
|
|
|
"highlightthickness": 0,
|
|
|
"borderwidth": 0,
|
|
|
"command": command,
|
|
|
}
|
|
|
|
|
|
base_config.update(kwargs)
|
|
|
button = tk.Button(parent, **base_config)
|
|
|
button.selected = False
|
|
|
|
|
|
def on_enter(e):
|
|
|
if not button.selected:
|
|
|
button.configure(fg="#FFFFFF")
|
|
|
|
|
|
def on_leave(e):
|
|
|
if not button.selected:
|
|
|
button.configure(fg="#AAAAAA")
|
|
|
else:
|
|
|
button.configure(fg="#00FFFF")
|
|
|
|
|
|
button.bind("<Enter>", on_enter)
|
|
|
button.bind("<Leave>", on_leave)
|
|
|
return button
|
|
|
|
|
|
def setup_buttons(self):
|
|
|
"""Initialize and setup all control buttons"""
|
|
|
|
|
|
left_frame = tk.Frame(self.main_frame, bg="#1a1a1a")
|
|
|
left_frame.place(x=25, y=20)
|
|
|
|
|
|
|
|
|
top_row = tk.Frame(left_frame, bg="#1a1a1a")
|
|
|
top_row.pack(pady=(0, 15))
|
|
|
|
|
|
|
|
|
camera_image = ImageTk.PhotoImage(Image.open("camera.png").resize((24, 24)))
|
|
|
self.camera_button = self.create_button(
|
|
|
top_row, command=self.capture_screen, image=camera_image
|
|
|
)
|
|
|
self.camera_button.image = camera_image
|
|
|
self.camera_button.pack(side=tk.LEFT, padx=(0, 15))
|
|
|
|
|
|
|
|
|
area_frame = tk.Frame(top_row, bg="#1a1a1a")
|
|
|
area_frame.pack(side=tk.LEFT)
|
|
|
|
|
|
|
|
|
button_style = {
|
|
|
"font": ("Nasalization Rg", 12),
|
|
|
"bg": "#1a1a1a",
|
|
|
}
|
|
|
|
|
|
|
|
|
for area, text in [("A", "[A]"), ("B", "[B]"), ("C", "[C]")]:
|
|
|
button = self.create_button(
|
|
|
area_frame,
|
|
|
command=lambda a=area: self.area_button_click(a),
|
|
|
text=text,
|
|
|
**button_style,
|
|
|
)
|
|
|
button.pack(side=tk.LEFT, padx=5)
|
|
|
setattr(self, f"button_{area.lower()}", button)
|
|
|
|
|
|
|
|
|
middle_row = tk.Frame(left_frame, bg="#1a1a1a")
|
|
|
middle_row.pack(pady=(0, 15))
|
|
|
|
|
|
|
|
|
self.preset_label = tk.Label(
|
|
|
middle_row,
|
|
|
text=f"P{self.current_preset}",
|
|
|
font=("Nasalization Rg", 12),
|
|
|
bg="#1a1a1a",
|
|
|
fg="#00FFFF",
|
|
|
)
|
|
|
self.preset_label.pack(side=tk.LEFT, padx=(0, 10))
|
|
|
|
|
|
|
|
|
self.save_button = self.create_button(
|
|
|
middle_row,
|
|
|
text="Save",
|
|
|
command=self.save_preset,
|
|
|
font=("Nasalization Rg", 12),
|
|
|
)
|
|
|
self.save_button.pack(side=tk.LEFT, padx=5)
|
|
|
|
|
|
|
|
|
bottom_row = tk.Frame(left_frame, bg="#1a1a1a")
|
|
|
bottom_row.pack()
|
|
|
|
|
|
|
|
|
force_image = ImageTk.PhotoImage(Image.open("force.png").resize((48, 24)))
|
|
|
self.force_button = self.create_button(
|
|
|
bottom_row, command=self.force_translate, image=force_image
|
|
|
)
|
|
|
self.force_button.image = force_image
|
|
|
self.force_button.pack(side=tk.LEFT, padx=(0, 8))
|
|
|
|
|
|
|
|
|
speed_container = tk.Frame(
|
|
|
bottom_row, bg="#1a1a1a", bd=1, relief="solid", highlightthickness=0
|
|
|
)
|
|
|
speed_container.pack(side=tk.LEFT, padx=(8, 0))
|
|
|
|
|
|
speed_frame = tk.Frame(speed_container, bg="#1a1a1a")
|
|
|
speed_frame.pack(padx=1, pady=1)
|
|
|
|
|
|
|
|
|
self.normal_speed_button = self.create_button(
|
|
|
speed_frame,
|
|
|
text="Normal",
|
|
|
command=lambda: self.switch_speed("normal"),
|
|
|
font=("Nasalization Rg", 11),
|
|
|
width=6,
|
|
|
bg="#1a1a1a",
|
|
|
)
|
|
|
self.normal_speed_button.pack(side=tk.LEFT)
|
|
|
self.normal_speed_button.selected = True
|
|
|
self.normal_speed_button.config(fg="#00FFFF")
|
|
|
|
|
|
|
|
|
tk.Frame(speed_frame, width=1, bg="#333333").pack(
|
|
|
side=tk.LEFT, fill=tk.Y, padx=1, pady=1
|
|
|
)
|
|
|
|
|
|
|
|
|
self.high_speed_button = self.create_button(
|
|
|
speed_frame,
|
|
|
text="High",
|
|
|
command=lambda: self.switch_speed("high"),
|
|
|
font=("Nasalization Rg", 11),
|
|
|
width=4,
|
|
|
bg="#1a1a1a",
|
|
|
)
|
|
|
self.high_speed_button.pack(side=tk.LEFT)
|
|
|
|
|
|
|
|
|
preset_row = tk.Frame(self.main_frame, bg="#1a1a1a")
|
|
|
preset_row.pack(side=tk.BOTTOM, pady=10)
|
|
|
|
|
|
|
|
|
self.preset_buttons = []
|
|
|
for i in range(5):
|
|
|
btn = self.create_button(
|
|
|
preset_row,
|
|
|
text=str(i + 1),
|
|
|
command=lambda x=i + 1: self.select_preset(x),
|
|
|
font=("Nasalization Rg", 10),
|
|
|
width=2,
|
|
|
height=1,
|
|
|
)
|
|
|
btn.pack(side=tk.LEFT, padx=2)
|
|
|
self.preset_buttons.append(btn)
|
|
|
|
|
|
|
|
|
self.update_preset_buttons()
|
|
|
self.current_speed = "normal"
|
|
|
|
|
|
def select_preset(self, preset_number):
|
|
|
"""เลือก preset ตามหมายเลข
|
|
|
Args:
|
|
|
preset_number (int): หมายเลข preset (1-5)
|
|
|
"""
|
|
|
if 1 <= preset_number <= self.max_presets:
|
|
|
if self.has_unsaved_changes:
|
|
|
|
|
|
warning = tk.Toplevel(self.root)
|
|
|
warning.title("คำเตือน")
|
|
|
warning.geometry("300x150")
|
|
|
warning.configure(bg="#1a1a1a")
|
|
|
warning.transient(self.root)
|
|
|
warning.grab_set()
|
|
|
|
|
|
|
|
|
x = self.root.winfo_x() + (self.root.winfo_width() - 300) // 2
|
|
|
y = self.root.winfo_y() + (self.root.winfo_height() - 150) // 2
|
|
|
warning.geometry(f"+{x}+{y}")
|
|
|
|
|
|
|
|
|
message = tk.Label(
|
|
|
warning,
|
|
|
text="คุณยังไม่ได้บันทึกการเปลี่ยนแปลง\nต้องการบันทึกก่อนเปลี่ยน Preset หรือไม่?",
|
|
|
bg="#1a1a1a",
|
|
|
fg="white",
|
|
|
font=("Nasalization Rg", 10),
|
|
|
)
|
|
|
message.pack(pady=20)
|
|
|
|
|
|
button_frame = tk.Frame(warning, bg="#1a1a1a")
|
|
|
button_frame.pack(pady=10)
|
|
|
|
|
|
def save_and_switch():
|
|
|
self.save_preset()
|
|
|
self.has_unsaved_changes = False
|
|
|
self._complete_preset_switch(preset_number)
|
|
|
warning.destroy()
|
|
|
|
|
|
def switch_without_save():
|
|
|
self.has_unsaved_changes = False
|
|
|
self._complete_preset_switch(preset_number)
|
|
|
warning.destroy()
|
|
|
|
|
|
|
|
|
save_btn = tk.Button(
|
|
|
button_frame,
|
|
|
text="บันทึก",
|
|
|
command=save_and_switch,
|
|
|
bg="#404040",
|
|
|
fg="#00FFFF",
|
|
|
font=("Nasalization Rg", 10),
|
|
|
width=10,
|
|
|
)
|
|
|
save_btn.pack(side=tk.LEFT, padx=5)
|
|
|
|
|
|
no_save_btn = tk.Button(
|
|
|
button_frame,
|
|
|
text="ไม่บันทึก",
|
|
|
command=switch_without_save,
|
|
|
bg="#404040",
|
|
|
fg="white",
|
|
|
font=("Nasalization Rg", 10),
|
|
|
width=10,
|
|
|
)
|
|
|
no_save_btn.pack(side=tk.LEFT, padx=5)
|
|
|
|
|
|
else:
|
|
|
self._complete_preset_switch(preset_number)
|
|
|
|
|
|
def _complete_preset_switch(self, preset_number):
|
|
|
"""ดำเนินการเปลี่ยน preset"""
|
|
|
try:
|
|
|
|
|
|
self.current_preset = preset_number
|
|
|
|
|
|
|
|
|
preset = self.settings.get_preset(preset_number)
|
|
|
if not preset:
|
|
|
logging.error(f"Cannot find preset {preset_number}")
|
|
|
return
|
|
|
|
|
|
|
|
|
area_config = preset.get("areas", "A")
|
|
|
coordinates = preset.get("coordinates", {})
|
|
|
|
|
|
|
|
|
for area, coords in coordinates.items():
|
|
|
self.settings.set_translate_area(
|
|
|
coords["start_x"],
|
|
|
coords["start_y"],
|
|
|
coords["end_x"],
|
|
|
coords["end_y"],
|
|
|
area,
|
|
|
)
|
|
|
|
|
|
|
|
|
active_areas = area_config.split("+")
|
|
|
for area in ["A", "B", "C"]:
|
|
|
self.area_states[area] = area in active_areas
|
|
|
|
|
|
|
|
|
self.update_preset_buttons()
|
|
|
self.update_button_highlights()
|
|
|
|
|
|
|
|
|
if self.switch_area_callback:
|
|
|
self.switch_area_callback(active_areas)
|
|
|
|
|
|
logging.info(
|
|
|
f"Switched to preset {preset_number} with areas: {area_config}"
|
|
|
)
|
|
|
|
|
|
except Exception as e:
|
|
|
logging.error(f"Error in _complete_preset_switch: {e}")
|
|
|
|
|
|
def update_preset_buttons(self):
|
|
|
"""อัพเดตสถานะและการแสดงผลของปุ่ม preset ทั้งหมด"""
|
|
|
for i, btn in enumerate(self.preset_buttons):
|
|
|
if i + 1 == self.current_preset:
|
|
|
btn.config(fg="#00FFFF", bg="#404040")
|
|
|
btn.selected = True
|
|
|
else:
|
|
|
btn.config(fg="#AAAAAA", bg="#1a1a1a")
|
|
|
btn.selected = False
|
|
|
|
|
|
|
|
|
self.preset_label.config(text=f"P{self.current_preset}", fg="#00FFFF")
|
|
|
|
|
|
def get_current_area_string(self):
|
|
|
"""รับสตริงแสดงพื้นที่ที่เลือกในปัจจุบัน"""
|
|
|
active = [area for area in ["A", "B", "C"] if self.area_states[area]]
|
|
|
return "+".join(active) if active else "A"
|
|
|
|
|
|
def load_current_area_states(self):
|
|
|
"""โหลดสถานะพื้นที่ปัจจุบัน"""
|
|
|
saved_area = self.settings.get("current_area", "A+B")
|
|
|
if saved_area:
|
|
|
areas = saved_area.split("+")
|
|
|
for area in ["A", "B", "C"]:
|
|
|
self.area_states[area] = area in areas
|
|
|
|
|
|
def switch_speed(self, speed_mode):
|
|
|
"""สลับระหว่างโหมดความเร็ว"""
|
|
|
self.current_speed = speed_mode
|
|
|
if speed_mode == "normal":
|
|
|
self.normal_speed_button.selecte
|
|
|
self.normal_speed_button.selected = True
|
|
|
self.high_speed_button.selected = False
|
|
|
self.normal_speed_button.config(fg="#00FFFF")
|
|
|
self.high_speed_button.config(fg="#AAAAAA")
|
|
|
else:
|
|
|
self.normal_speed_button.selected = False
|
|
|
self.high_speed_button.selected = True
|
|
|
self.normal_speed_button.config(fg="#AAAAAA")
|
|
|
self.high_speed_button.config(fg="#00FFFF")
|
|
|
|
|
|
if hasattr(self, "speed_callback"):
|
|
|
self.speed_callback(speed_mode)
|
|
|
|
|
|
def position_below_main_ui(self):
|
|
|
"""จัดตำแหน่ง Control UI ให้อยู่ด้านล่างของ Main UI"""
|
|
|
if hasattr(self.root.master, "winfo_x") and hasattr(
|
|
|
self.root.master, "winfo_y"
|
|
|
):
|
|
|
main_x = self.root.master.winfo_x()
|
|
|
main_y = self.root.master.winfo_y()
|
|
|
main_height = self.root.master.winfo_height()
|
|
|
|
|
|
new_x = main_x
|
|
|
new_y = main_y + main_height + 5
|
|
|
|
|
|
self.ui_cache["position_x"] = new_x
|
|
|
self.ui_cache["position_y"] = new_y
|
|
|
|
|
|
self.root.geometry(f"+{new_x}+{new_y}")
|
|
|
|
|
|
def show_window(self):
|
|
|
"""แสดงหน้าต่าง Control UI"""
|
|
|
if self.root.winfo_exists():
|
|
|
if self.ui_cache["position_x"] is not None:
|
|
|
self.restore_cached_position()
|
|
|
else:
|
|
|
self.position_below_main_ui()
|
|
|
|
|
|
|
|
|
current_areas = self.ui_cache["current_area"].split("+")
|
|
|
for area in ["A", "B", "C"]:
|
|
|
self.area_states[area] = area in current_areas
|
|
|
|
|
|
self.root.deiconify()
|
|
|
self.root.lift()
|
|
|
self.root.attributes("-topmost", True)
|
|
|
self.update_button_highlights()
|
|
|
self.update_preset_display()
|
|
|
|
|
|
def restore_cached_position(self):
|
|
|
"""กู้คืนตำแหน่งจากแคช"""
|
|
|
if (
|
|
|
self.ui_cache["position_x"] is not None
|
|
|
and self.ui_cache["position_y"] is not None
|
|
|
):
|
|
|
self.root.geometry(
|
|
|
f"+{self.ui_cache['position_x']}+{self.ui_cache['position_y']}"
|
|
|
)
|
|
|
|
|
|
def close_window(self):
|
|
|
"""ปิดหน้าต่าง Control UI"""
|
|
|
if self.root.winfo_exists():
|
|
|
if self.root.state() != "withdrawn":
|
|
|
self.root.withdraw()
|
|
|
|
|
|
def update_button_highlights(self):
|
|
|
"""Update button colors based on area states"""
|
|
|
button_map = {"A": self.button_a, "B": self.button_b, "C": self.button_c}
|
|
|
|
|
|
try:
|
|
|
|
|
|
for area, button in button_map.items():
|
|
|
if self.area_states[area]:
|
|
|
button.config(fg="#00FFFF", bg="#404040")
|
|
|
button.selected = True
|
|
|
else:
|
|
|
button.config(fg="#AAAAAA", bg="black")
|
|
|
button.selected = False
|
|
|
|
|
|
|
|
|
active_areas = self.get_active_areas()
|
|
|
area_str = "+".join(active_areas) if active_areas else "A"
|
|
|
self.ui_cache["current_area"] = area_str
|
|
|
self.settings.set("current_area", area_str)
|
|
|
|
|
|
|
|
|
logging.info(f"Updated button highlights. Active areas: {area_str}")
|
|
|
|
|
|
except Exception as e:
|
|
|
logging.error(f"Error in update_button_highlights: {e}")
|
|
|
|
|
|
def get_active_areas(self):
|
|
|
"""Return list of active areas in correct order"""
|
|
|
return [area for area in ["A", "B", "C"] if self.area_states[area]]
|
|
|
|
|
|
def setup_bindings(self):
|
|
|
"""Setup window movement bindings"""
|
|
|
self.root.bind("<Button-1>", self.start_move)
|
|
|
self.root.bind("<ButtonRelease-1>", self.stop_move)
|
|
|
self.root.bind("<B1-Motion>", self.on_drag)
|
|
|
|
|
|
def start_move(self, event):
|
|
|
self.x = event.x
|
|
|
self.y = event.y
|
|
|
|
|
|
def stop_move(self, event):
|
|
|
self.x = None
|
|
|
self.y = None
|
|
|
|
|
|
def on_drag(self, event):
|
|
|
"""จัดการการลากหน้าต่าง"""
|
|
|
if self.x is not None and self.y is not None:
|
|
|
deltax = event.x - self.x
|
|
|
deltay = event.y - self.y
|
|
|
x = self.root.winfo_x() + deltax
|
|
|
y = self.root.winfo_y() + deltay
|
|
|
self.root.geometry(f"+{x}+{y}")
|
|
|
|
|
|
self.ui_cache["position_x"] = x
|
|
|
self.ui_cache["position_y"] = y
|
|
|
|
|
|
def area_button_click(self, area):
|
|
|
"""Toggle area on/off and update UI
|
|
|
Args:
|
|
|
area (str): พื้นที่ที่ถูกคลิก (A, B, หรือ C)
|
|
|
"""
|
|
|
try:
|
|
|
|
|
|
new_state = not self.area_states[area]
|
|
|
|
|
|
|
|
|
other_active_areas = any(
|
|
|
self.area_states[a] for a in ["A", "B", "C"] if a != area
|
|
|
)
|
|
|
|
|
|
|
|
|
if new_state or other_active_areas:
|
|
|
self.area_states[area] = new_state
|
|
|
self.update_button_highlights()
|
|
|
|
|
|
|
|
|
active_areas = self.get_active_areas()
|
|
|
|
|
|
|
|
|
if active_areas:
|
|
|
self.switch_area_callback(active_areas)
|
|
|
self.force_translate()
|
|
|
|
|
|
logging.info(
|
|
|
f"Area {area} clicked. Active areas: {self.get_active_areas()}"
|
|
|
)
|
|
|
|
|
|
except Exception as e:
|
|
|
logging.error(f"Error in area_button_click: {e}")
|
|
|
|
|
|
def capture_screen(self):
|
|
|
"""Capture screen function"""
|
|
|
try:
|
|
|
from screen_capture import ScreenCapture
|
|
|
|
|
|
capturer = ScreenCapture()
|
|
|
filepath = capturer.capture_primary_screen()
|
|
|
if filepath:
|
|
|
self.show_capture_feedback()
|
|
|
except Exception as e:
|
|
|
logging.error(f"Screen capture error: {e}")
|
|
|
|
|
|
def show_capture_feedback(self):
|
|
|
"""Show capture feedback"""
|
|
|
feedback = tk.Toplevel(self.root)
|
|
|
feedback.overrideredirect(True)
|
|
|
feedback.configure(bg="black")
|
|
|
x = self.root.winfo_x() + self.camera_button.winfo_x()
|
|
|
y = self.root.winfo_y() + self.camera_button.winfo_y()
|
|
|
tk.Label(
|
|
|
feedback,
|
|
|
text="Captured!",
|
|
|
fg="lime",
|
|
|
bg="black",
|
|
|
font=("Nasalization Rg", 8),
|
|
|
).pack(padx=10, pady=5)
|
|
|
feedback.geometry(f"+{x+30}+{y}")
|
|
|
feedback.after(1000, feedback.destroy)
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
root = tk.Tk()
|
|
|
|
|
|
def dummy_force():
|
|
|
print("Force translate triggered")
|
|
|
|
|
|
def dummy_switch(area):
|
|
|
print(f"Switched to area {area}")
|
|
|
|
|
|
app = Control_UI(root, dummy_force, dummy_switch, Settings())
|
|
|
root.mainloop()
|
|
|
|