changeset 13:f5846a46e9c5

Add base class for user events.
author Simon Cross <hodgestar@gmail.com>
date Sun, 11 Sep 2011 13:22:14 +0200
parents 0196455fa432
children 4e0d6ebf9127
files mamba/engine.py
diffstat 1 files changed, 15 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mamba/engine.py	Sun Sep 11 13:11:52 2011 +0200
+++ b/mamba/engine.py	Sun Sep 11 13:22:14 2011 +0200
@@ -2,7 +2,7 @@
 
 import pygame.event
 import pygame.display
-from pygame.locals import QUIT
+from pygame.locals import QUIT, USEREVENT
 
 
 class Engine(object):
@@ -19,3 +19,17 @@
                 if ev.type is QUIT:
                     return
             flip()
+
+
+class UserEvent(object):
+
+    utype = "UNKNOWN"
+
+    @classmethod
+    def post(cls, **kws):
+        ev = pygame.event.Event(USEREVENT, utype=cls.utype, **kws)
+        pygame.event.post(ev)
+
+    @classmethod
+    def matches(cls, ev):
+        return ev.type is USEREVENT and ev.utype == cls.utype