Translations, suggestion box, UX
All checks were successful
Gitea/kapitanbooru-uploader/pipeline/head This commit looks good
All checks were successful
Gitea/kapitanbooru-uploader/pipeline/head This commit looks good
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import tkinter as tk
|
||||
from tkinter import font
|
||||
|
||||
from .I18N import _
|
||||
from .TagsRepo import TagsRepo
|
||||
from .common import open_tag_wiki_url
|
||||
from .tag_processing import process_tag
|
||||
@@ -24,7 +25,37 @@ class AutocompleteEntry(tk.Entry):
|
||||
self.bind("<Up>", self.on_up)
|
||||
self.bind("<Return>", self.on_return)
|
||||
self.bind("<Tab>", self.on_return)
|
||||
self.bind("<FocusOut>", lambda e: self.hide_listbox())
|
||||
self.bind("<FocusOut>", self.on_focus_out)
|
||||
|
||||
def on_focus_out(self, event):
|
||||
self.after(10, self.delayed_focus_check)
|
||||
|
||||
def delayed_focus_check(self):
|
||||
try:
|
||||
# Get current focus using Tk's internal command
|
||||
focused_name = self.tk.call("focus")
|
||||
if not focused_name:
|
||||
self.hide_listbox()
|
||||
return
|
||||
|
||||
# Convert to widget object
|
||||
focused_widget = self.nametowidget(focused_name)
|
||||
|
||||
# Check if focus is in our listbox hierarchy
|
||||
if self.listbox_window and self.is_child_of_listbox_window(focused_widget):
|
||||
return
|
||||
except (KeyError, tk.TclError):
|
||||
pass
|
||||
|
||||
self.hide_listbox()
|
||||
|
||||
def is_child_of_listbox_window(self, widget):
|
||||
current = widget
|
||||
while current:
|
||||
if current == self.listbox_window:
|
||||
return True
|
||||
current = current.master
|
||||
return False
|
||||
|
||||
def on_keyrelease(self, event):
|
||||
if event.keysym in ("Down", "Up", "Return", "Tab"):
|
||||
@@ -99,7 +130,7 @@ class AutocompleteEntry(tk.Entry):
|
||||
self.suggestion_map[display_text] = tag_insert
|
||||
return suggestions
|
||||
except Exception as e:
|
||||
print("Błąd przy pobieraniu sugestii:", e)
|
||||
print(_("Błąd przy pobieraniu sugestii:"), e)
|
||||
return []
|
||||
|
||||
def show_listbox(self):
|
||||
@@ -139,12 +170,22 @@ class AutocompleteEntry(tk.Entry):
|
||||
|
||||
def on_listbox_click(self, event):
|
||||
if self.listbox:
|
||||
index = self.listbox.curselection()
|
||||
if index:
|
||||
value = self.listbox.get(index)
|
||||
# Process click first before changing focus
|
||||
index = self.listbox.nearest(event.y)
|
||||
if index >= 0:
|
||||
# Get the display text from listbox
|
||||
selected_display = self.listbox.get(index)
|
||||
# Get the actual tag from the suggestion map
|
||||
tag = self.suggestion_map.get(selected_display, selected_display)
|
||||
|
||||
if self.callback:
|
||||
self.callback(tag)
|
||||
|
||||
# Clear the entry and hide listbox
|
||||
self.delete(0, tk.END)
|
||||
self.insert(tk.END, value)
|
||||
self.hide_listbox()
|
||||
# Then explicitly manage focus
|
||||
self.focus_set() # Use focus_set() instead of focus_force()
|
||||
self.hide_listbox()
|
||||
return "break"
|
||||
|
||||
def on_listbox_motion(self, event):
|
||||
|
Reference in New Issue
Block a user