Skip to content

Commit 1eba14e

Browse files
committed
Add event poll sufficient to run example, but not real match
1 parent e52a8bf commit 1eba14e

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

examples/termbox/termbox.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
Implementation notes:
1111
[ ] tdl.init() needs a window, made 132x60
1212
[ ] Termbox.close() is not implemented, does nothing
13-
13+
[ ] poll_event needs review, because it does not
14+
completely follows the original logic
1415
1516
"""
1617

@@ -131,6 +132,20 @@ def __str__(self):
131132
EVENT_RESIZE = 2
132133
EVENT_MOUSE = 3
133134

135+
class Event:
136+
""" Aggregate for Termbox Event structure """
137+
type = None
138+
ch = None
139+
key = None
140+
mod = None
141+
width = None
142+
height = None
143+
mousex = None
144+
mousey = None
145+
146+
def gettuple(self):
147+
return (self.type, self.ch, self.key, self.mod, self.width, self.height, self.mousex, self.mousey)
148+
134149
class Termbox:
135150
def __init__(self, width=132, height=60):
136151
global _instance
@@ -142,6 +157,8 @@ def __init__(self, width=132, height=60):
142157
except tdl.TDLException as e:
143158
raise TermboxException(e)
144159

160+
self.e = Event() # cache for event data
161+
145162
_instance = self
146163

147164
def __del__(self):
@@ -247,4 +264,11 @@ def poll_event(self):
247264
else:
248265
uch = None
249266
"""
250-
return (e.type, uch, e.key, e.mod, e.w, e.h, e.x, e.y)
267+
for e in tdl.event.get():
268+
# [ ] not all events are passed thru
269+
self.e.type = e.type
270+
if e.type == 'KEYDOWN':
271+
self.e.key = e.key
272+
return self.e.gettuple()
273+
274+
#return (e.type, uch, e.key, e.mod, e.w, e.h, e.x, e.y)

0 commit comments

Comments
 (0)