libtcod / python-tcod

A high-performance Python port of libtcod. Includes the libtcodpy module for backwards compatibility with older projects.
BSD 2-Clause "Simplified" License
404 stars 37 forks source link

No event on scrolling with mouse wheel #118

Closed ancla33 closed 2 years ago

ancla33 commented 2 years ago

Hi,

Thank you for the great work on the library.

I can't register any event when scrolling the mouse wheel. Other events, such as mouse click (left, right, middle) are registered fine. I tried the functions below.

def ev_mousehweel(self, event: tcod.event.MouseWheel):
    print(event)

def ev_event(self, event: tcod.event.Event):
    print(event)

def ev_undefined(self, event: tcod.event.Undefined):
    print(event)

I tried it with Pygame and was able to catch the MouseWheel event:

for event in pygame.event.get():
    if event.type == pygame.MOUSEWHEEL:
        print(event)

<Event(1027-MouseWheel {'flipped': False, 'y': 2, 'x': 0, 'touch': False, 'window': None})>

Thank you!

HexDecimal commented 2 years ago

This might be similar to an issue where keys don't repeat properly when Pygame is imported. The solution then was to initialize then quit the display module. That might not work if you're using Pygame for the display.

pygame.display.init()
pygame.display.quit()

The primary issue is that SDL1 from pygame and SDL2 from tcod don't work well together. If you can't quit the display then I'll talk about the alternatives.

HexDecimal commented 2 years ago

I can't confirm the bug, and I can't confirm Pygame causing the bug either. You might need to provide a minimal example of what triggers this issue.

ancla33 commented 2 years ago

Found the problem, I had written ev_mousehweel and not ev_mousewheel. Sorry! Should have checked it this way first:

    for event in tcod.event.get():
        print(event)
HexDecimal commented 2 years ago

I missed it too. A downside to how Python handles class methods. Python's structural pattern matching might become a better way of handing this in the future.