joystick.py 630 B

1234567891011121314151617181920212223242526
  1. from .custom_view import CustomView
  2. from .element import Element
  3. class JoystickView(CustomView):
  4. def __init__(self, on_move, **options):
  5. self.on_move = on_move
  6. super().__init__('joystick', __file__, [
  7. 'https://cdn.jsdelivr.net/npm/nipplejs@0.9.0/dist/nipplejs.min.js',
  8. ], **options)
  9. self.allowed_events = ['onMove']
  10. self.initialize(temp=False, onMove=self.handle_move)
  11. def handle_move(self, msg):
  12. self.on_move(msg.data)
  13. class Joystick(Element):
  14. def __init__(self, *, on_move, **options):
  15. super().__init__(JoystickView(on_move, **options))