tuikit/driver_sdl.py
changeset 48 1f00e90fd72a
child 50 c5b8b9d2da95
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tuikit/driver_sdl.py	Sat Jan 05 12:40:32 2013 +0100
@@ -0,0 +1,93 @@
+# -*- coding: utf-8 -*-
+'''SDL driver.
+
+Requires C++ extension module.
+See sdlterm directory.
+
+'''
+
+from tuikit.driver import Driver
+
+import logging
+
+import sys
+sys.path.insert(0, 'sdlterm/build/lib.linux-x86_64-3.2')
+from sdlterm import SDLTerminal
+
+
+class DriverSDL(Driver):
+
+    '''SDL driver class'''
+
+    def __init__(self):
+        '''Initialize instance attributes'''
+        Driver.__init__(self)
+        self.log = logging.getLogger('tuikit')
+        self.sdlterm = SDLTerminal()
+
+    def start(self, mainfunc):
+        '''Start driver and run mainfunc.'''
+        self.sdlterm.resize(800, 600)
+        self.sdlterm.select_font("sdlterm/font/DejaVuSansMono.ttf", "sdlterm/font/DejaVuSansMono-Bold.ttf", 12)
+        self.size.w, self.size.h = self.sdlterm.width, self.sdlterm.height
+        mainfunc()
+
+
+    ## input ##
+
+    def getevents(self, timeout=None):
+        '''Process input, return list of events.'''
+        event = self.sdlterm.get_next_event()
+        return [event]
+
+
+    ## drawing ##
+
+    def erase(self):
+        '''Clear screen.'''
+        self.sdlterm.erase()
+
+    def putch(self, x, y, c):
+        '''Output one unicode character to specified coordinates.'''
+        if not self.clipstack.test(x, y):
+            return
+        self.sdlterm.putch(x, y, c)
+
+    def commit(self):
+        '''Commit changes to the screen.'''
+        self.sdlterm.commit()
+
+
+    ## colors ##
+
+    def setcolor(self, name, desc):
+        '''Define color name.
+
+        name - name of color (e.g. 'normal', 'active')
+        desc - color description - foreground, background, attributes (e.g. 'black on white, bold')
+
+        '''
+        self.log.info('DummyDriver.setcolor(name=%r, desc=%r)', name, desc)
+
+    def pushcolor(self, name):
+        '''Add color on top of stack and use this color for following output.'''
+        self.log.info('DummyDriver.pushcolor(name=%r)', name)
+
+    def popcolor(self):
+        '''Remove color from top of stack and use new top color for following output.'''
+        self.log.info('DummyDriver.popcolor()')
+
+
+    ## cursor ##
+
+    def showcursor(self, x, y):
+        '''Set cursor to be shown at x, y coordinates.'''
+        self.log.info('DummyDriver.showcursor(x=%r, y=%r)', x, y)
+
+    def hidecursor(self):
+        '''Hide cursor.'''
+        self.log.info('DummyDriver.hidecursor()')
+
+
+driverclass = DriverSDL
+