author | Radek Brich <radek.brich@devl.cz> |
Wed, 27 Aug 2014 23:09:53 +0200 | |
changeset 103 | 49f212aa0228 |
parent 75 | 2430c643838a |
permissions | -rw-r--r-- |
0 | 1 |
# -*- coding: utf-8 -*- |
2 |
||
43
369c8ef5070a
Rename emitter module to events.
Radek Brich <radek.brich@devl.cz>
parents:
41
diff
changeset
|
3 |
from tuikit.events import Event, Emitter |
40
5faa38c10b67
Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents:
35
diff
changeset
|
4 |
|
5
ae128c885d0f
New GridLayout. Change cursor behavior (hide on unfocus event). Change resize event to propagate through containers. Change container clipping - allowlayout=false children are clipped without borders. More Widget doc.
Radek Brich <radek.brich@devl.cz>
parents:
0
diff
changeset
|
5 |
|
62
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
6 |
class Select: |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
7 |
def __init__(self, selected=None): |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
8 |
if not hasattr(self, '_options'): |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
9 |
raise TypeError('Cannot instantiate Select class.') |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
10 |
self._selected = selected or self._options[0] |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
11 |
|
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
12 |
def update(self, selected): |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
13 |
if selected not in self._options: |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
14 |
raise ValueError('Select: %r not in options %r' % (selected, self._options)) |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
15 |
self._selected = selected |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
16 |
|
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
17 |
def select_next(self): |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
18 |
i = self._options.index(self._selected) |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
19 |
try: |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
20 |
self._selected = self._options[i+1] |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
21 |
except IndexError: |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
22 |
self._selected = self._options[0] |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
23 |
|
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
24 |
@property |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
25 |
def selected(self): |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
26 |
return self._selected |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
27 |
|
75
2430c643838a
Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents:
74
diff
changeset
|
28 |
def get_value(self): |
2430c643838a
Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents:
74
diff
changeset
|
29 |
return self._selected |
2430c643838a
Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents:
74
diff
changeset
|
30 |
|
62
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
31 |
def __repr__(self): |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
32 |
return self.__class__.__name__ + '(%r)' % self._selected |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
33 |
|
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
34 |
|
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
35 |
def make_select(*args): |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
36 |
name = ''.join([x.capitalize() for x in args]) + 'Select' |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
37 |
return type(name, (Select,), {'_options': args}) |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
38 |
|
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
39 |
|
64
03f591f5fe5c
Drop Container.offset, add special layout for that - OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents:
63
diff
changeset
|
40 |
class Coords(Emitter): |
35 | 41 |
|
23
4e72fd2a0e14
Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
42 |
'''2D coordinates.''' |
35 | 43 |
|
5
ae128c885d0f
New GridLayout. Change cursor behavior (hide on unfocus event). Change resize event to propagate through containers. Change container clipping - allowlayout=false children are clipped without borders. More Widget doc.
Radek Brich <radek.brich@devl.cz>
parents:
0
diff
changeset
|
44 |
def __init__(self, x=0, y=0): |
64
03f591f5fe5c
Drop Container.offset, add special layout for that - OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents:
63
diff
changeset
|
45 |
self._x = x |
03f591f5fe5c
Drop Container.offset, add special layout for that - OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents:
63
diff
changeset
|
46 |
self._y = y |
03f591f5fe5c
Drop Container.offset, add special layout for that - OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents:
63
diff
changeset
|
47 |
self.add_events('change', Event) |
03f591f5fe5c
Drop Container.offset, add special layout for that - OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents:
63
diff
changeset
|
48 |
|
03f591f5fe5c
Drop Container.offset, add special layout for that - OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents:
63
diff
changeset
|
49 |
@property |
03f591f5fe5c
Drop Container.offset, add special layout for that - OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents:
63
diff
changeset
|
50 |
def x(self): |
03f591f5fe5c
Drop Container.offset, add special layout for that - OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents:
63
diff
changeset
|
51 |
return self._x |
03f591f5fe5c
Drop Container.offset, add special layout for that - OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents:
63
diff
changeset
|
52 |
|
03f591f5fe5c
Drop Container.offset, add special layout for that - OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents:
63
diff
changeset
|
53 |
@x.setter |
03f591f5fe5c
Drop Container.offset, add special layout for that - OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents:
63
diff
changeset
|
54 |
def x(self, value): |
03f591f5fe5c
Drop Container.offset, add special layout for that - OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents:
63
diff
changeset
|
55 |
self._x = value |
03f591f5fe5c
Drop Container.offset, add special layout for that - OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents:
63
diff
changeset
|
56 |
self.emit('change') |
03f591f5fe5c
Drop Container.offset, add special layout for that - OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents:
63
diff
changeset
|
57 |
|
03f591f5fe5c
Drop Container.offset, add special layout for that - OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents:
63
diff
changeset
|
58 |
@property |
03f591f5fe5c
Drop Container.offset, add special layout for that - OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents:
63
diff
changeset
|
59 |
def y(self): |
03f591f5fe5c
Drop Container.offset, add special layout for that - OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents:
63
diff
changeset
|
60 |
return self._y |
03f591f5fe5c
Drop Container.offset, add special layout for that - OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents:
63
diff
changeset
|
61 |
|
03f591f5fe5c
Drop Container.offset, add special layout for that - OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents:
63
diff
changeset
|
62 |
@y.setter |
03f591f5fe5c
Drop Container.offset, add special layout for that - OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents:
63
diff
changeset
|
63 |
def y(self, value): |
03f591f5fe5c
Drop Container.offset, add special layout for that - OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents:
63
diff
changeset
|
64 |
self._y = value |
03f591f5fe5c
Drop Container.offset, add special layout for that - OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents:
63
diff
changeset
|
65 |
self.emit('change') |
5
ae128c885d0f
New GridLayout. Change cursor behavior (hide on unfocus event). Change resize event to propagate through containers. Change container clipping - allowlayout=false children are clipped without borders. More Widget doc.
Radek Brich <radek.brich@devl.cz>
parents:
0
diff
changeset
|
66 |
|
16
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
67 |
def __getitem__(self, key): |
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
68 |
try: |
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
69 |
tupl = (self.x, self.y) |
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
70 |
return tupl[key] |
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
71 |
except TypeError: |
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
72 |
pass |
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
73 |
return self.__dict__[key] |
35 | 74 |
|
16
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
75 |
def __setitem__(self, key, value): |
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
76 |
if key == 0: |
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
77 |
self.x = value |
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
78 |
if key == 1: |
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
79 |
self.y = value |
5
ae128c885d0f
New GridLayout. Change cursor behavior (hide on unfocus event). Change resize event to propagate through containers. Change container clipping - allowlayout=false children are clipped without borders. More Widget doc.
Radek Brich <radek.brich@devl.cz>
parents:
0
diff
changeset
|
80 |
|
ae128c885d0f
New GridLayout. Change cursor behavior (hide on unfocus event). Change resize event to propagate through containers. Change container clipping - allowlayout=false children are clipped without borders. More Widget doc.
Radek Brich <radek.brich@devl.cz>
parents:
0
diff
changeset
|
81 |
def __repr__(self): |
16
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
82 |
return 'Coords(x={0.x},y={0.y})'.format(self) |
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
83 |
|
62
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
84 |
def update(self, x=None, y=None): |
64
03f591f5fe5c
Drop Container.offset, add special layout for that - OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents:
63
diff
changeset
|
85 |
old_x, old_y = self._x, self._y |
62
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
86 |
if isinstance(x, Coords) and y is None: |
74
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
64
diff
changeset
|
87 |
self._x, self._y = x |
62
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
88 |
else: |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
89 |
if isinstance(x, int): |
74
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
64
diff
changeset
|
90 |
self._x = x |
62
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
91 |
elif x is not None: |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
92 |
raise ValueError('Coords.update(): first parameter must be int or Coords') |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
93 |
if isinstance(y, int): |
74
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
64
diff
changeset
|
94 |
self._y = y |
62
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
95 |
elif y is not None: |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
96 |
raise ValueError('Coords.update(): second parameter must be int') |
64
03f591f5fe5c
Drop Container.offset, add special layout for that - OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents:
63
diff
changeset
|
97 |
if self._x != old_x or self._y != old_y: |
03f591f5fe5c
Drop Container.offset, add special layout for that - OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents:
63
diff
changeset
|
98 |
self.emit('change') |
62
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
99 |
|
16
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
100 |
|
40
5faa38c10b67
Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents:
35
diff
changeset
|
101 |
class Size(Emitter): |
35 | 102 |
|
23
4e72fd2a0e14
Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
103 |
'''Size class. |
35 | 104 |
|
23
4e72fd2a0e14
Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
105 |
Implements attribute access (.w, .h), list-like access([0],[1]) |
4e72fd2a0e14
Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
106 |
and dict-like access (['w'],['h']). |
35 | 107 |
|
23
4e72fd2a0e14
Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
108 |
''' |
35 | 109 |
|
16
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
110 |
def __init__(self, w=None, h=None): |
40
5faa38c10b67
Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents:
35
diff
changeset
|
111 |
self._w = w |
5faa38c10b67
Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents:
35
diff
changeset
|
112 |
self._h = h |
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:
40
diff
changeset
|
113 |
self.add_events('change', Event) |
40
5faa38c10b67
Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents:
35
diff
changeset
|
114 |
|
5faa38c10b67
Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents:
35
diff
changeset
|
115 |
@property |
5faa38c10b67
Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents:
35
diff
changeset
|
116 |
def w(self): |
5faa38c10b67
Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents:
35
diff
changeset
|
117 |
return self._w |
5faa38c10b67
Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents:
35
diff
changeset
|
118 |
|
5faa38c10b67
Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents:
35
diff
changeset
|
119 |
@w.setter |
5faa38c10b67
Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents:
35
diff
changeset
|
120 |
def w(self, value): |
5faa38c10b67
Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents:
35
diff
changeset
|
121 |
self._w = value |
5faa38c10b67
Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents:
35
diff
changeset
|
122 |
self.emit('change') |
5faa38c10b67
Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents:
35
diff
changeset
|
123 |
|
5faa38c10b67
Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents:
35
diff
changeset
|
124 |
@property |
5faa38c10b67
Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents:
35
diff
changeset
|
125 |
def h(self): |
5faa38c10b67
Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents:
35
diff
changeset
|
126 |
return self._h |
5faa38c10b67
Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents:
35
diff
changeset
|
127 |
|
5faa38c10b67
Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents:
35
diff
changeset
|
128 |
@h.setter |
5faa38c10b67
Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents:
35
diff
changeset
|
129 |
def h(self, value): |
5faa38c10b67
Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents:
35
diff
changeset
|
130 |
self._h = value |
5faa38c10b67
Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents:
35
diff
changeset
|
131 |
self.emit('change') |
35 | 132 |
|
16
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
133 |
def __getitem__(self, key): |
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
134 |
try: |
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
135 |
tupl = (self.w, self.h) |
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
136 |
return tupl[key] |
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
137 |
except TypeError: |
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
138 |
pass |
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
139 |
return self.__dict__[key] |
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
140 |
|
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
141 |
def __setitem__(self, key, value): |
23
4e72fd2a0e14
Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
142 |
if key in [0, 'w']: |
16
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
143 |
self.w = value |
23
4e72fd2a0e14
Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
144 |
if key in [1, 'h']: |
16
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
145 |
self.h = value |
35 | 146 |
|
16
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
147 |
def __repr__(self): |
40
5faa38c10b67
Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents:
35
diff
changeset
|
148 |
return 'Size(w={0._w},h={0._h})'.format(self) |
5
ae128c885d0f
New GridLayout. Change cursor behavior (hide on unfocus event). Change resize event to propagate through containers. Change container clipping - allowlayout=false children are clipped without borders. More Widget doc.
Radek Brich <radek.brich@devl.cz>
parents:
0
diff
changeset
|
149 |
|
62
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
150 |
def update(self, w=None, h=None): |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
151 |
old_w, old_h = self._w, self._h |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
152 |
if isinstance(w, Size) and h is None: |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
153 |
self._w, self._h = w |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
154 |
else: |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
155 |
if isinstance(w, int): |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
156 |
self._w = w |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
157 |
elif w is not None: |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
158 |
raise ValueError('Size.update(): first parameter must be int or Size') |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
159 |
if isinstance(h, int): |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
160 |
self._h = h |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
161 |
elif h is not None: |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
162 |
raise ValueError('Size.update(): second parameter must be int') |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
163 |
if self._w != old_w or self._h != old_h: |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
164 |
self.emit('change') |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
165 |
|
5
ae128c885d0f
New GridLayout. Change cursor behavior (hide on unfocus event). Change resize event to propagate through containers. Change container clipping - allowlayout=false children are clipped without borders. More Widget doc.
Radek Brich <radek.brich@devl.cz>
parents:
0
diff
changeset
|
166 |
|
0 | 167 |
class Rect: |
35 | 168 |
|
23
4e72fd2a0e14
Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
169 |
'''Rectangle is defined by 2D coordinates and size.''' |
35 | 170 |
|
0 | 171 |
def __init__(self, x=0, y=0, w=0, h=0): |
172 |
self.x = x |
|
173 |
self.y = y |
|
174 |
self.w = w |
|
175 |
self.h = h |
|
176 |
||
177 |
def __repr__(self): |
|
16
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
178 |
return 'Rect(x={0.x},y={0.y},w={0.w},h={0.h})'.format(self) |
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
179 |
|
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
180 |
|
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
181 |
class Borders: |
35 | 182 |
|
23
4e72fd2a0e14
Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
183 |
'''Borders are defined by left, top, right, bottom border size. |
35 | 184 |
|
23
4e72fd2a0e14
Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
185 |
Ordering is clock-wise, starting with left. This may seem weird, |
4e72fd2a0e14
Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
186 |
but it corresponds to X/Y or W/H used elsewhere. Left and right are |
4e72fd2a0e14
Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
187 |
on X axis, so they are defined first. |
35 | 188 |
|
23
4e72fd2a0e14
Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
189 |
''' |
35 | 190 |
|
62
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
191 |
def __init__(self, l=0, t=0, r=0, b=0, full=None): |
16
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
192 |
self.l = l # left |
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
193 |
self.t = t # top |
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
194 |
self.r = r # right |
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
195 |
self.b = b # bottom |
62
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
196 |
if full is not None: |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
197 |
self.l = self.t = self.r = self.b = full |
0 | 198 |
|
16
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
199 |
def __getitem__(self, key): |
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
200 |
try: |
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
201 |
tupl = (self.l, self.t, self.r, self.b) |
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
202 |
return tupl[key] |
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
203 |
except TypeError: |
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
204 |
pass |
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
205 |
return self.__dict__[key] |
35 | 206 |
|
16
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
207 |
def __repr__(self): |
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
208 |
return 'Borders(l={0.l},t={0.t},r={0.r},b={0.b})'.format(self) |
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
209 |
|
62
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
210 |
def update(self, *args, **kwargs): |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
211 |
if len(args) == 4: |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
212 |
self.l, self.t, self.r, self.b = args |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
213 |
elif len(args) == 1 and isinstance(args[0], Borders): |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
214 |
self.l, self.t, self.r, self.b = args[0] |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
215 |
elif len(args): |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
216 |
raise ValueError('Borders.update() takes exactly 4 positional arguments.') |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
217 |
for arg in kwargs: |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
218 |
setattr(self, arg, kwargs[arg]) |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
219 |
|
23
4e72fd2a0e14
Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
220 |
|
4e72fd2a0e14
Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
221 |
class ClipStack: |
35 | 222 |
|
23
4e72fd2a0e14
Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
223 |
'''Stack of clipping regions.''' |
35 | 224 |
|
23
4e72fd2a0e14
Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
225 |
def __init__(self): |
4e72fd2a0e14
Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
226 |
self.stack = [] |
35 | 227 |
|
23
4e72fd2a0e14
Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
228 |
def push(self, x, y, w, h): |
4e72fd2a0e14
Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
229 |
newclip = Rect(x, y, w, h) |
4e72fd2a0e14
Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
230 |
if len(self.stack): |
74
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
64
diff
changeset
|
231 |
oldclip = self.top() |
23
4e72fd2a0e14
Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
232 |
newclip = self.intersect(oldclip, newclip) |
4e72fd2a0e14
Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
233 |
self.stack.append(newclip) |
4e72fd2a0e14
Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
234 |
|
4e72fd2a0e14
Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
235 |
def pop(self): |
4e72fd2a0e14
Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
236 |
self.stack.pop() |
4e72fd2a0e14
Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
237 |
|
74
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
64
diff
changeset
|
238 |
def top(self): |
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
64
diff
changeset
|
239 |
return self.stack[-1] |
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
64
diff
changeset
|
240 |
|
23
4e72fd2a0e14
Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
241 |
def test(self, x, y): |
4e72fd2a0e14
Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
242 |
# no clip rectangle on stack => passed |
4e72fd2a0e14
Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
243 |
if not len(self.stack): |
4e72fd2a0e14
Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
244 |
return True |
4e72fd2a0e14
Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
245 |
# test against top clip rect from stack |
74
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
64
diff
changeset
|
246 |
clip = self.top() |
23
4e72fd2a0e14
Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
247 |
if x < clip.x or y < clip.y \ |
4e72fd2a0e14
Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
248 |
or x >= clip.x + clip.w or y >= clip.y + clip.h: |
4e72fd2a0e14
Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
249 |
return False |
4e72fd2a0e14
Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
250 |
# passed |
4e72fd2a0e14
Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
251 |
return True |
4e72fd2a0e14
Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
252 |
|
4e72fd2a0e14
Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
253 |
def intersect(self, r1, r2): |
4e72fd2a0e14
Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
254 |
x1 = max(r1.x, r2.x) |
4e72fd2a0e14
Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
255 |
y1 = max(r1.y, r2.y) |
4e72fd2a0e14
Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
256 |
x2 = min(r1.x + r1.w, r2.x + r2.w) |
4e72fd2a0e14
Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
257 |
y2 = min(r1.y + r1.h, r2.y + r2.h) |
4e72fd2a0e14
Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
258 |
if x1 >= x2 or y1 >= y2: |
4e72fd2a0e14
Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
259 |
return Rect() |
4e72fd2a0e14
Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
260 |
return Rect(x1, y1, x2-x1, y2-y1) |
4e72fd2a0e14
Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
261 |
|
4e72fd2a0e14
Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
262 |
def union(self, r1, r2): |
4e72fd2a0e14
Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
263 |
x = min(r1.x, r2.x) |
4e72fd2a0e14
Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
264 |
y = min(r1.y, r2.y) |
4e72fd2a0e14
Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
265 |
w = max(r1.x + r1.w, r2.x + r2.w) - x |
4e72fd2a0e14
Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
266 |
h = max(r1.y + r1.h, r2.y + r2.h) - y |
4e72fd2a0e14
Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
267 |
return Rect(x, y, w, h) |
4e72fd2a0e14
Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
268 |
|
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:
23
diff
changeset
|
269 |
|
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:
23
diff
changeset
|
270 |
class UnicodeGraphics: |
35 | 271 |
|
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:
23
diff
changeset
|
272 |
'''Unicode graphics bank. |
35 | 273 |
|
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:
23
diff
changeset
|
274 |
This class can be overriden to change graphics style (round corners etc.).''' |
35 | 275 |
|
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:
23
diff
changeset
|
276 |
# http://en.wikipedia.org/wiki/List_of_Unicode_characters#Geometric_shapes |
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:
23
diff
changeset
|
277 |
UP_ARROW = '▲' #curses.ACS_UARROW |
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:
23
diff
changeset
|
278 |
DOWN_ARROW = '▼' #curses.ACS_DARROW |
62
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
279 |
LEFT_ARROW = '◀' |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
280 |
RIGHT_ARROW = '▶' |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
281 |
CIRCLE = '●' |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
282 |
DIAMOND = '◆' |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
283 |
MIDDLE_DOT = '·' |
35 | 284 |
|
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:
23
diff
changeset
|
285 |
# http://en.wikipedia.org/wiki/Box-drawing_characters |
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:
23
diff
changeset
|
286 |
LIGHT_SHADE = '░' #curses.ACS_BOARD |
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:
23
diff
changeset
|
287 |
MEDIUM_SHADE = '▒' |
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:
23
diff
changeset
|
288 |
DARK_SHADE = '▓' |
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:
23
diff
changeset
|
289 |
BLOCK = '█' |
35 | 290 |
|
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:
23
diff
changeset
|
291 |
COLUMN = '▁▂▃▄▅▆▇█' |
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:
23
diff
changeset
|
292 |
CORNER_ROUND = '╭╮╰╯' |
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:
23
diff
changeset
|
293 |
CORNER = '┌┐└┘' |
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:
23
diff
changeset
|
294 |
LINE = '─━│┃┄┅┆┇┈┉┊┋' |
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:
23
diff
changeset
|
295 |
|
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:
23
diff
changeset
|
296 |
HLINE = '─' # curses.ACS_HLINE |
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:
23
diff
changeset
|
297 |
VLINE = '│' # curses.ACS_VLINE |
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:
23
diff
changeset
|
298 |
ULCORNER = '┌' # curses.ACS_ULCORNER |
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:
23
diff
changeset
|
299 |
URCORNER = '┐' # curses.ACS_URCORNER |
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:
23
diff
changeset
|
300 |
LLCORNER = '└' # curses.ACS_LLCORNER |
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:
23
diff
changeset
|
301 |
LRCORNER = '┘' # curses.ACS_LRCORNER |
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:
23
diff
changeset
|
302 |
LTEE = '├' |
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:
23
diff
changeset
|
303 |
RTEE = '┤' |
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:
23
diff
changeset
|
304 |
|
63
2a0e04091898
Rework MenuBar. Add MenuButton. Add mouse event cascading to floaters.
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
305 |
char_map = { |
2a0e04091898
Rework MenuBar. Add MenuButton. Add mouse event cascading to floaters.
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
306 |
# scrollbar |
2a0e04091898
Rework MenuBar. Add MenuButton. Add mouse event cascading to floaters.
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
307 |
'sb_thumb' : CIRCLE, |
2a0e04091898
Rework MenuBar. Add MenuButton. Add mouse event cascading to floaters.
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
308 |
'sb_htrack' : LINE[8], |
2a0e04091898
Rework MenuBar. Add MenuButton. Add mouse event cascading to floaters.
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
309 |
'sb_vtrack' : LINE[10], |
2a0e04091898
Rework MenuBar. Add MenuButton. Add mouse event cascading to floaters.
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
310 |
'sb_left' : LEFT_ARROW, |
2a0e04091898
Rework MenuBar. Add MenuButton. Add mouse event cascading to floaters.
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
311 |
'sb_right' : RIGHT_ARROW, |
2a0e04091898
Rework MenuBar. Add MenuButton. Add mouse event cascading to floaters.
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
312 |
'sb_up' : UP_ARROW, |
2a0e04091898
Rework MenuBar. Add MenuButton. Add mouse event cascading to floaters.
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
313 |
'sb_down' : DOWN_ARROW, |
2a0e04091898
Rework MenuBar. Add MenuButton. Add mouse event cascading to floaters.
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
314 |
} |
2a0e04091898
Rework MenuBar. Add MenuButton. Add mouse event cascading to floaters.
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
315 |
|
2a0e04091898
Rework MenuBar. Add MenuButton. Add mouse event cascading to floaters.
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
316 |
def get_char(self, name): |
2a0e04091898
Rework MenuBar. Add MenuButton. Add mouse event cascading to floaters.
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
317 |
return self.char_map[name] |
2a0e04091898
Rework MenuBar. Add MenuButton. Add mouse event cascading to floaters.
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
318 |