Git Product home page Git Product logo

Comments (6)

ppizarror avatar ppizarror commented on June 3, 2024

Hello, you can create your menu without using menu.mainloop to test events and manually delegate events to the menu. See https://pygame-menu.readthedocs.io/en/4.3.9/_source/create_menu.html#display-a-menu.

Could you also check out #422. In particular, you can customize the events by creating your own controller object. See https://pygame-menu.readthedocs.io/en/4.3.9/_source/advanced_controller.html

from pygame-menu.

MichaelWoodc avatar MichaelWoodc commented on June 3, 2024

Hello, you can create your menu without using menu.mainloop to test events and manually delegate events to the menu. See https://pygame-menu.readthedocs.io/en/4.3.9/_source/create_menu.html#display-a-menu.

Could you also check out #422. In particular, you can customize the events by creating your own controller object. See https://pygame-menu.readthedocs.io/en/4.3.9/_source/advanced_controller.html

Thanks for your help! I unfortunately still cannot get it to work. Does it work by default with any specific controller? I'm ready to give up on the vintage USB nintendo controller :(

from pygame-menu.

ppizarror avatar ppizarror commented on June 3, 2024

It does work with controllers right out of the box. However, it might not work for some controllers because of incorrect mapping.

Could you test if the menu responds to any event by cloning and testing the menu event function? Maybe the events do not match the controller you're using:

def update(self, events: EventVectorType) -> bool:
"""
Update the status of the Menu using external events. The update event is
applied only on the **current** Menu.
.. warning::
This method should not be used along :py:meth:`pygame_menu.menu.Menu.get_current`,
for example, ``menu.get_current().update(...)``.
:param events: List of pygame events
:return: ``True`` if the menu updated (or a widget)
"""
# Check events
assert isinstance(events, list)
self._current._last_update_mode = []
# If menu is not enabled
if not self.is_enabled():
self._current._runtime_errors.throw(self._current._runtime_errors.update,
'menu is not enabled')
self._current._stats.update += 1
# Call onupdate callback
if self._current._onupdate is not None:
try:
self._current._onupdate(events, self._current)
except TypeError:
self._current._onupdate()
if self._current._disable_update:
self._current._last_update_mode.append(_events.MENU_LAST_DISABLE_UPDATE)
return False
# If any widget status changes, set the status as True
updated = False
# Update mouse
if self._mouse_visible_update:

What happens if you print the event list?

from pygame-menu.

MichaelWoodc avatar MichaelWoodc commented on June 3, 2024

When I print the events using pygame and not pygame menu, ( couldn't quite get the provided code to work, I'm really scratching my head here! I'm still learning programming) I get the following:

pygame 2.2.0 (SDL 2.0.22, Python 3.8.10)
Hello from the pygame community. https://www.pygame.org/contribute.html
<Event(1541-JoyDeviceAdded {'device_index': 0, 'guid': '03000000790000001100000000000000'})>

#Now lets press the A button, it gives us 2 events
<Event(1539-JoyButtonDown {'joy': 0, 'instance_id': 0, 'button': 1})>
<Event(1540-JoyButtonUp {'joy': 0, 'instance_id': 0, 'button': 1})>

#Likewise, if we push button b, also two events:
<Event(1539-JoyButtonDown {'joy': 0, 'instance_id': 0, 'button': 2})>
<Event(1540-JoyButtonUp {'joy': 0, 'instance_id': 0, 'button': 2})>

#Start Button:
<Event(1539-JoyButtonDown {'joy': 0, 'instance_id': 0, 'button': 9})>
<Event(1540-JoyButtonUp {'joy': 0, 'instance_id': 0, 'button': 9})>

#Select Button:
<Event(1539-JoyButtonDown {'joy': 0, 'instance_id': 0, 'button': 8})>
<Event(1540-JoyButtonUp {'joy': 0, 'instance_id': 0, 'button': 8})>

#Joystick Up: Please note: for the initial click it always displays the resting axis value first
<Event(1536-JoyAxisMotion {'joy': 0, 'instance_id': 0, 'axis': 4, 'value': -0.007812738425855281})>
<Event(1536-JoyAxisMotion {'joy': 0, 'instance_id': 0, 'axis': 4, 'value': -1.000030518509476})>
<Event(1536-JoyAxisMotion {'joy': 0, 'instance_id': 0, 'axis': 4, 'value': -0.007812738425855281})>


#Joystick Down:
<Event(1536-JoyAxisMotion {'joy': 0, 'instance_id': 0, 'axis': 4, 'value': -0.007812738425855281})>
<Event(1536-JoyAxisMotion {'joy': 0, 'instance_id': 0, 'axis': 4, 'value': 1.0})>
<Event(1536-JoyAxisMotion {'joy': 0, 'instance_id': 0, 'axis': 4, 'value': -0.007812738425855281})>

#Joystick Left: (note: this usb controller actually considers 4 different axis for left and right
	I will only display one axis, axis 0, again, 3 events for first click, two thereafter)
<Event(1536-JoyAxisMotion {'joy': 0, 'instance_id': 0, 'axis': 0, 'value': -0.007812738425855281})>
<Event(1536-JoyAxisMotion {'joy': 0, 'instance_id': 0, 'axis': 0, 'value': -1.000030518509476})>
<Event(1536-JoyAxisMotion {'joy': 0, 'instance_id': 0, 'axis': 0, 'value': -0.007812738425855281})>

#Joystick Right: (again, 4 axis change, only showing axis 0)
<Event(1536-JoyAxisMotion {'joy': 0, 'instance_id': 0, 'axis': 0, 'value': -0.007812738425855281})>
<Event(1536-JoyAxisMotion {'joy': 0, 'instance_id': 0, 'axis': 0, 'value': 1.0})>
<Event(1536-JoyAxisMotion {'joy': 0, 'instance_id': 0, 'axis': 0, 'value': -0.007812738425855281})>`


```
Of note may be the fact that when I test the controller with a different controller test app, using SDL, the A button is button 1, B is button 0, start button6, select button 4.  

from pygame-menu.

MichaelWoodc avatar MichaelWoodc commented on June 3, 2024

Hey so I did get it to work, probably not in an ideal fashion, but I just directly edited the controls.py file. Also, for some reason the events from my controller never showed up in any of the examples, although hot plugging the controller itself would show up as an event. May be a controller issue with pygame_menu, but every controller event shows up with no issue is pygame, just not pygame_menu.

from pygame-menu.

ppizarror avatar ppizarror commented on June 3, 2024

Hello, you also can edit default controls (as there are tons of different control mappings out there); check out https://pygame-menu.readthedocs.io/en/4.3.9/_source/advanced_controller.html#configure-controller. For future related issues, the menu cannot guarantee each control mapping. Thus any PR is welcome that addresses this issue.

from pygame-menu.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.