This commit is contained in:
edschuy95 2026-01-22 19:37:54 -05:00
parent 7c3d5db62c
commit 2506d36674
2 changed files with 34 additions and 8 deletions

View file

@ -23,7 +23,7 @@ import pygame
shutdown_event = threading.Event()
# ========================= 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_WIN_GAME_EXE = r"./qgame.dll"

View file

@ -2,6 +2,7 @@ import tkinter as tk
from tkinter import ttk
import time
import math
import os
from typing import List, Optional
class TextMenu:
@ -224,15 +225,40 @@ class TextMenu:
self.listbox.bind('<Double-Button-1>', self._on_double_click) # Proper double-click binding
self.root.bind('<Key>', self._on_key_press)
# Bind mouse wheel scrolling
self.root.bind('<MouseWheel>', self._on_mousewheel) # Windows
self.root.bind('<Button-4>', lambda e: self._on_mousewheel(e)) # Linux up
self.root.bind('<Button-5>', lambda e: self._on_mousewheel(e)) # Linux down
# Bind mouse wheel scrolling - platform specific
if os.name == 'nt': # Windows
self.root.bind('<MouseWheel>', self._on_mousewheel)
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
if self.choices:
self.listbox.selection_set(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):
"""Handle double-click event directly"""
@ -291,12 +317,12 @@ class TextMenu:
# Run the GUI event loop
self.root.mainloop()
# Clean up - destroy the window immediately to prevent hanging
# CRITICAL: Destroy the window BEFORE returning
try:
if self.root and str(self.root) != '.':
if self.root:
self.root.destroy()
self.root = None
except tk.TclError:
# Window may already be destroyed
pass
return self.selected