author | Radek Brich <radek.brich@devl.cz> |
Sun, 02 Oct 2011 23:32:35 +0200 | |
changeset 15 | c55b4749e562 |
parent 13 | 19ebde2fd594 |
child 16 | 8791a7da6835 |
permissions | -rw-r--r-- |
0 | 1 |
# -*- coding: utf-8 -*- |
2 |
||
3 |
from .widget import Widget |
|
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
|
4 |
import logging |
0 | 5 |
|
13
19ebde2fd594
Add more generated documentation.
Radek Brich <radek.brich@devl.cz>
parents:
9
diff
changeset
|
6 |
|
0 | 7 |
class Container(Widget): |
13
19ebde2fd594
Add more generated documentation.
Radek Brich <radek.brich@devl.cz>
parents:
9
diff
changeset
|
8 |
|
19ebde2fd594
Add more generated documentation.
Radek Brich <radek.brich@devl.cz>
parents:
9
diff
changeset
|
9 |
'''Container widget. Base for any widget which can contain other widgets.''' |
19ebde2fd594
Add more generated documentation.
Radek Brich <radek.brich@devl.cz>
parents:
9
diff
changeset
|
10 |
|
0 | 11 |
def __init__(self, width = 10, height = 10): |
13
19ebde2fd594
Add more generated documentation.
Radek Brich <radek.brich@devl.cz>
parents:
9
diff
changeset
|
12 |
'''Create container of requested size.''' |
0 | 13 |
Widget.__init__(self, width, height) |
14 |
||
13
19ebde2fd594
Add more generated documentation.
Radek Brich <radek.brich@devl.cz>
parents:
9
diff
changeset
|
15 |
#: List of child widgets. |
0 | 16 |
self.children = [] |
13
19ebde2fd594
Add more generated documentation.
Radek Brich <radek.brich@devl.cz>
parents:
9
diff
changeset
|
17 |
|
0 | 18 |
self.mousechild = None |
19 |
||
13
19ebde2fd594
Add more generated documentation.
Radek Brich <radek.brich@devl.cz>
parents:
9
diff
changeset
|
20 |
#: Width of borders (left, top, right, bottom). |
19ebde2fd594
Add more generated documentation.
Radek Brich <radek.brich@devl.cz>
parents:
9
diff
changeset
|
21 |
#: Child widgets are placed within borders. |
19ebde2fd594
Add more generated documentation.
Radek Brich <radek.brich@devl.cz>
parents:
9
diff
changeset
|
22 |
self.borders = (0, 0, 0, 0) |
19ebde2fd594
Add more generated documentation.
Radek Brich <radek.brich@devl.cz>
parents:
9
diff
changeset
|
23 |
|
15 | 24 |
self._layout = None |
25 |
||
0 | 26 |
self.widthrequest = (None, None) |
27 |
self.heightrequest = (None, None) |
|
28 |
||
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
|
29 |
self.colorprefix = None |
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
|
30 |
|
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
|
31 |
self.trapfocus = False # if True, tab cycles inside container |
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
|
32 |
|
0 | 33 |
|
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
|
34 |
def add(self, widget, **kw): |
13
19ebde2fd594
Add more generated documentation.
Radek Brich <radek.brich@devl.cz>
parents:
9
diff
changeset
|
35 |
'''Add widget into this container.''' |
0 | 36 |
self.children.append(widget) |
37 |
widget.parent = self |
|
38 |
widget.settop(self.top) |
|
15 | 39 |
widget.hints.update(kw) |
0 | 40 |
|
41 |
||
42 |
def layout(self, layout): |
|
13
19ebde2fd594
Add more generated documentation.
Radek Brich <radek.brich@devl.cz>
parents:
9
diff
changeset
|
43 |
'''Set layout manager for placing child widgets.''' |
15 | 44 |
self._layout = layout |
0 | 45 |
layout.container = self |
46 |
self.connect('resize', layout.resize) |
|
47 |
||
48 |
||
49 |
def settop(self, top): |
|
13
19ebde2fd594
Add more generated documentation.
Radek Brich <radek.brich@devl.cz>
parents:
9
diff
changeset
|
50 |
'''Set top widget.''' |
0 | 51 |
self.top = top |
52 |
for child in self.children: |
|
53 |
child.settop(top) |
|
54 |
||
55 |
||
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
|
56 |
def focusnext(self): |
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
|
57 |
i = self.children.index(self.top.focuswidget) |
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
|
58 |
while True: |
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
|
59 |
i += 1 |
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
|
60 |
if i >= len(self.children): |
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
|
61 |
i = 0 |
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
|
62 |
if self.children[i].canfocus(): |
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
|
63 |
self.children[i].setfocus() |
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
|
64 |
break |
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
|
65 |
log = logging.getLogger('tuikit') |
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
|
66 |
log.debug(str(self.top.focuswidget.__class__)) |
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
|
67 |
|
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
|
68 |
|
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
|
69 |
def keypress(self, keyname, char): |
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
|
70 |
if keyname == 'tab': |
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
|
71 |
self.focusnext() |
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
|
72 |
return |
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
|
73 |
Widget.keypress(self, keyname, char) |
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
|
74 |
|
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
|
75 |
|
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
|
76 |
def resize(self): |
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
|
77 |
Widget.resize(self) |
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
|
78 |
for child in self.children: |
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 |
child.emit('resize') |
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
|
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:
2
diff
changeset
|
81 |
|
0 | 82 |
def draw(self, screen, x=0, y=0): |
2
684cdc352562
Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
1
diff
changeset
|
83 |
if self.hidden: |
684cdc352562
Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
1
diff
changeset
|
84 |
return |
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
|
85 |
|
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
|
86 |
screen.pushclip(x, y, self.width, self.height) |
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
|
87 |
if self.colorprefix: |
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
|
88 |
screen.pushcolorprefix(self.colorprefix) |
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
|
89 |
|
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
|
90 |
Widget.draw(self, screen, x, y) |
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
|
91 |
|
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
|
92 |
for child in [x for x in self.children if not x.allowlayout]: |
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
|
93 |
child.draw(screen, x + child.x, y + child.y) |
0 | 94 |
|
95 |
l, t, r, b = self.borders |
|
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
|
96 |
screen.pushclip(x+l, y+t, self.width-l-r, self.height-t-b) |
0 | 97 |
|
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
|
98 |
for child in [x for x in self.children if x.allowlayout]: |
0 | 99 |
child.draw(screen, x + child.x, y + child.y) |
100 |
||
101 |
screen.popclip() |
|
102 |
||
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
|
103 |
if self.colorprefix: |
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
|
104 |
screen.popcolorprefix() |
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
|
105 |
screen.popclip() |
0 | 106 |
|
107 |
||
108 |
def mousedown(self, ev): |
|
109 |
handled = False |
|
110 |
for child in reversed(self.children): |
|
111 |
if child.enclose(ev.wx, ev.wy): |
|
112 |
childev = ev.childevent(child) |
|
113 |
child.mousedown(childev) |
|
114 |
self.mousechild = child |
|
115 |
handled = True |
|
116 |
break |
|
117 |
if not handled: |
|
1
69318aba22bf
Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents:
0
diff
changeset
|
118 |
self.setfocus() |
0 | 119 |
self.handle('mousedown', ev) |
120 |
||
121 |
||
122 |
def mouseup(self, ev): |
|
123 |
if self.mousechild: |
|
124 |
childev = ev.childevent(self.mousechild) |
|
125 |
self.mousechild.mouseup(childev) |
|
126 |
self.mousechild = None |
|
127 |
else: |
|
128 |
self.handle('mouseup', ev) |
|
129 |
#handled = False |
|
130 |
#for child in self.children: |
|
131 |
#if child.enclose(ev.wx, ev.wy): |
|
132 |
#childev = ev.childevent(child) |
|
133 |
#child.mouseup(childev) |
|
134 |
#self.mousechild = child |
|
135 |
#handled = True |
|
136 |
#if not handled: |
|
137 |
#self.handle('mouseup', ev) |
|
138 |
||
139 |
||
140 |
def mousemove(self, ev): |
|
141 |
if self.mousechild: |
|
142 |
childev = ev.childevent(self.mousechild) |
|
143 |
self.mousechild.mousemove(childev) |
|
144 |
else: |
|
145 |
self.handle('mousemove', ev) |
|
146 |
||
147 |
||
148 |
def mousewheel(self, ev): |
|
149 |
handled = False |
|
150 |
for child in reversed(self.children): |
|
151 |
if child.enclose(ev.wx, ev.wy): |
|
152 |
childev = ev.childevent(child) |
|
153 |
child.mousewheel(childev) |
|
154 |
handled = True |
|
155 |
break |
|
156 |
if not handled: |
|
157 |
self.handle('mousewheel', ev) |