Skip to content

Commit d43f814

Browse files
committed
add realtime search option
1 parent 02e3467 commit d43f814

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

main.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,17 @@ def create_widgets(self):
3333
search_frame.pack(fill="x", padx=10, pady=5)
3434

3535
self.search_var = tk.StringVar()
36+
self.search_var.trace_add("write", self.on_search_change)
3637
self.search_entry = ttk.Entry(search_frame, textvariable=self.search_var)
3738
self.search_entry.pack(side="left", fill="x", expand=True, padx=5)
38-
self.search_entry.bind("<Return>", lambda e: self.start_search())
39+
# self.search_entry.bind("<Return>", lambda e: self.start_search()) # Enter key still works but not strictly needed with auto-search
3940

4041
search_btn = ttk.Button(search_frame, text="Search", command=self.start_search)
4142
search_btn.pack(side="right", padx=5)
4243

44+
# Debounce timer
45+
self.debounce_timer = None
46+
4347
# Results Frame
4448
results_frame = ttk.LabelFrame(self.root, text="Results", padding=(10, 10))
4549
results_frame.pack(fill="both", expand=True, padx=10, pady=5)
@@ -75,11 +79,21 @@ def create_widgets(self):
7579
status_bar = ttk.Label(self.root, textvariable=self.status_var, relief="sunken", anchor="w")
7680
status_bar.pack(fill="x", side="bottom")
7781

82+
def on_search_change(self, *args):
83+
if self.debounce_timer:
84+
self.root.after_cancel(self.debounce_timer)
85+
self.debounce_timer = self.root.after(600, self.start_search)
86+
7887
def start_search(self):
7988
query = self.search_var.get().strip()
8089
if not query:
8190
return
8291

92+
# Debounce cleanup if called manually
93+
if self.debounce_timer:
94+
self.root.after_cancel(self.debounce_timer)
95+
self.debounce_timer = None
96+
8397
self.patch_btn.config(state="disabled")
8498
self.status_var.set("Searching...")
8599
self.tree.delete(*self.tree.get_children())

0 commit comments

Comments
 (0)