<commit_before>#!/usr/bin/env python
'''
'''

__docformat__ = 'restructuredtext'
__version__ = '$Id$'

import pyglet.window.key
from pyglet.event import EVENT_HANDLED, EVENT_UNHANDLED, EventHandler

class WindowEventHandler(EventHandler):
    pass

# symbolic names for the window events
EVENT_KEY_PRESS = WindowEventHandler.register_event_type('on_key_press')
EVENT_KEY_RELEASE = WindowEventHandler.register_event_type('on_key_release')
EVENT_TEXT = WindowEventHandler.register_event_type('on_text')
EVENT_MOUSE_MOTION = WindowEventHandler.register_event_type('on_mouse_motion')
EVENT_MOUSE_DRAG = WindowEventHandler.register_event_type('on_mouse_drag')
EVENT_MOUSE_PRESS = WindowEventHandler.register_event_type('on_mouse_press')
EVENT_MOUSE_RELEASE = WindowEventHandler.register_event_type('on_mouse_release')
EVENT_MOUSE_SCROLL = WindowEventHandler.register_event_type('on_mouse_scroll')
EVENT_MOUSE_ENTER = WindowEventHandler.register_event_type('on_mouse_enter')
EVENT_MOUSE_LEAVE = WindowEventHandler.register_event_type('on_mouse_leave')
EVENT_CLOSE = WindowEventHandler.register_event_type('on_close')
EVENT_EXPOSE = WindowEventHandler.register_event_type('on_expose')
EVENT_RESIZE = WindowEventHandler.register_event_type('on_resize')
EVENT_MOVE = WindowEventHandler.register_event_type('on_move')
EVENT_ACTIVATE = WindowEventHandler.register_event_type('on_activate')
EVENT_DEACTIVATE = WindowEventHandler.register_event_type('on_deactivate')
EVENT_SHOW = WindowEventHandler.register_event_type('on_show')
EVENT_HIDE = WindowEventHandler.register_event_type('on_hide')
EVENT_CONTEXT_LOST = WindowEventHandler.register_event_type('on_context_lost')
EVENT_CONTEXT_STATE_LOST = \
    WindowEventHandler.register_event_type('on_context_state_lost')

# symbolic names for the mouse buttons
MOUSE_LEFT_BUTTON =   1 << 0
MOUSE_MIDDLE_BUTTON = 1 << 1
MOUSE_RIGHT_BUTTON =  1 << 2

def _modifiers_to_string(modifiers):
    mod_names = []
    if modifiers & pyglet.window.key.MOD_SHIFT:
        mod_names.append('MOD_SHIFT')
    if modifiers & pyglet.window.key.MOD_CTRL:
        mod_names.append('MOD_CTRL')
    if modifiers & pyglet.window.key.MOD_ALT:
        mod_names.append('MOD_ALT')
    if modifiers & pyglet.window.key.MOD_CAPSLOCK:
        mod_names.append('MOD_CAPSLOCK')
    if modifiers & pyglet.window.key.MOD_NUMLOCK:
        mod_names.append('MOD_NUMLOCK')
    if modifiers & pyglet.window.key.MOD_COMMAND:
        mod_names.append('MOD_COMMAND')
    if modifiers & pyglet.window.key.MOD_OPTION:
        mod_names.append('MOD_OPTION')
    return '|'.join(mod_names)

def _buttons_to_string(buttons):
    button_names = []
    if buttons & MOUSE_LEFT_BUTTON:
        button_names.append('MOUSE_LEFT_BUTTON')
    if buttons & MOUSE_MIDDLE_BUTTON:
        button_names.append('MOUSE_MIDDLE_BUTTON')
    if buttons & MOUSE_RIGHT_BUTTON:
        button_names.append('MOUSE_RIGHT_BUTTON')
    return '|'.join(button_names)

def _symbol_to_string(symbol):
    return pyglet.window.key._key_names.get(symbol, str(symbol))

