author | Radek Brich <radek.brich@devl.cz> |
Sat, 15 Mar 2014 11:05:12 +0100 | |
changeset 83 | ebe732b9ef19 |
parent 82 | tuikit/driver_base.py@2bead23b1262 |
child 84 | 04dfb5ddf031 |
permissions | -rw-r--r-- |
24
b248ef500557
Add DriverPygame (incomplete). Move unicode graphics constants to UnicodeGraphics class. Move shared parts of drivers to Driver base class.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
1 |
# -*- coding: utf-8 -*- |
b248ef500557
Add DriverPygame (incomplete). Move unicode graphics constants to UnicodeGraphics class. Move shared parts of drivers to Driver base class.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
2 |
|
83
ebe732b9ef19
Refactor Driver, CursesDriver: init, close, draw.
Radek Brich <radek.brich@devl.cz>
parents:
82
diff
changeset
|
3 |
from tuikit.common import Size, ClipStack |
24
b248ef500557
Add DriverPygame (incomplete). Move unicode graphics constants to UnicodeGraphics class. Move shared parts of drivers to Driver base class.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
4 |
|
b248ef500557
Add DriverPygame (incomplete). Move unicode graphics constants to UnicodeGraphics class. Move shared parts of drivers to Driver base class.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
5 |
|
b248ef500557
Add DriverPygame (incomplete). Move unicode graphics constants to UnicodeGraphics class. Move shared parts of drivers to Driver base class.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
6 |
class Driver: |
41
37b7dfc3eae6
Update Emitter: All event handlers now have exactly one argument: object inherited from Event class, which carries any data.
Radek Brich <radek.brich@devl.cz>
parents:
27
diff
changeset
|
7 |
|
83
ebe732b9ef19
Refactor Driver, CursesDriver: init, close, draw.
Radek Brich <radek.brich@devl.cz>
parents:
82
diff
changeset
|
8 |
"""Driver base class. |
ebe732b9ef19
Refactor Driver, CursesDriver: init, close, draw.
Radek Brich <radek.brich@devl.cz>
parents:
82
diff
changeset
|
9 |
|
ebe732b9ef19
Refactor Driver, CursesDriver: init, close, draw.
Radek Brich <radek.brich@devl.cz>
parents:
82
diff
changeset
|
10 |
Defines common interface. |
ebe732b9ef19
Refactor Driver, CursesDriver: init, close, draw.
Radek Brich <radek.brich@devl.cz>
parents:
82
diff
changeset
|
11 |
|
ebe732b9ef19
Refactor Driver, CursesDriver: init, close, draw.
Radek Brich <radek.brich@devl.cz>
parents:
82
diff
changeset
|
12 |
""" |
41
37b7dfc3eae6
Update Emitter: All event handlers now have exactly one argument: object inherited from Event class, which carries any data.
Radek Brich <radek.brich@devl.cz>
parents:
27
diff
changeset
|
13 |
|
24
b248ef500557
Add DriverPygame (incomplete). Move unicode graphics constants to UnicodeGraphics class. Move shared parts of drivers to Driver base class.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
14 |
def __init__(self): |
41
37b7dfc3eae6
Update Emitter: All event handlers now have exactly one argument: object inherited from Event class, which carries any data.
Radek Brich <radek.brich@devl.cz>
parents:
27
diff
changeset
|
15 |
#: Screen size. |
24
b248ef500557
Add DriverPygame (incomplete). Move unicode graphics constants to UnicodeGraphics class. Move shared parts of drivers to Driver base class.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
16 |
self.size = Size() |
41
37b7dfc3eae6
Update Emitter: All event handlers now have exactly one argument: object inherited from Event class, which carries any data.
Radek Brich <radek.brich@devl.cz>
parents:
27
diff
changeset
|
17 |
#: Clipping region stack. |
24
b248ef500557
Add DriverPygame (incomplete). Move unicode graphics constants to UnicodeGraphics class. Move shared parts of drivers to Driver base class.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
18 |
self.clipstack = ClipStack() |
41
37b7dfc3eae6
Update Emitter: All event handlers now have exactly one argument: object inherited from Event class, which carries any data.
Radek Brich <radek.brich@devl.cz>
parents:
27
diff
changeset
|
19 |
#: Stack of color prefixes. |
27
139d1241b4c5
DriverPygame: add colors, make window resizable.
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
20 |
self.colorprefix = [] |
24
b248ef500557
Add DriverPygame (incomplete). Move unicode graphics constants to UnicodeGraphics class. Move shared parts of drivers to Driver base class.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
21 |
|
83
ebe732b9ef19
Refactor Driver, CursesDriver: init, close, draw.
Radek Brich <radek.brich@devl.cz>
parents:
82
diff
changeset
|
22 |
def init(self): |
ebe732b9ef19
Refactor Driver, CursesDriver: init, close, draw.
Radek Brich <radek.brich@devl.cz>
parents:
82
diff
changeset
|
23 |
"""Initialize the driver and screen.""" |
ebe732b9ef19
Refactor Driver, CursesDriver: init, close, draw.
Radek Brich <radek.brich@devl.cz>
parents:
82
diff
changeset
|
24 |
pass |
ebe732b9ef19
Refactor Driver, CursesDriver: init, close, draw.
Radek Brich <radek.brich@devl.cz>
parents:
82
diff
changeset
|
25 |
|
ebe732b9ef19
Refactor Driver, CursesDriver: init, close, draw.
Radek Brich <radek.brich@devl.cz>
parents:
82
diff
changeset
|
26 |
def close(self): |
ebe732b9ef19
Refactor Driver, CursesDriver: init, close, draw.
Radek Brich <radek.brich@devl.cz>
parents:
82
diff
changeset
|
27 |
"""Clean up the screen etc.""" |
ebe732b9ef19
Refactor Driver, CursesDriver: init, close, draw.
Radek Brich <radek.brich@devl.cz>
parents:
82
diff
changeset
|
28 |
pass |
ebe732b9ef19
Refactor Driver, CursesDriver: init, close, draw.
Radek Brich <radek.brich@devl.cz>
parents:
82
diff
changeset
|
29 |
|
ebe732b9ef19
Refactor Driver, CursesDriver: init, close, draw.
Radek Brich <radek.brich@devl.cz>
parents:
82
diff
changeset
|
30 |
def draw(self, buffer, x=0, y=0): |
ebe732b9ef19
Refactor Driver, CursesDriver: init, close, draw.
Radek Brich <radek.brich@devl.cz>
parents:
82
diff
changeset
|
31 |
for bufy in range(buffer.size.h): |
ebe732b9ef19
Refactor Driver, CursesDriver: init, close, draw.
Radek Brich <radek.brich@devl.cz>
parents:
82
diff
changeset
|
32 |
for bufx in range(buffer.size.w): |
ebe732b9ef19
Refactor Driver, CursesDriver: init, close, draw.
Radek Brich <radek.brich@devl.cz>
parents:
82
diff
changeset
|
33 |
print(buffer.get(bufx, bufy)[0], end='') |
ebe732b9ef19
Refactor Driver, CursesDriver: init, close, draw.
Radek Brich <radek.brich@devl.cz>
parents:
82
diff
changeset
|
34 |
print() |
ebe732b9ef19
Refactor Driver, CursesDriver: init, close, draw.
Radek Brich <radek.brich@devl.cz>
parents:
82
diff
changeset
|
35 |
|
24
b248ef500557
Add DriverPygame (incomplete). Move unicode graphics constants to UnicodeGraphics class. Move shared parts of drivers to Driver base class.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
36 |
|
27
139d1241b4c5
DriverPygame: add colors, make window resizable.
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
37 |
## drawing ## |
41
37b7dfc3eae6
Update Emitter: All event handlers now have exactly one argument: object inherited from Event class, which carries any data.
Radek Brich <radek.brich@devl.cz>
parents:
27
diff
changeset
|
38 |
|
77
fc1989059e19
Propagate "quit" event, do not just terminate application. Resize: flag widgets to be resized, do resizes only once before draw. Draw: flag widgets to be redrawn, do not draw everything on any event.
Radek Brich <radek.brich@devl.cz>
parents:
41
diff
changeset
|
39 |
def fill_clip(self, c=' '): |
fc1989059e19
Propagate "quit" event, do not just terminate application. Resize: flag widgets to be resized, do resizes only once before draw. Draw: flag widgets to be redrawn, do not draw everything on any event.
Radek Brich <radek.brich@devl.cz>
parents:
41
diff
changeset
|
40 |
"""Fill current clip region.""" |
fc1989059e19
Propagate "quit" event, do not just terminate application. Resize: flag widgets to be resized, do resizes only once before draw. Draw: flag widgets to be redrawn, do not draw everything on any event.
Radek Brich <radek.brich@devl.cz>
parents:
41
diff
changeset
|
41 |
rect = self.clipstack.top() |
fc1989059e19
Propagate "quit" event, do not just terminate application. Resize: flag widgets to be resized, do resizes only once before draw. Draw: flag widgets to be redrawn, do not draw everything on any event.
Radek Brich <radek.brich@devl.cz>
parents:
41
diff
changeset
|
42 |
self.fill(rect.x, rect.y, rect.w, rect.h, c) |
fc1989059e19
Propagate "quit" event, do not just terminate application. Resize: flag widgets to be resized, do resizes only once before draw. Draw: flag widgets to be redrawn, do not draw everything on any event.
Radek Brich <radek.brich@devl.cz>
parents:
41
diff
changeset
|
43 |
|
27
139d1241b4c5
DriverPygame: add colors, make window resizable.
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
44 |
|
139d1241b4c5
DriverPygame: add colors, make window resizable.
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
45 |
## colors ## |
41
37b7dfc3eae6
Update Emitter: All event handlers now have exactly one argument: object inherited from Event class, which carries any data.
Radek Brich <radek.brich@devl.cz>
parents:
27
diff
changeset
|
46 |
|
27
139d1241b4c5
DriverPygame: add colors, make window resizable.
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
47 |
def pushcolorprefix(self, name): |
139d1241b4c5
DriverPygame: add colors, make window resizable.
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
48 |
self.colorprefix.append(name) |
139d1241b4c5
DriverPygame: add colors, make window resizable.
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
49 |
|
139d1241b4c5
DriverPygame: add colors, make window resizable.
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
50 |
def popcolorprefix(self): |
139d1241b4c5
DriverPygame: add colors, make window resizable.
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
51 |
self.colorprefix.pop() |
139d1241b4c5
DriverPygame: add colors, make window resizable.
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
52 |