-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui_app.py
More file actions
90 lines (71 loc) · 3.38 KB
/
gui_app.py
File metadata and controls
90 lines (71 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import tkinter as tk
from tkinter import ttk
import threading
import time
from bot_logic import StoneBot
class BotGUI:
def __init__(self, root):
self.root = root
self.root.title("AI Vision Bot - Configuration")
self.root.geometry("400x300")
self.root.resizable(False, False)
self.bot = StoneBot()
self.bot_thread = None
# --- UI LAYOUT ---
title_label = ttk.Label(root, text="Bot Control Panel", font=("Segoe UI", 14, "bold"))
title_label.pack(pady=10)
# Stats Frame
stats_frame = ttk.LabelFrame(root, text="Statistics", padding=(10, 5))
stats_frame.pack(pady=5, padx=10, fill="x")
self.time_label = ttk.Label(stats_frame, text="Time: 00:00", font=("Consolas", 10))
self.time_label.pack(anchor="w")
self.count_label = ttk.Label(stats_frame, text="Stones Cleared: 0", font=("Consolas", 10))
self.count_label.pack(anchor="w")
# Settings Frame
settings_frame = ttk.LabelFrame(root, text="Settings", padding=(10, 5))
settings_frame.pack(pady=5, padx=10, fill="x")
ttk.Label(settings_frame, text="Attack Duration (s):").pack(side="left")
self.duration_var = tk.StringVar(value="5.0")
self.duration_entry = ttk.Entry(settings_frame, textvariable=self.duration_var, width=5)
self.duration_entry.pack(side="left", padx=5)
# Buttons
btn_frame = ttk.Frame(root)
btn_frame.pack(pady=15)
self.start_button = ttk.Button(btn_frame, text="START", command=self.start_bot)
self.start_button.pack(side="left", padx=5)
self.stop_button = ttk.Button(btn_frame, text="STOP", command=self.stop_bot, state="disabled")
self.stop_button.pack(side="left", padx=5)
# Status Bar
self.status_label = ttk.Label(root, text="Ready", foreground="gray", font=("Arial", 9))
self.status_label.pack(side="bottom", pady=5)
self.update_stats()
def start_bot(self):
if not self.bot.initialize():
self.status_label.config(text="Error: Model could not be loaded!", foreground="red")
return
try:
wait_time = float(self.duration_var.get())
except ValueError:
wait_time = 5.0
self.duration_var.set("5.0")
self.status_label.config(text=f"Running (Attack Wait: {wait_time}s)...", foreground="green")
self.start_button.config(state="disabled")
self.stop_button.config(state="normal")
self.duration_entry.config(state="disabled")
self.bot_thread = threading.Thread(target=self.bot.run, args=(wait_time,))
self.bot_thread.daemon = True
self.bot_thread.start()
def stop_bot(self):
if self.bot:
self.bot.stop()
self.status_label.config(text="Stopped.", foreground="orange")
self.start_button.config(state="normal")
self.stop_button.config(state="disabled")
self.duration_entry.config(state="normal")
def update_stats(self):
if self.bot.running:
elapsed = int(time.time() - self.bot.start_time)
mins, secs = divmod(elapsed, 60)
self.time_label.config(text=f"Time: {mins:02}:{secs:02}")
self.count_label.config(text=f"Stones Cleared: {self.bot.stone_count}")
self.root.after(500, self.update_stats)