<commit_before># Module:   pygame_driver
# Date:     1st February 2009
# Author:   <NAME>, prologic at shortcircuit dot net dot au

"""PyGame Driver

A driver for the pygame library.
"""

from circuits.lib.drivers import DriverError

try:
    import pygame
    from pygame import fastevent as event
except ImportError:
    try:
        import pygame
        from pygame import event
    except ImportError:
        raise DriverError("No pygame support available.")

from circuits.core import Event, Component

class Key(Event): pass
class Quit(Event): pass
class Focus(Event): pass
class Mouse(Event): pass
class Click(Event): pass
    
class PyGameDriver(Component):

    def __tick__(self):
        self.poll()

    def poll(self):
        for e in event.get():
            if e.type == pygame.QUIT:
                self.push(Quit(), "quit")
            elif e.type == pygame.KEYDOWN:
                self.push(Key(e.key, e.mod), "keydown")
            elif e.type == pygame.KEYUP:
                self.push(Key(e.key, e.mod), "keyup")
            elif e.type == pygame.ACTIVEEVENT:
                self.push(Focus(e.state, e.gain), "focus")
            elif e.type == pygame.MOUSEMOTION:
                self.push(Mouse(e.buttons, e.pos, e.rel), "mouse")
            elif e.type == pygame.MOUSEBUTTONDOWN:
                self.push(Click(e.button, e.pos), "click")
            elif e.type == pygame.MOUSEBUTTONUP:
                self.push(Click(e.button, e.pos), "click")
            else:
                self.push(Unknown(e), "unknown")<commit_msg>lib.drivers.pygame_driver: Initialize the pygame event system.<commit_after># Module:   pygame_driver
# Date:     1st February 2009
# Author:   <NAME>, prologic at shortcircuit dot net dot au

"""PyGame Driver

A driver for the pygame library.
"""

from circuits.lib.drivers import DriverError

try:
    import pygame
    from pygame import fastevent as event
except ImportError:
    try:
        import pygame
        from pygame import event
    except ImportError:
        raise DriverError("No pygame support available.")

from circuits.core import Event, Component

class Key(Event): pass
class Quit(Event): pass
class Focus(Event): pass
class Mouse(Event): pass
class Click(Event): pass
    
class PyGameDriver(Component):

    def __new__(cls, *args, **kwargs):
        self = super(PyGameDriver, cls).__new__(cls, *args, **kwargs)
        event.init()
        return self

    def __tick__(self):
        self.poll()

    def poll(self):
        for e in event.get():
            if e.type == pygame.QUIT:
                self.push(Quit(), "quit")
            elif e.type == pygame.KEYDOWN:
                self.push(Key(e.key, e.mod), "keydown")
            elif e.type == pygame.KEYUP:
                self.push(Key(e.key, e.mod), "keyup")
            elif e.type == pygame.ACTIVEEVENT:
                self.push(Focus(e.state, e.gain), "focus")
            elif e.type == pygame.MOUSEMOTION:
                self.push(Mouse(e.buttons, e.pos, e.rel), "mouse")
            elif e.type == pygame.MOUSEBUTTONDOWN:
                self.push(Click(e.button, e.pos), "click")
            elif e.type == pygame.MOUSEBUTTONUP:
                self.push(Click(e.button, e.pos), "click")
            else:
                self.push(Unknown(e), "unknown")
{'fraction_non_alphanumeric': 0.11880290205562273, 'fraction_numerical': 0.003022974607013301, 'mean_word_length': 2.2095053346265763, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '7541572', 'n_tokens_mistral': 1035, 'n_tokens_neox': 1005, 'n_words': 274}