--- a/sdlterm/cython/sdlterm.pyx Sat Jan 05 00:40:27 2013 +0100
+++ b/sdlterm/cython/sdlterm.pyx Sat Jan 05 12:40:32 2013 +0100
@@ -10,11 +10,27 @@
cdef extern from "sdlterm.h":
- enum EventType:
- pass
+ cdef struct Event_key:
+ char *keyname
+ Py_UNICODE unicode
+
+ cdef struct Event_mouse:
+ int x, y
+ int button
- union Event:
- EventType type
+ cdef struct Event:
+ # enum
+ int QUIT
+ int RESIZE
+ int KEYPRESS
+ int MOUSEDOWN
+ int MOUSEUP
+ int MOUSEMOVE
+ int MOUSEWHEEL
+
+ int type
+ Event_key key
+ Event_mouse mouse
cdef cppclass Terminal:
Terminal() except +
@@ -34,6 +50,9 @@
void get_next_event(Event event)
+ int get_width()
+ int get_height()
+
cdef class SDLTerminal:
cdef Terminal *thisptr # hold a C++ instance which we're wrapping
@@ -60,5 +79,28 @@
def get_next_event(self):
cdef Event event
self.thisptr.get_next_event(event)
- return dict()
+ if event.type == event.MOUSEMOVE:
+ return ('mousemove', event.mouse.x, event.mouse.y)
+ if event.type == event.MOUSEDOWN:
+ return ('mousedown', event.mouse.x, event.mouse.y, event.mouse.button)
+ if event.type == event.MOUSEUP:
+ return ('mouseup', event.mouse.x, event.mouse.y, event.mouse.button)
+ if event.type == event.KEYPRESS:
+ keyname = event.key.keyname
+ if keyname:
+ keyname = keyname.decode()
+ else:
+ keyname = None
+ char = event.key.unicode
+ if char == '\x00':
+ char = None
+ return ('keypress', keyname, char)
+ if event.type == event.QUIT:
+ return ('quit',)
+ return ('unknown',)
+ property width:
+ def __get__(self): return self.thisptr.get_width()
+ property height:
+ def __get__(self): return self.thisptr.get_height()
+