libtcod/python-tcod

No event on scrolling with mouse wheel

ancla33 opened this issue · 4 comments

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!

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.

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.

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)

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.