tuikit/driver_dummy.py
author Radek Brich <radek.brich@devl.cz>
Wed, 03 Sep 2014 21:56:20 +0200
changeset 113 6796adfdc7eb
parent 82 2bead23b1262
permissions -rw-r--r--
Merge. Due to my schizophrenia, I've accidentally forked my own code. The other set of changes were found in another computer.

# -*- coding: utf-8 -*-
'''Dummy driver.

Implements basic driver interface.
This is useful for debugging or when writing new driver.

'''

import logging

from tuikit.driver_base import Driver


class DriverDummy(Driver):

    '''Dummy driver class'''

    def __init__(self):
        '''Initialize instance attributes'''
        Driver.__init__(self)
        self.log = logging.getLogger('tuikit')
        self.size.w, self.size.h = 80, 25

    def start(self, mainfunc):
        '''Start driver and run mainfunc.'''
        mainfunc()


    ## input ##

    def getevents(self, timeout=None):
        '''Process input, return list of events.

        timeout -- float, in seconds

        This dummy implementation just returns 'q' and Escape key presses.

        '''
        events = [('keypress', None, 'q'), ('keypress', 'escape', None)]
        return events


    ## drawing ##

    def erase(self):
        '''Clear screen.'''
        self.log.info('DummyDriver.erase()')

    def putch(self, x, y, c):
        '''Output one unicode character to specified coordinates.'''
        if not self.clipstack.test(x, y):
            return
        self.log.info('DummyDriver.putch(x=%r, y=%r, c=%r)', x, y, c)

    def commit(self):
        '''Commit changes to the screen.'''
        self.log.info('DummyDriver.commit()')


    ## colors ##

    def defcolor(self, name, desc):
        '''Define color name.

        Args:
            name: name of color (e.g. 'normal', 'active')
            desc: color description - foreground, background, attributes
                Format: '<fg> [on <bg>][, <attr>[, <attr> ...]]
                eg. 'white on black, bold'

        '''
        self.log.info('DummyDriver.defcolor(name=%r, desc=%r)', name, desc)

    def setcolor(self, name):
        """Set defined color.

        Previous color is forgotten.
        Color prefix is ignored.

        See pushcolor, popcolor for more advanced work with colors.

        """
        self.log.info('DummyDriver.setcolor(name=%r)', name)

    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 = DriverDummy