Update utf8 character input to Python3. Reorganize tests.
authorRadek Brich <radek.brich@devl.cz>
Fri, 07 Oct 2011 12:36:14 +0200
changeset 20 472a753664f9
parent 19 5e78d52ebb24
child 21 8553a6bd2d82
Update utf8 character input to Python3. Reorganize tests.
.hgignore
demo_input.py
tests/curses_getkey.py
tests/curses_keycodes.py
tests/curses_mouse.py
tests/curses_unicode.py
tests/input.py
tests/keycodes.py
tests/mouse.py
tests/unicode.py
tuikit/backend_curses.py
--- a/.hgignore	Fri Oct 07 12:02:33 2011 +0200
+++ b/.hgignore	Fri Oct 07 12:36:14 2011 +0200
@@ -2,3 +2,7 @@
 tuikit/.*\.pyc
 docs/_build
 tuikit\.log
+old
+\.project
+\.pydevproject
+\.settings
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/demo_input.py	Fri Oct 07 12:36:14 2011 +0200
@@ -0,0 +1,33 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+import locale
+locale.setlocale(locale.LC_ALL, '')
+
+from tuikit import *
+
+
+class MyApplication(Application):
+    def __init__(self):
+        Application.__init__(self)
+        self.top.connect('keypress', self.globalkeypress)
+
+        self.text = ''
+        textedit = TextEdit(100, 40, self.text)
+        self.top.add(textedit)
+        textedit.x = 2
+        self.textedit = textedit
+
+
+    def globalkeypress(self, keyname, char):
+        if char == 'q':
+            self.terminate()
+        self.text += 'keyname: %s  char: %s\n' % (keyname, char)
+        self.textedit.settext(self.text)
+        self.textedit.scrolltoend()
+
+
+if __name__ == '__main__':
+    app = MyApplication()
+    app.start()
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/curses_getkey.py	Fri Oct 07 12:36:14 2011 +0200
@@ -0,0 +1,18 @@
+#!/usr/bin/python
+# coding=UTF-8
+
+import curses
+import locale
+
+locale.setlocale(locale.LC_ALL, "")
+
+def doStuff(stdscr):
+  message = "Press 'q' to quit.\n"
+  stdscr.addstr(0, 0, message, 0)
+  while True:
+    c = stdscr.getkey() # pauses until a key's hit
+    if c == 'q':
+      break
+    stdscr.addstr('%s %r\n' % (c, c))
+
+curses.wrapper(doStuff)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/curses_keycodes.py	Fri Oct 07 12:36:14 2011 +0200
@@ -0,0 +1,28 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+import curses
+import locale
+
+locale.setlocale(locale.LC_ALL,"")
+
+def doStuff(screen):
+    screen.addstr('termname: %s\n' % curses.termname())
+    screen.keypad(0)
+    screen.scrollok(1)
+    curses.nl()
+    curses.mousemask(curses.ALL_MOUSE_EVENTS | curses.REPORT_MOUSE_POSITION)
+    while True:
+        c = screen.getch()
+
+        screen.nodelay(1)
+        while c != -1:
+            screen.addstr('0x%02x,' % c)
+            c = screen.getch()
+        screen.nodelay(0)
+
+        screen.addstr('\n')
+
+        screen.refresh()
+
+curses.wrapper(doStuff)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/curses_mouse.py	Fri Oct 07 12:36:14 2011 +0200
@@ -0,0 +1,29 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+import curses
+import locale
+
+locale.setlocale(locale.LC_ALL,"")
+
+def doStuff(screen):
+    screen.addstr('%s\n' % curses.termname())
+    screen.keypad(1)
+    screen.scrollok(1)
+    curses.nl()
+    curses.mousemask(curses.ALL_MOUSE_EVENTS | curses.REPORT_MOUSE_POSITION)
+    curses.mouseinterval(0)  # do not wait to detect clicks, we use only press/release
+    while True:
+        c = screen.getch()
+        char = ' '
+        if c < 256:
+            char = curses.unctrl(c)
+        screen.addstr('key: %x %s\n' % (c, char))
+
+        if c == curses.KEY_MOUSE:
+            m = curses.getmouse()
+            screen.addstr('(%d %d %d %d %x)\n' % m)
+
+        screen.refresh()
+
+curses.wrapper(doStuff)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/curses_unicode.py	Fri Oct 07 12:36:14 2011 +0200
@@ -0,0 +1,18 @@
+#!/usr/bin/python
+# coding=UTF-8
+
+import curses
+import locale
+
+locale.setlocale(locale.LC_ALL, "")
+
+def doStuff(stdscr):
+  message = "Žlutý kůň.\nPress 'q' to quit.\n"
+  stdscr.addstr(0, 0, message, 0)
+  while True:
+    c = stdscr.getch() # pauses until a key's hit
+    if c == ord('q'):
+      break
+    stdscr.addch(c)
+
+curses.wrapper(doStuff)
--- a/tests/input.py	Fri Oct 07 12:02:33 2011 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,33 +0,0 @@
-#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
-
-import locale
-locale.setlocale(locale.LC_ALL, '')
-
-from tuikit import *
-
-
-class MyApplication(Application):
-    def __init__(self):
-        Application.__init__(self)
-        self.top.connect('keypress', self.globalkeypress)
-
-        self.text = ''
-        textedit = TextEdit(100, 40, self.text)
-        self.top.add(textedit)
-        textedit.x = 2
-        self.textedit = textedit
-
-
-    def globalkeypress(self, keyname, char):
-        if char == 'q':
-            self.terminate()
-        self.text += 'keyname: %s  char: %s\n' % (keyname, char)
-        self.textedit.settext(self.text)
-        self.textedit.scrolltoend()
-
-
-if __name__ == '__main__':
-    app = MyApplication()
-    app.start()
-
--- a/tests/keycodes.py	Fri Oct 07 12:02:33 2011 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,28 +0,0 @@
-#!/usr/bin/python
-# -*- coding: utf-8 -*-
-
-import curses
-import locale
-
-locale.setlocale(locale.LC_ALL,"")
-
-def doStuff(screen):
-    screen.addstr('termname: %s\n' % curses.termname())
-    screen.keypad(0)
-    screen.scrollok(1)
-    curses.nl()
-    curses.mousemask(curses.ALL_MOUSE_EVENTS | curses.REPORT_MOUSE_POSITION)
-    while True:
-        c = screen.getch()
-
-        screen.nodelay(1)
-        while c != -1:
-            screen.addstr('0x%02x,' % c)
-            c = screen.getch()
-        screen.nodelay(0)
-
-        screen.addstr('\n')
-
-        screen.refresh()
-
-curses.wrapper(doStuff)
--- a/tests/mouse.py	Fri Oct 07 12:02:33 2011 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,29 +0,0 @@
-#!/usr/bin/python
-# -*- coding: utf-8 -*-
-
-import curses
-import locale
-
-locale.setlocale(locale.LC_ALL,"")
-
-def doStuff(screen):
-    screen.addstr('%s\n' % curses.termname())
-    screen.keypad(1)
-    screen.scrollok(1)
-    curses.nl()
-    curses.mousemask(curses.ALL_MOUSE_EVENTS | curses.REPORT_MOUSE_POSITION)
-    curses.mouseinterval(0)  # do not wait to detect clicks, we use only press/release
-    while True:
-        c = screen.getch()
-        char = ' '
-        if c < 256:
-            char = curses.unctrl(c)
-        screen.addstr('key: %x %s\n' % (c, char))
-
-        if c == curses.KEY_MOUSE:
-            m = curses.getmouse()
-            screen.addstr('(%d %d %d %d %x)\n' % m)
-
-        screen.refresh()
-
-curses.wrapper(doStuff)
--- a/tests/unicode.py	Fri Oct 07 12:02:33 2011 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,18 +0,0 @@
-#!/usr/bin/python
-# coding=UTF-8
-
-import curses
-import locale
-
-locale.setlocale(locale.LC_ALL, "")
-
-def doStuff(stdscr):
-  message = "Žlutý kůň.\nPress 'q' to quit.\n"
-  stdscr.addstr(0, 0, message, 0)
-  while True:
-    c = stdscr.getch() # pauses until a key's hit
-    if c == ord('q'):
-      break
-    stdscr.addch(c)
-
-curses.wrapper(doStuff)
--- a/tuikit/backend_curses.py	Fri Oct 07 12:02:33 2011 +0200
+++ b/tuikit/backend_curses.py	Fri Oct 07 12:36:14 2011 +0200
@@ -448,12 +448,12 @@
 
     def process_utf8_chars(self):
         #FIXME read exact number of chars as defined by utf-8
-        utf = ''
+        utf = []
         while len(utf) <= 6:
             c = self.inputqueue_get_wait()
-            utf += chr(c)
+            utf.append(c)
             try:
-                uni = str(utf, 'utf-8')
+                uni = str(bytes(utf), 'utf-8')
                 return [('keypress', None, uni)]
             except UnicodeDecodeError:
                 continue