.
This commit is contained in:
parent
7c3d5db62c
commit
2506d36674
2 changed files with 34 additions and 8 deletions
|
|
@ -23,7 +23,7 @@ import pygame
|
||||||
shutdown_event = threading.Event()
|
shutdown_event = threading.Event()
|
||||||
|
|
||||||
# ========================= CONFIG =========================
|
# ========================= CONFIG =========================
|
||||||
DEBUG = False # Set True to enable debug overrides
|
DEBUG = True # Set True to enable debug overrides
|
||||||
|
|
||||||
# Default paths (used if not in debug mode)
|
# Default paths (used if not in debug mode)
|
||||||
DEFAULT_WIN_GAME_EXE = r"./qgame.dll"
|
DEFAULT_WIN_GAME_EXE = r"./qgame.dll"
|
||||||
|
|
|
||||||
40
textmenu.py
40
textmenu.py
|
|
@ -2,6 +2,7 @@ import tkinter as tk
|
||||||
from tkinter import ttk
|
from tkinter import ttk
|
||||||
import time
|
import time
|
||||||
import math
|
import math
|
||||||
|
import os
|
||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
|
|
||||||
class TextMenu:
|
class TextMenu:
|
||||||
|
|
@ -224,15 +225,40 @@ class TextMenu:
|
||||||
self.listbox.bind('<Double-Button-1>', self._on_double_click) # Proper double-click binding
|
self.listbox.bind('<Double-Button-1>', self._on_double_click) # Proper double-click binding
|
||||||
self.root.bind('<Key>', self._on_key_press)
|
self.root.bind('<Key>', self._on_key_press)
|
||||||
|
|
||||||
# Bind mouse wheel scrolling
|
# Bind mouse wheel scrolling - platform specific
|
||||||
self.root.bind('<MouseWheel>', self._on_mousewheel) # Windows
|
if os.name == 'nt': # Windows
|
||||||
self.root.bind('<Button-4>', lambda e: self._on_mousewheel(e)) # Linux up
|
self.root.bind('<MouseWheel>', self._on_mousewheel)
|
||||||
self.root.bind('<Button-5>', lambda e: self._on_mousewheel(e)) # Linux down
|
else: # Linux/Unix
|
||||||
|
self.root.bind('<Button-4>', lambda e: self._on_mousewheel_linux(-1)) # Scroll up
|
||||||
|
self.root.bind('<Button-5>', lambda e: self._on_mousewheel_linux(1)) # Scroll down
|
||||||
|
|
||||||
# Set first item as active
|
# Set first item as active
|
||||||
if self.choices:
|
if self.choices:
|
||||||
self.listbox.selection_set(0)
|
self.listbox.selection_set(0)
|
||||||
self.listbox.activate(0)
|
self.listbox.activate(0)
|
||||||
|
self.listbox.focus_set() # This ensures the listbox has keyboard focus
|
||||||
|
|
||||||
|
def _on_mousewheel_linux(self, direction):
|
||||||
|
"""Handle Linux mouse wheel events"""
|
||||||
|
self._cancel_timeout()
|
||||||
|
|
||||||
|
selection = self.listbox.curselection()
|
||||||
|
if not selection:
|
||||||
|
current_index = 0
|
||||||
|
self.listbox.selection_set(0)
|
||||||
|
self.listbox.activate(0)
|
||||||
|
return
|
||||||
|
|
||||||
|
current_index = selection[0]
|
||||||
|
|
||||||
|
if direction == -1: # Button-4 = scroll up
|
||||||
|
new_index = max(0, current_index - 1)
|
||||||
|
else: # Button-5 = scroll down
|
||||||
|
new_index = min(len(self.choices) - 1, current_index + 1)
|
||||||
|
|
||||||
|
self.listbox.selection_clear(0, tk.END)
|
||||||
|
self.listbox.selection_set(new_index)
|
||||||
|
self.listbox.activate(new_index)
|
||||||
|
|
||||||
def _on_double_click(self, event):
|
def _on_double_click(self, event):
|
||||||
"""Handle double-click event directly"""
|
"""Handle double-click event directly"""
|
||||||
|
|
@ -291,12 +317,12 @@ class TextMenu:
|
||||||
# Run the GUI event loop
|
# Run the GUI event loop
|
||||||
self.root.mainloop()
|
self.root.mainloop()
|
||||||
|
|
||||||
# Clean up - destroy the window immediately to prevent hanging
|
# CRITICAL: Destroy the window BEFORE returning
|
||||||
try:
|
try:
|
||||||
if self.root and str(self.root) != '.':
|
if self.root:
|
||||||
self.root.destroy()
|
self.root.destroy()
|
||||||
|
self.root = None
|
||||||
except tk.TclError:
|
except tk.TclError:
|
||||||
# Window may already be destroyed
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return self.selected
|
return self.selected
|
||||||
Loading…
Add table
Add a link
Reference in a new issue