# Does nothing, but shows prototypes.
class EventHandler(object):
    def on_key_press(self, symbol, modifiers):
        pass

    def on_key_release(self, symbol, modifiers):
        pass

    def on_text(self, text):
        pass

    def on_mouse_motion(self, x, y, dx, dy):
        pass

    def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
        pass

    def on_mouse_press(self, button, x, y, modifiers):
        '''
            "button" is one of:
                MOUSE_LEFT_BUTTON = 1
                MOUSE_MIDDLE_BUTTON = 2
                MOUSE_RIGHT_BUTTON = 4
        '''
        pass

    def on_mouse_release(self, button, x, y, modifiers):
        pass

    def on_mouse_scroll(self, dx, dy):
        pass

    def on_close(self):
        pass

    def on_mouse_enter(self, x, y):
        pass

    def on_mouse_leave(self, x, y):
        pass

    def on_expose(self):
        pass

    def on_resize(self, width, height):
        pass

    def on_move(self, x, y):
        pass

    def on_activate(self):
        pass

    def on_deactivate(self):
        pass

    def on_show(self):
        pass

    def on_hide(self):
        pass

    def on_context_lost(self):
        pass

    def on_context_state_lost(self):
        pass

class ExitHandler(object):
    '''Simple handler that detects the window close button or escape key
    press.
    '''
    exit = False
    def on_close(self):
        self.exit = True
    def on_key_press(self, symbol, modifiers):
        if symbol == pyglet.window.key.K_ESCAPE:
            self.exit = True
        return EVENT_UNHANDLED


class DebugEventHandler(object):
    def on_key_press(self, symbol, modifiers):
        print 'on_key_press(symbol=%s, modifiers=%s)' % (
            _symbol_to_string(symbol), _modifiers_to_string(modifiers))
        return EVENT_UNHANDLED

    def on_key_release(self, symbol, modifiers):
        print 'on_key_release(symbol=%s, modifiers=%s)' % (
            _symbol_to_string(symbol), _modifiers_to_string(modifiers))
        return EVENT_UNHANDLED

    def on_text(self, text):
        print 'on_text(text=%r)' % text
        return EVENT_UNHANDLED

    def on_mouse_motion(self, x, y, dx, dy):
        print 'on_mouse_motion(x=%d, y=%d, dx=%d, dy=%d)' % (x, y, dx, dy)
        return EVENT_UNHANDLED

    def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
        print 'on_mouse_drag(x=%d, y=%d, dx=%d, dy=%d, '\
                            'buttons=%s, modifiers=%s)' % (
              x, y, dx, dy, 
              _buttons_to_string(buttons),
              _modifiers_to_string(modifiers))

    def on_mouse_press(self, button, x, y, modifiers):
        print 'on_mouse_press(button=%r, x=%d, y=%d, modifiers=%s)' % (
            button, x, y, _modifiers_to_string(modifiers))
        return EVENT_UNHANDLED

    def on_mouse_release(self, button, x, y, modifiers):
        print 'on_mouse_release(button=%r, x=%d, y=%d, modifiers=%s)' % (
            button, x, y, _modifiers_to_string(modifiers))
        return EVENT_UNHANDLED

    def on_mouse_scroll(self, dx, dy):
        print 'on_mouse_scroll(dx=%f, dy=%f)' % (dx, dy)

    def on_close(self):
        print 'on_destroy()'
        return EVENT_UNHANDLED

    def on_mouse_enter(self, x, y):
        print 'on_mouse_enter(x=%d, y=%d)' % (x, y)
        return EVENT_UNHANDLED

    def on_mouse_leave(self, x, y):
        print 'on_mouse_leave(x=%d, y=%d)' % (x, y)
        return EVENT_UNHANDLED

    def on_expose(self):
        print 'on_expose()'
        return EVENT_UNHANDLED

    def on_resize(self, width, height):
        print 'on_resize(width=%d, height=%d)' % (width, height)
        return EVENT_UNHANDLED

    def on_move(self, x, y):
        print 'on_move(x=%d, y=%d)' % (x, y)
        return EVENT_UNHANDLED

    def on_activate(self):
        print 'on_activate()'
        return EVENT_UNHANDLED
<commit_msg>EVENT_UNHANDLED for on_mouse_drag and on_mouse_scroll in DebugEventHandler.<commit_after>#!/usr/bin/env python
'''
'''

__docformat__ = 'restructuredtext'
__version__ = '$Id$'

