author | Radek Brich <radek.brich@devl.cz> |
Wed, 02 Jan 2013 11:48:36 +0100 | |
changeset 44 | d77f1ae3786c |
parent 43 | 369c8ef5070a |
child 45 | 43b2279b06e1 |
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 Emitter, Event, DrawEvent, FocusEvent, KeyboardEvent, MouseEvent |
18
e6c3a5ee91aa
Eliminate relative imports.
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
4 |
from tuikit.common import Coords, Size |
0 | 5 |
|
9
7175ed629a76
Added ComboBox, HorizontalLayout, TreeNode, TreeModel, TreeView. Widget is now descendant of EventSource. Improved color management (color prefixes).
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
6 |
|
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
18
diff
changeset
|
7 |
class Widget(Emitter): |
9
7175ed629a76
Added ComboBox, HorizontalLayout, TreeNode, TreeModel, TreeView. Widget is now descendant of EventSource. Improved color management (color prefixes).
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
8 |
|
13
19ebde2fd594
Add more generated documentation.
Radek Brich <radek.brich@devl.cz>
parents:
9
diff
changeset
|
9 |
'''Base class for all widgets.''' |
9
7175ed629a76
Added ComboBox, HorizontalLayout, TreeNode, TreeModel, TreeView. Widget is now descendant of EventSource. Improved color management (color prefixes).
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
10 |
|
0 | 11 |
def __init__(self, width = 10, height = 10): |
34
e3beacd5e536
Update event propagation, keypress event, focusing.
Radek Brich <radek.brich@devl.cz>
parents:
33
diff
changeset
|
12 |
#: Widget name is used for logging etc. Not visible anywhere. |
e3beacd5e536
Update event propagation, keypress event, focusing.
Radek Brich <radek.brich@devl.cz>
parents:
33
diff
changeset
|
13 |
self.name = None |
e3beacd5e536
Update event propagation, keypress event, focusing.
Radek Brich <radek.brich@devl.cz>
parents:
33
diff
changeset
|
14 |
|
13
19ebde2fd594
Add more generated documentation.
Radek Brich <radek.brich@devl.cz>
parents:
9
diff
changeset
|
15 |
#: Parent widget. |
0 | 16 |
self.parent = None |
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
18
diff
changeset
|
17 |
|
13
19ebde2fd594
Add more generated documentation.
Radek Brich <radek.brich@devl.cz>
parents:
9
diff
changeset
|
18 |
#: Top widget (same for every widget in one application). |
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
|
19 |
self._top = None |
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
18
diff
changeset
|
20 |
|
13
19ebde2fd594
Add more generated documentation.
Radek Brich <radek.brich@devl.cz>
parents:
9
diff
changeset
|
21 |
# Position inside parent widget. Modified by layout manager. |
16
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
15
diff
changeset
|
22 |
self.position = Coords() |
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
18
diff
changeset
|
23 |
|
13
19ebde2fd594
Add more generated documentation.
Radek Brich <radek.brich@devl.cz>
parents:
9
diff
changeset
|
24 |
# Actual size. Modified by layout manager. |
16
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
15
diff
changeset
|
25 |
self.size = Size(width, height) |
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
18
diff
changeset
|
26 |
|
13
19ebde2fd594
Add more generated documentation.
Radek Brich <radek.brich@devl.cz>
parents:
9
diff
changeset
|
27 |
#: Minimal size of widget. Under normal circumstances |
19ebde2fd594
Add more generated documentation.
Radek Brich <radek.brich@devl.cz>
parents:
9
diff
changeset
|
28 |
#: widget will never be sized smaller than this. |
19ebde2fd594
Add more generated documentation.
Radek Brich <radek.brich@devl.cz>
parents:
9
diff
changeset
|
29 |
#: Tuple (w, h). Both must be integers >= 1. |
40
5faa38c10b67
Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents:
39
diff
changeset
|
30 |
self.sizemin = Size(1, 1) |
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
18
diff
changeset
|
31 |
|
13
19ebde2fd594
Add more generated documentation.
Radek Brich <radek.brich@devl.cz>
parents:
9
diff
changeset
|
32 |
#: Maximum size of widget. Widget will never be sized bigger than this. |
19ebde2fd594
Add more generated documentation.
Radek Brich <radek.brich@devl.cz>
parents:
9
diff
changeset
|
33 |
#: Tuple (w, h). Integers >= 1 or None (meaning no maximum size or infinite). |
16
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
15
diff
changeset
|
34 |
self.sizemax = Size(None, None) |
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
18
diff
changeset
|
35 |
|
13
19ebde2fd594
Add more generated documentation.
Radek Brich <radek.brich@devl.cz>
parents:
9
diff
changeset
|
36 |
#: Size request. This is default size of the widget. Will be fulfilled if possible. |
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
|
37 |
#: Size(w, h). Integers >= 1 or None (meaning use minumal size). |
40
5faa38c10b67
Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents:
39
diff
changeset
|
38 |
self._sizereq = Size(10, 10) |
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
|
39 |
self._sizereq.connect('change', lambda ev: self.emit('sizereq')) |
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
18
diff
changeset
|
40 |
|
13
19ebde2fd594
Add more generated documentation.
Radek Brich <radek.brich@devl.cz>
parents:
9
diff
changeset
|
41 |
#: When false, the widget is not considered in layout. |
40
5faa38c10b67
Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents:
39
diff
changeset
|
42 |
self.allow_layout = True |
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
18
diff
changeset
|
43 |
|
34
e3beacd5e536
Update event propagation, keypress event, focusing.
Radek Brich <radek.brich@devl.cz>
parents:
33
diff
changeset
|
44 |
#: Allow keyboard focus for this widget. |
e3beacd5e536
Update event propagation, keypress event, focusing.
Radek Brich <radek.brich@devl.cz>
parents:
33
diff
changeset
|
45 |
self.allow_focus = False |
e3beacd5e536
Update event propagation, keypress event, focusing.
Radek Brich <radek.brich@devl.cz>
parents:
33
diff
changeset
|
46 |
|
15 | 47 |
#: Dictionary containing optional parameters for layout managers etc. |
48 |
self.hints = {} |
|
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
18
diff
changeset
|
49 |
|
13
19ebde2fd594
Add more generated documentation.
Radek Brich <radek.brich@devl.cz>
parents:
9
diff
changeset
|
50 |
#: Hidden widget does not affect layout. |
19ebde2fd594
Add more generated documentation.
Radek Brich <radek.brich@devl.cz>
parents:
9
diff
changeset
|
51 |
self.hidden = False |
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
18
diff
changeset
|
52 |
|
44
d77f1ae3786c
Add Widget.spot property. TreeView: move spot with cursor node. ScrollView: scroll when spot moves.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
53 |
#: Cursor is position where text input will occur, |
d77f1ae3786c
Add Widget.spot property. TreeView: move spot with cursor node. ScrollView: scroll when spot moves.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
54 |
#: i.e. classic blinking cursor in console. |
d77f1ae3786c
Add Widget.spot property. TreeView: move spot with cursor node. ScrollView: scroll when spot moves.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
55 |
#: None means no cursor (hidden). |
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:
2
diff
changeset
|
56 |
self.cursor = None |
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
18
diff
changeset
|
57 |
|
44
d77f1ae3786c
Add Widget.spot property. TreeView: move spot with cursor node. ScrollView: scroll when spot moves.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
58 |
# See spot property. |
d77f1ae3786c
Add Widget.spot property. TreeView: move spot with cursor node. ScrollView: scroll when spot moves.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
59 |
self._spot = Coords() |
d77f1ae3786c
Add Widget.spot property. TreeView: move spot with cursor node. ScrollView: scroll when spot moves.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
60 |
|
0 | 61 |
# redraw request |
62 |
self._redraw = True |
|
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
18
diff
changeset
|
63 |
|
0 | 64 |
# event handlers |
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
18
diff
changeset
|
65 |
self.add_events( |
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
|
66 |
'resize', Event, |
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
|
67 |
'draw', DrawEvent, |
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
|
68 |
'keypress', KeyboardEvent, |
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
|
69 |
'mousedown', MouseEvent, |
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
|
70 |
'mouseup', MouseEvent, |
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
|
71 |
'mousemove', MouseEvent, |
44
d77f1ae3786c
Add Widget.spot property. TreeView: move spot with cursor node. ScrollView: scroll when spot moves.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
72 |
'mousewheel', MouseEvent, |
d77f1ae3786c
Add Widget.spot property. TreeView: move spot with cursor node. ScrollView: scroll when spot moves.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
73 |
'sizereq', Event, |
d77f1ae3786c
Add Widget.spot property. TreeView: move spot with cursor node. ScrollView: scroll when spot moves.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
74 |
'spotmove', Event, |
d77f1ae3786c
Add Widget.spot property. TreeView: move spot with cursor node. ScrollView: scroll when spot moves.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
75 |
'focus', FocusEvent, |
d77f1ae3786c
Add Widget.spot property. TreeView: move spot with cursor node. ScrollView: scroll when spot moves.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
76 |
'unfocus', FocusEvent) |
0 | 77 |
|
78 |
||
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:
2
diff
changeset
|
79 |
@property |
16
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
15
diff
changeset
|
80 |
def x(self): |
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
15
diff
changeset
|
81 |
return self.position.x |
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
15
diff
changeset
|
82 |
|
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
15
diff
changeset
|
83 |
@x.setter |
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
15
diff
changeset
|
84 |
def x(self, value): |
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
15
diff
changeset
|
85 |
self.position.x = value |
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
15
diff
changeset
|
86 |
|
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
15
diff
changeset
|
87 |
@property |
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
15
diff
changeset
|
88 |
def y(self): |
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
15
diff
changeset
|
89 |
return self.position.y |
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
15
diff
changeset
|
90 |
|
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
15
diff
changeset
|
91 |
@y.setter |
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
15
diff
changeset
|
92 |
def y(self, value): |
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
15
diff
changeset
|
93 |
self.position.y = value |
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
15
diff
changeset
|
94 |
|
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
15
diff
changeset
|
95 |
|
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
15
diff
changeset
|
96 |
@property |
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:
2
diff
changeset
|
97 |
def width(self): |
16
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
15
diff
changeset
|
98 |
return self.size.w |
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:
2
diff
changeset
|
99 |
|
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:
2
diff
changeset
|
100 |
@width.setter |
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:
2
diff
changeset
|
101 |
def width(self, value): |
16
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
15
diff
changeset
|
102 |
self.size.w = value |
34
e3beacd5e536
Update event propagation, keypress event, focusing.
Radek Brich <radek.brich@devl.cz>
parents:
33
diff
changeset
|
103 |
self.emit('resize') |
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:
2
diff
changeset
|
104 |
|
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:
2
diff
changeset
|
105 |
@property |
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:
2
diff
changeset
|
106 |
def height(self): |
16
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
15
diff
changeset
|
107 |
return self.size.h |
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:
2
diff
changeset
|
108 |
|
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:
2
diff
changeset
|
109 |
@height.setter |
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:
2
diff
changeset
|
110 |
def height(self, value): |
16
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
15
diff
changeset
|
111 |
self.size.h = value |
34
e3beacd5e536
Update event propagation, keypress event, focusing.
Radek Brich <radek.brich@devl.cz>
parents:
33
diff
changeset
|
112 |
self.emit('resize') |
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:
2
diff
changeset
|
113 |
|
40
5faa38c10b67
Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents:
39
diff
changeset
|
114 |
@property |
5faa38c10b67
Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents:
39
diff
changeset
|
115 |
def sizereq(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:
40
diff
changeset
|
116 |
"""Size request. |
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
|
117 |
|
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
|
118 |
This is default size of the widget. Will be fulfilled if possible. |
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
|
119 |
Size(w, h). Integers >= 1 or None (meaning use minumal size). |
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
|
120 |
|
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
|
121 |
""" |
40
5faa38c10b67
Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents:
39
diff
changeset
|
122 |
return self._sizereq |
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:
2
diff
changeset
|
123 |
|
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
|
124 |
@property |
44
d77f1ae3786c
Add Widget.spot property. TreeView: move spot with cursor node. ScrollView: scroll when spot moves.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
125 |
def spot(self): |
d77f1ae3786c
Add Widget.spot property. TreeView: move spot with cursor node. ScrollView: scroll when spot moves.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
126 |
"""Spot of visibility. |
d77f1ae3786c
Add Widget.spot property. TreeView: move spot with cursor node. ScrollView: scroll when spot moves.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
127 |
|
d77f1ae3786c
Add Widget.spot property. TreeView: move spot with cursor node. ScrollView: scroll when spot moves.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
128 |
This is one point which should be always visible. |
d77f1ae3786c
Add Widget.spot property. TreeView: move spot with cursor node. ScrollView: scroll when spot moves.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
129 |
It affects scrolling (moving spot in widget placed in ScrollView scrolls the view). |
d77f1ae3786c
Add Widget.spot property. TreeView: move spot with cursor node. ScrollView: scroll when spot moves.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
130 |
|
d77f1ae3786c
Add Widget.spot property. TreeView: move spot with cursor node. ScrollView: scroll when spot moves.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
131 |
""" |
d77f1ae3786c
Add Widget.spot property. TreeView: move spot with cursor node. ScrollView: scroll when spot moves.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
132 |
return self._spot |
d77f1ae3786c
Add Widget.spot property. TreeView: move spot with cursor node. ScrollView: scroll when spot moves.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
133 |
|
d77f1ae3786c
Add Widget.spot property. TreeView: move spot with cursor node. ScrollView: scroll when spot moves.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
134 |
|
d77f1ae3786c
Add Widget.spot property. TreeView: move spot with cursor node. ScrollView: scroll when spot moves.
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
135 |
@property |
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
|
136 |
def top(self): |
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
|
137 |
"""Top widget (same for every widget in one application).""" |
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
|
138 |
return self._top |
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
|
139 |
|
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
|
140 |
@top.setter |
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
|
141 |
def top(self, value): |
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
|
142 |
self._set_top(value) |
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
|
143 |
|
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
|
144 |
def _set_top(self, value): |
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
|
145 |
"""Real setter for top. Allows override.""" |
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
|
146 |
self._top = value |
0 | 147 |
|
148 |
||
9
7175ed629a76
Added ComboBox, HorizontalLayout, TreeNode, TreeModel, TreeView. Widget is now descendant of EventSource. Improved color management (color prefixes).
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
149 |
### events |
2
684cdc352562
Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
1
diff
changeset
|
150 |
|
0 | 151 |
def redraw(self, parent=True): |
152 |
self._redraw = True |
|
153 |
if parent and self.parent: |
|
154 |
self.parent._redraw = True |
|
155 |
||
34
e3beacd5e536
Update event propagation, keypress event, focusing.
Radek Brich <radek.brich@devl.cz>
parents:
33
diff
changeset
|
156 |
def draw(self, driver, x, y): |
36 | 157 |
"""Draw the widget. |
158 |
||
159 |
This method should not be overriden by subclasses, |
|
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
|
160 |
use _handle_draw instead. |
36 | 161 |
|
162 |
""" |
|
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:
2
diff
changeset
|
163 |
if self.hidden: |
34
e3beacd5e536
Update event propagation, keypress event, focusing.
Radek Brich <radek.brich@devl.cz>
parents:
33
diff
changeset
|
164 |
return True |
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:
2
diff
changeset
|
165 |
|
34
e3beacd5e536
Update event propagation, keypress event, focusing.
Radek Brich <radek.brich@devl.cz>
parents:
33
diff
changeset
|
166 |
self.emit('draw', driver, x, y) |
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:
2
diff
changeset
|
167 |
|
38
c6e170452c7f
Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
168 |
if self.has_focus(): |
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:
2
diff
changeset
|
169 |
if self.cursor: |
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:
2
diff
changeset
|
170 |
cx, cy = self.cursor |
34
e3beacd5e536
Update event propagation, keypress event, focusing.
Radek Brich <radek.brich@devl.cz>
parents:
33
diff
changeset
|
171 |
driver.showcursor(x + cx, y + cy) |
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:
2
diff
changeset
|
172 |
else: |
34
e3beacd5e536
Update event propagation, keypress event, focusing.
Radek Brich <radek.brich@devl.cz>
parents:
33
diff
changeset
|
173 |
driver.hidecursor() |
0 | 174 |
|
40
5faa38c10b67
Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents:
39
diff
changeset
|
175 |
def _handle_mousedown(self, ev): |
38
c6e170452c7f
Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
176 |
self.set_focus() |
13
19ebde2fd594
Add more generated documentation.
Radek Brich <radek.brich@devl.cz>
parents:
9
diff
changeset
|
177 |
|
19ebde2fd594
Add more generated documentation.
Radek Brich <radek.brich@devl.cz>
parents:
9
diff
changeset
|
178 |
|
0 | 179 |
### focus |
180 |
||
181 |
||
38
c6e170452c7f
Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
182 |
def can_focus(self): |
34
e3beacd5e536
Update event propagation, keypress event, focusing.
Radek Brich <radek.brich@devl.cz>
parents:
33
diff
changeset
|
183 |
return not self.hidden and self.allow_focus |
0 | 184 |
|
185 |
||
38
c6e170452c7f
Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
186 |
def has_focus(self): |
34
e3beacd5e536
Update event propagation, keypress event, focusing.
Radek Brich <radek.brich@devl.cz>
parents:
33
diff
changeset
|
187 |
if self.parent is None: |
e3beacd5e536
Update event propagation, keypress event, focusing.
Radek Brich <radek.brich@devl.cz>
parents:
33
diff
changeset
|
188 |
return True |
38
c6e170452c7f
Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
189 |
return (self.parent.has_focus() \ |
34
e3beacd5e536
Update event propagation, keypress event, focusing.
Radek Brich <radek.brich@devl.cz>
parents:
33
diff
changeset
|
190 |
and self.parent.focuschild == self) |
9
7175ed629a76
Added ComboBox, HorizontalLayout, TreeNode, TreeModel, TreeView. Widget is now descendant of EventSource. Improved color management (color prefixes).
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
191 |
|
7175ed629a76
Added ComboBox, HorizontalLayout, TreeNode, TreeModel, TreeView. Widget is now descendant of EventSource. Improved color management (color prefixes).
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
192 |
|
38
c6e170452c7f
Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
193 |
def set_focus(self): |
c6e170452c7f
Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
194 |
"""Focus the widget. |
c6e170452c7f
Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
195 |
|
c6e170452c7f
Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
196 |
This changes focus state of parent widget, |
c6e170452c7f
Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
197 |
but it does not check if parent widget actually |
c6e170452c7f
Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
198 |
has focus. It still works if it has not, |
c6e170452c7f
Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
199 |
but keyboard events will go to really focused widget, |
c6e170452c7f
Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
200 |
not this one. |
c6e170452c7f
Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
201 |
|
c6e170452c7f
Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
202 |
See also grab_focus() which cares about parents. |
c6e170452c7f
Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
203 |
|
c6e170452c7f
Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
204 |
""" |
c6e170452c7f
Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
205 |
if self.has_focus() or not self.can_focus(): |
1
69318aba22bf
Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents:
0
diff
changeset
|
206 |
return |
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
|
207 |
oldfocuschild = self.parent.focuschild |
34
e3beacd5e536
Update event propagation, keypress event, focusing.
Radek Brich <radek.brich@devl.cz>
parents:
33
diff
changeset
|
208 |
self.parent.focuschild = 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:
40
diff
changeset
|
209 |
if oldfocuschild: |
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
|
210 |
oldfocuschild.emit('unfocus', new=self) |
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
|
211 |
self.emit('focus', old=oldfocuschild) |
0 | 212 |
|
213 |
||
38
c6e170452c7f
Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
214 |
def grab_focus(self): |
c6e170452c7f
Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
215 |
"""Focus the widget and its parents.""" |
c6e170452c7f
Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
216 |
self.set_focus() |
c6e170452c7f
Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
217 |
if self.parent and not self.parent.has_focus(): |
c6e170452c7f
Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
218 |
self.parent.grab_focus() |
c6e170452c7f
Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
219 |
|
c6e170452c7f
Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
220 |
|
9
7175ed629a76
Added ComboBox, HorizontalLayout, TreeNode, TreeModel, TreeView. Widget is now descendant of EventSource. Improved color management (color prefixes).
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
221 |
### |
7175ed629a76
Added ComboBox, HorizontalLayout, TreeNode, TreeModel, TreeView. Widget is now descendant of EventSource. Improved color management (color prefixes).
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
222 |
|
16
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
15
diff
changeset
|
223 |
def hint(self, key): |
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
15
diff
changeset
|
224 |
if key in self.hints: |
8791a7da6835
Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents:
15
diff
changeset
|
225 |
return self.hints[key] |
9
7175ed629a76
Added ComboBox, HorizontalLayout, TreeNode, TreeModel, TreeView. Widget is now descendant of EventSource. Improved color management (color prefixes).
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
226 |
|
0 | 227 |
def enclose(self, x, y): |
228 |
if self.hidden: |
|
229 |
return False |
|
230 |
if x < self.x or y < self.y \ |
|
231 |
or x >= self.x + self.width or y >= self.y + self.height: |
|
232 |
return False |
|
233 |
return True |
|
234 |
||
235 |
||
236 |
def screentest(self, y, x): |
|
237 |
sy, sx = self.screenyx() |
|
238 |
if y < sy or x < sx or y >= sy + self.height or x >= sx + self.width: |
|
239 |
return False |
|
240 |
return True |
|
241 |
||
242 |
||
243 |
def screenyx(self): |
|
244 |
if self.parent: |
|
245 |
y,x = self.parent.screenyx() |
|
246 |
return self.y + y, self.x + x |
|
247 |
return self.y, self.x |
|
1
69318aba22bf
Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents:
0
diff
changeset
|
248 |
|
2
684cdc352562
Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
1
diff
changeset
|
249 |
|
684cdc352562
Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
1
diff
changeset
|
250 |
def hide(self): |
13
19ebde2fd594
Add more generated documentation.
Radek Brich <radek.brich@devl.cz>
parents:
9
diff
changeset
|
251 |
'''Hide widget. Convenience method.''' |
2
684cdc352562
Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
1
diff
changeset
|
252 |
self.hidden = True |
39 | 253 |
if self.parent and self.has_focus(): |
38
c6e170452c7f
Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
254 |
self.parent.focus_next() |
2
684cdc352562
Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
1
diff
changeset
|
255 |
self.redraw() |
684cdc352562
Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
1
diff
changeset
|
256 |
|
684cdc352562
Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
1
diff
changeset
|
257 |
|
684cdc352562
Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
1
diff
changeset
|
258 |
def show(self): |
13
19ebde2fd594
Add more generated documentation.
Radek Brich <radek.brich@devl.cz>
parents:
9
diff
changeset
|
259 |
'''Show widget. Convenience method.''' |
2
684cdc352562
Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
1
diff
changeset
|
260 |
self.hidden = False |
684cdc352562
Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
1
diff
changeset
|
261 |
self.redraw() |
684cdc352562
Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
1
diff
changeset
|
262 |