def __init__(self, device, window):
        '''Create an opened instance of a device on the given window.

        :Parameters:
            `device` : XInputDevice
                Device to open
            `window` : Window
                Window to open device on

        '''
        assert device._x_display == window._x_display
        assert device._open_device

        self.device = device
        self.window = window
        self._events = []

        try:
            dispatcher = window.__xinput_window_event_dispatcher
        except __HOLE__:
            dispatcher = window.__xinput_window_event_dispatcher = \
                XInputWindowEventDispatcher()
        dispatcher.add_instance(self)

        device = device._open_device.contents
        if not device.num_classes:
            return

        # Bind matching extended window events to bound instance methods
        # on this object.
        #
        # This is inspired by test.c of xinput package by Frederic
        # Lepied available at x.org.
        #
        # In C, this stuff is normally handled by the macro DeviceKeyPress and
        # friends. Since we don't have access to those macros here, we do it
        # this way.

        for i in range(device.num_classes):
            class_info = device.classes[i]
            if class_info.input_class == xi.KeyClass:
                self._add(class_info, xi._deviceKeyPress,
                          dispatcher._event_xinput_key_press)
                self._add(class_info, xi._deviceKeyRelease,
                          dispatcher._event_xinput_key_release)

            elif class_info.input_class == xi.ButtonClass:
                self._add(class_info, xi._deviceButtonPress,
                          dispatcher._event_xinput_button_press)
                self._add(class_info, xi._deviceButtonRelease,
                          dispatcher._event_xinput_button_release)

            elif class_info.input_class == xi.ValuatorClass:
                self._add(class_info, xi._deviceMotionNotify,
                          dispatcher._event_xinput_motion)

            elif class_info.input_class == xi.ProximityClass:
                self._add(class_info, xi._proximityIn,
                          dispatcher._event_xinput_proximity_in)
                self._add(class_info, xi._proximityOut,
                          dispatcher._event_xinput_proximity_out)

            elif class_info.input_class == xi.FeedbackClass:
                pass

            elif class_info.input_class == xi.FocusClass:
                pass
                
            elif class_info.input_class == xi.OtherClass:
                pass

        array = (xi.XEventClass * len(self._events))(*self._events)
        xi.XSelectExtensionEvent(window._x_display,
                                 window._window,
                                 array,
                                 len(array))
dataset/ETHPy150Open ardekantur/pyglet/experimental/input/xinput.py/XInputDeviceInstance.__init__