import pyglet.window.key
from pyglet.event import EVENT_HANDLED, EVENT_UNHANDLED, EventHandler

class WindowEventHandler(EventHandler):
    pass

# symbolic names for the window events
EVENT_KEY_PRESS = WindowEventHandler.register_event_type('on_key_press')
EVENT_KEY_RELEASE = WindowEventHandler.register_event_type('on_key_release')
EVENT_TEXT = WindowEventHandler.register_event_type('on_text')
EVENT_MOUSE_MOTION = WindowEventHandler.register_event_type('on_mouse_motion')
EVENT_MOUSE_DRAG = WindowEventHandler.register_event_type('on_mouse_drag')
EVENT_MOUSE_PRESS = WindowEventHandler.register_event_type('on_mouse_press')
EVENT_MOUSE_RELEASE = WindowEventHandler.register_event_type('on_mouse_release')
EVENT_MOUSE_SCROLL = WindowEventHandler.register_event_type('on_mouse_scroll')
EVENT_MOUSE_ENTER = WindowEventHandler.register_event_type('on_mouse_enter')
EVENT_MOUSE_LEAVE = WindowEventHandler.register_event_type('on_mouse_leave')
EVENT_CLOSE = WindowEventHandler.register_event_type('on_close')
EVENT_EXPOSE = WindowEventHandler.register_event_type('on_expose')
EVENT_RESIZE = WindowEventHandler.register_event_type('on_resize')
EVENT_MOVE = WindowEventHandler.register_event_type('on_move')
EVENT_ACTIVATE = WindowEventHandler.register_event_type('on_activate')
EVENT_DEACTIVATE = WindowEventHandler.register_event_type('on_deactivate')
EVENT_SHOW = WindowEventHandler.register_event_type('on_show')
EVENT_HIDE = WindowEventHandler.register_event_type('on_hide')
EVENT_CONTEXT_LOST = WindowEventHandler.register_event_type('on_context_lost')
EVENT_CONTEXT_STATE_LOST = \
    WindowEventHandler.register_event_type('on_context_state_lost')

# symbolic names for the mouse buttons
MOUSE_LEFT_BUTTON =   1 << 0
MOUSE_MIDDLE_BUTTON = 1 << 1
MOUSE_RIGHT_BUTTON =  1 << 2

def _modifiers_to_string(modifiers):
    mod_names = []
    if modifiers & pyglet.window.key.MOD_SHIFT:
        mod_names.append('MOD_SHIFT')
    if modifiers & pyglet.window.key.MOD_CTRL:
        mod_names.append('MOD_CTRL')
    if modifiers & pyglet.window.key.MOD_ALT:
        mod_names.append('MOD_ALT')
    if modifiers & pyglet.window.key.MOD_CAPSLOCK:
        mod_names.append('MOD_CAPSLOCK')
    if modifiers & pyglet.window.key.MOD_NUMLOCK:
        mod_names.append('MOD_NUMLOCK')
    if modifiers & pyglet.window.key.MOD_COMMAND:
        mod_names.append('MOD_COMMAND')
    if modifiers & pyglet.window.key.MOD_OPTION:
        mod_names.append('MOD_OPTION')
    return '|'.join(mod_names)

def _buttons_to_string(buttons):
    button_names = []
    if buttons & MOUSE_LEFT_BUTTON:
        button_names.append('MOUSE_LEFT_BUTTON')
    if buttons & MOUSE_MIDDLE_BUTTON:
        button_names.append('MOUSE_MIDDLE_BUTTON')
    if buttons & MOUSE_RIGHT_BUTTON:
        button_names.append('MOUSE_RIGHT_BUTTON')
    return '|'.join(button_names)

def _symbol_to_string(symbol):
    return pyglet.window.key._key_names.get(symbol, str(symbol))

