demo_input.py
changeset 55 1ab0edd5d784
parent 45 43b2279b06e1
child 62 2f61931520c9
--- a/demo_input.py	Sun Jan 06 23:03:24 2013 +0100
+++ b/demo_input.py	Mon Jan 07 00:23:45 2013 +0100
@@ -4,24 +4,29 @@
 import locale
 locale.setlocale(locale.LC_ALL, '')
 
-from tuikit import *
+from tuikit import Application, TextEdit
 
 
 class MyApplication(Application):
     def __init__(self):
         Application.__init__(self)
-        self.top.add_handler('keypress', self.on_top_keypress)
 
         self.text = ''
-        textedit = TextEdit(100, 40, self.text)
-        self.top.add(textedit)
-        textedit.x = 2
-        self.textedit = textedit
+        self.textedit = TextEdit(100, 40, self.text)
+        self.top.add(self.textedit)
+        self.textedit.x = 2
 
-    def on_top_keypress(self, ev):
-        if ev.char == 'q':
+        editbox = self.textedit.editbox
+        editbox.add_handler('keypress', self.on_any_input)
+        editbox.add_handler('mousedown', self.on_any_input)
+        editbox.add_handler('mouseup', self.on_any_input)
+        editbox.add_handler('mousewheel', self.on_any_input)
+        editbox.add_handler('mousemove', self.on_any_input)
+
+    def on_any_input(self, ev):
+        if ev.event_name == 'keypress' and ev.char == 'q':
             self.terminate()
-        self.text += 'keyname: %(keyname)s  char: %(char)s\n' % ev
+        self.text += ''.join((ev.event_name.ljust(10), ' : ', repr(ev), '\n'))
         self.textedit.settext(self.text)
         self.textedit.scrolltoend()
         return True