2 '''Dummy driver. |
2 '''Dummy driver. |
3 |
3 |
4 Implements basic driver interface. |
4 Implements basic driver interface. |
5 This is useful for debugging or when writing new driver. |
5 This is useful for debugging or when writing new driver. |
6 |
6 |
7 @author: Radek Brich <radek.brich@devl.cz> |
|
8 |
|
9 ''' |
7 ''' |
10 |
8 |
11 import logging |
9 import logging |
12 |
10 |
13 from tuikit.common import Size, ClipStack |
11 from tuikit.driver import Driver |
14 |
12 |
15 |
13 |
16 class DriverDummy: |
14 class DriverDummy(Driver): |
17 |
15 |
18 '''Dummy driver class''' |
16 '''Dummy driver class''' |
19 |
17 |
20 def __init__(self): |
18 def __init__(self): |
21 '''Initialize instance attributes''' |
19 '''Initialize instance attributes''' |
|
20 Driver.__init__(self) |
22 self.log = logging.getLogger('tuikit') |
21 self.log = logging.getLogger('tuikit') |
23 self.size = Size() |
22 self.size.w, self.size.h = 80, 25 |
24 self.clipstack = ClipStack() |
|
25 |
23 |
26 def start(self, mainfunc): |
24 def start(self, mainfunc): |
27 '''Start driver and run mainfunc.''' |
25 '''Start driver and run mainfunc.''' |
28 self.size.w, self.size.h = 80, 25 |
|
29 mainfunc() |
26 mainfunc() |
30 |
27 |
31 |
28 |
32 # colors |
29 ## input ## |
|
30 |
|
31 def getevents(self, timeout=None): |
|
32 '''Process input, return list of events. |
|
33 |
|
34 This dummy implementation just returns 'q' and Escape key presses. |
|
35 |
|
36 ''' |
|
37 events = [('keypress', None, 'q'), ('keypress', 'escape', None)] |
|
38 return events |
|
39 |
|
40 |
|
41 ## drawing ## |
|
42 |
|
43 def erase(self): |
|
44 '''Clear screen.''' |
|
45 self.log.info('DummyDriver.erase()') |
|
46 |
|
47 def putch(self, x, y, c): |
|
48 '''Output one unicode character to specified coordinates.''' |
|
49 self.log.info('DummyDriver.putch(x=%r, y=%r, c=%r)', x, y, c) |
|
50 |
|
51 def commit(self): |
|
52 '''Commit changes to the screen.''' |
|
53 self.log.info('DummyDriver.commit()') |
|
54 |
|
55 |
|
56 ## colors ## |
33 |
57 |
34 def setcolor(self, name, desc): |
58 def setcolor(self, name, desc): |
35 '''Define color name. |
59 '''Define color name. |
36 |
60 |
37 name - name of color (e.g. 'normal', 'active') |
61 name - name of color (e.g. 'normal', 'active') |
39 |
63 |
40 ''' |
64 ''' |
41 self.log.info('DummyDriver.setcolor(name=%r, desc=%r)', name, desc) |
65 self.log.info('DummyDriver.setcolor(name=%r, desc=%r)', name, desc) |
42 |
66 |
43 def pushcolor(self, name): |
67 def pushcolor(self, name): |
|
68 '''Add color on top of stack and use this color for following output.''' |
44 self.log.info('DummyDriver.pushcolor(name=%r)', name) |
69 self.log.info('DummyDriver.pushcolor(name=%r)', name) |
45 |
70 |
46 def popcolor(self): |
71 def popcolor(self): |
|
72 '''Remove color from top of stack and use new top color for following output.''' |
47 self.log.info('DummyDriver.popcolor()') |
73 self.log.info('DummyDriver.popcolor()') |
48 |
74 |
49 |
75 |
50 # drawing |
76 ## cursor ## |
51 |
|
52 def erase(self): |
|
53 '''Clear screen.''' |
|
54 self.log.info('DummyDriver.erase()') |
|
55 |
77 |
56 def puts(self, x, y, s): |
78 def showcursor(self, x, y): |
57 '''Output string to specified coordinates.''' |
79 '''Set cursor to be shown at x, y coordinates.''' |
58 self.log.info('DummyDriver.puts(x=%r, y=%r, s=%r)', x, y, s) |
80 self.log.info('DummyDriver.showcursor(x=%r, y=%r)', x, y) |
59 |
81 |
60 def commit(self): |
82 def hidecursor(self): |
61 '''Commit changes to the screen.''' |
83 '''Hide cursor.''' |
62 self.log.info('DummyDriver.commit()') |
84 self.log.info('DummyDriver.hidecursor()') |
63 |
85 |
64 |
|
65 # input |
|
66 |
|
67 def process_input(self, timeout=None): |
|
68 '''Process input, return list of events. |
|
69 |
|
70 This dummy implementation just returns 'q' and Escape key presses. |
|
71 |
|
72 ''' |
|
73 events = [('keypress', None, 'q'), ('keypress', 'escape', None)] |
|
74 return events |
|
75 |
|