# Does nothing, but shows prototypes.
class EventHandler(object):
    def on_key_press(self, symbol, modifiers):
        pass

    def on_key_release(self, symbol, modifiers):
        pass

    def on_text(self, text):
        pass

    def on_mouse_motion(self, x, y, dx, dy):
        pass

    def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
        pass

    def on_mouse_press(self, button, x, y, modifiers):
        '''
            "button" is one of:
                MOUSE_LEFT_BUTTON = 1
                MOUSE_MIDDLE_BUTTON = 2
                MOUSE_RIGHT_BUTTON = 4
        '''
        pass

    def on_mouse_release(self, button, x, y, modifiers):
        pass

    def on_mouse_scroll(self, dx, dy):
        pass

    def on_close(self):
        pass

    def on_mouse_enter(self, x, y):
        pass

    def on_mouse_leave(self, x, y):
        pass

    def on_expose(self):
        pass

    def on_resize(self, width, height):
        pass

    def on_move(self, x, y):
        pass

    def on_activate(self):
        pass

    def on_deactivate(self):
        pass

    def on_show(self):
        pass

    def on_hide(self):
        pass

    def on_context_lost(self):
        pass

    def on_context_state_lost(self):
        pass

class ExitHandler(object):
    '''Simple handler that detects the window close button or escape key
    press.
    '''
    exit = False
    def on_close(self):
        self.exit = True
    def on_key_press(self, symbol, modifiers):
        if symbol == pyglet.window.key.K_ESCAPE:
            self.exit = True
        return EVENT_UNHANDLED


class DebugEventHandler(object):
    def on_key_press(self, symbol, modifiers):
        print 'on_key_press(symbol=%s, modifiers=%s)' % (
            _symbol_to_string(symbol), _modifiers_to_string(modifiers))
        return EVENT_UNHANDLED

    def on_key_release(self, symbol, modifiers):
        print 'on_key_release(symbol=%s, modifiers=%s)' % (
            _symbol_to_string(symbol), _modifiers_to_string(modifiers))
        return EVENT_UNHANDLED

    def on_text(self, text):
        print 'on_text(text=%r)' % text
        return EVENT_UNHANDLED

    def on_mouse_motion(self, x, y, dx, dy):
        print 'on_mouse_motion(x=%d, y=%d, dx=%d, dy=%d)' % (x, y, dx, dy)
        return EVENT_UNHANDLED

    def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
        print 'on_mouse_drag(x=%d, y=%d, dx=%d, dy=%d, '\
                            'buttons=%s, modifiers=%s)' % (
              x, y, dx, dy, 
              _buttons_to_string(buttons),
              _modifiers_to_string(modifiers))
        return EVENT_UNHANDLED

    def on_mouse_press(self, button, x, y, modifiers):
        print 'on_mouse_press(button=%r, x=%d, y=%d, modifiers=%s)' % (
            button, x, y, _modifiers_to_string(modifiers))
        return EVENT_UNHANDLED

    def on_mouse_release(self, button, x, y, modifiers):
        print 'on_mouse_release(button=%r, x=%d, y=%d, modifiers=%s)' % (
            button, x, y, _modifiers_to_string(modifiers))
        return EVENT_UNHANDLED

    def on_mouse_scroll(self, dx, dy):
        print 'on_mouse_scroll(dx=%f, dy=%f)' % (dx, dy)
        return EVENT_UNHANDLED

    def on_close(self):
        print 'on_destroy()'
        return EVENT_UNHANDLED

    def on_mouse_enter(self, x, y):
        print 'on_mouse_enter(x=%d, y=%d)' % (x, y)
        return EVENT_UNHANDLED

    def on_mouse_leave(self, x, y):
        print 'on_mouse_leave(x=%d, y=%d)' % (x, y)
        return EVENT_UNHANDLED

    def on_expose(self):
        print 'on_expose()'
        return EVENT_UNHANDLED

    def on_resize(self, width, height):
        print 'on_resize(width=%d, height=%d)' % (width, height)
        return EVENT_UNHANDLED

    def on_move(self, x, y):
        print 'on_move(x=%d, y=%d)' % (x, y)
        return EVENT_UNHANDLED

    def on_activate(self):
        print 'on_activate()'
        return EVENT_UNHANDLED

{'fraction_non_alphanumeric': 0.10451493070438635, 'fraction_numerical': 0.0012858979854264896, 'mean_word_length': 3.4133039092055486, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4295904', 'n_tokens_mistral': 4710, 'n_tokens_neox': 4704, 'n_words': 908}