In [1]:
from __future__ import print_function # For py 2.7 compat
from IPython.html import widgets # Widget definitions
from IPython.display import display # Used to display widgets in the notebook
from IPython.utils.traitlets import Unicode # Used to declare attributes of our widget
In [1]:
In [2]:
from IPython.display import HTML, Javascript
In [3]:
from IPython.html.widgets.widget_bool import _BoolWidget
from IPython.html.widgets.widget_float import _FloatWidget
from IPython.utils.traitlets import CInt, CFloat, Unicode
from IPython.html.widgets.widget import DOMWidget
In [4]:
with open("static/gamepad.js") as f:
display(Javascript(f.read()))
In [5]:
class JoystickBoolWidget(_BoolWidget):
_view_name = Unicode('JoystickBoolView', sync=True)
button_id = CInt(0, help='button_id', sync=True)
In [6]:
class JoystickFloatWidget(DOMWidget):
_view_name = Unicode('JoystickFloatView', sync=True)
value = CFloat(0.0, help="Float value", sync=True)
axis_id = CInt(0, help='axis_id', sync=True)
description = Unicode('', help="Description of the float (label).", sync=True)
In [7]:
#NBINCLUDE_STOP
In [8]:
def bar(**kwargs):
print(kwargs)
In [14]:
widgets.interact(bar,
x=JoystickBoolWidget(description="x", button_id=1),
a=JoystickBoolWidget(description="a", button_id=0),
axis1=JoystickFloatWidget(description="axis 1", axis_id=1),
axis3=JoystickFloatWidget(description="axis 3", axis_id=3),
)
Out[14]:
In [9]:
axis1=JoystickFloatWidget(description="axis 1", axis_id=1)
In [11]:
axis1
In [17]:
x=JoystickBoolWidget(description="x", button_id=1)
In [18]:
x
In [20]:
axis1