<commit_before><commit_msg>Add pyglet/window/event.py.  Whoops.<commit_after>#!/usr/bin/env python

'''
'''

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

import pyglet.window.key

EVENT_HANDLED = None 
EVENT_UNHANDLED = 1 

EVENT_KEYPRESS = 1
EVENT_KEYRELEASE = 2
EVENT_TEXT = 3

_event_types = {
    'on_keypress': EVENT_KEYPRESS,
    'on_keyrelease': EVENT_KEYRELEASE,
    'on_text': EVENT_TEXT
}

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')
    return '+'.join(mod_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_keypress(self, symbol, modifiers):
        pass

    def on_keyrelease(self, symbol, modifiers):
        pass

    def on_text(self, text):
        pass

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

    def on_keyrelease(self, symbol, modifiers):
        print 'on_keyrelease(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


{'fraction_non_alphanumeric': 0.11038607939097335, 'fraction_numerical': 0.002175095160413268, 'mean_word_length': 3.3914081145584727, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2189051', 'n_tokens_mistral': 643, 'n_tokens_neox': 627, 'n_words': 110}