diff --git a/RA3MP3Playback.pyw b/RA3MP3Playback.pyw index 5aed971..98b20e4 100644 --- a/RA3MP3Playback.pyw +++ b/RA3MP3Playback.pyw @@ -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" diff --git a/textmenu.py b/textmenu.py index 68c4fbd..b3e1e80 100644 --- a/textmenu.py +++ b/textmenu.py @@ -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('', self._on_double_click) # Proper double-click binding self.root.bind('', self._on_key_press) - # Bind mouse wheel scrolling - self.root.bind('', self._on_mousewheel) # Windows - self.root.bind('', lambda e: self._on_mousewheel(e)) # Linux up - self.root.bind('', lambda e: self._on_mousewheel(e)) # Linux down + # Bind mouse wheel scrolling - platform specific + if os.name == 'nt': # Windows + self.root.bind('', self._on_mousewheel) + else: # Linux/Unix + self.root.bind('', lambda e: self._on_mousewheel_linux(-1)) # Scroll up + self.root.bind('', 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 \ No newline at end of file