author | Radek Brich <radek.brich@devl.cz> |
Sun, 10 Apr 2011 22:54:38 +0200 | |
changeset 5 | ae128c885d0f |
parent 2 | 684cdc352562 |
child 9 | 7175ed629a76 |
permissions | -rw-r--r-- |
0 | 1 |
# -*- coding: utf-8 -*- |
2 |
||
3 |
from .widget import Widget |
|
4 |
||
5 |
||
6 |
class Container(Widget): |
|
7 |
def __init__(self, width = 10, height = 10): |
|
8 |
Widget.__init__(self, width, height) |
|
9 |
||
10 |
self.children = [] |
|
11 |
self.mousechild = None |
|
12 |
||
13 |
self.borders = (0, 0, 0, 0) # left, top, right, bottom |
|
14 |
self.widthrequest = (None, None) |
|
15 |
self.heightrequest = (None, None) |
|
16 |
||
17 |
||
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
|
18 |
def add(self, widget, **kw): |
0 | 19 |
self.children.append(widget) |
20 |
widget.parent = self |
|
21 |
widget.settop(self.top) |
|
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
|
22 |
widget.layouthints.update(kw) |
0 | 23 |
|
24 |
||
25 |
def layout(self, layout): |
|
26 |
self.layout = layout |
|
27 |
layout.container = self |
|
28 |
self.connect('resize', layout.resize) |
|
29 |
||
30 |
||
31 |
def settop(self, top): |
|
32 |
self.top = top |
|
33 |
for child in self.children: |
|
34 |
child.settop(top) |
|
35 |
||
36 |
||
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
|
37 |
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
|
38 |
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
|
39 |
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
|
40 |
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
|
41 |
|
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
|
42 |
|
0 | 43 |
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
|
44 |
if self.hidden: |
684cdc352562
Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
1
diff
changeset
|
45 |
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
|
46 |
|
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
|
47 |
screen.pushclip(x, y, self.width, self.height) |
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
|
48 |
|
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
|
49 |
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
|
50 |
|
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
|
51 |
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
|
52 |
child.draw(screen, x + child.x, y + child.y) |
0 | 53 |
|
54 |
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
|
55 |
screen.pushclip(x+l, y+t, self.width-l-r, self.height-t-b) |
0 | 56 |
|
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
|
57 |
for child in [x for x in self.children if x.allowlayout]: |
0 | 58 |
child.draw(screen, x + child.x, y + child.y) |
59 |
||
60 |
screen.popclip() |
|
61 |
||
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
|
62 |
screen.popclip() |
0 | 63 |
|
64 |
||
65 |
def mousedown(self, ev): |
|
66 |
handled = False |
|
67 |
for child in reversed(self.children): |
|
68 |
if child.enclose(ev.wx, ev.wy): |
|
69 |
childev = ev.childevent(child) |
|
70 |
child.mousedown(childev) |
|
71 |
self.mousechild = child |
|
72 |
handled = True |
|
73 |
break |
|
74 |
if not handled: |
|
1
69318aba22bf
Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents:
0
diff
changeset
|
75 |
self.setfocus() |
0 | 76 |
self.handle('mousedown', ev) |
77 |
||
78 |
||
79 |
def mouseup(self, ev): |
|
80 |
if self.mousechild: |
|
81 |
childev = ev.childevent(self.mousechild) |
|
82 |
self.mousechild.mouseup(childev) |
|
83 |
self.mousechild = None |
|
84 |
else: |
|
85 |
self.handle('mouseup', ev) |
|
86 |
#handled = False |
|
87 |
#for child in self.children: |
|
88 |
#if child.enclose(ev.wx, ev.wy): |
|
89 |
#childev = ev.childevent(child) |
|
90 |
#child.mouseup(childev) |
|
91 |
#self.mousechild = child |
|
92 |
#handled = True |
|
93 |
#if not handled: |
|
94 |
#self.handle('mouseup', ev) |
|
95 |
||
96 |
||
97 |
def mousemove(self, ev): |
|
98 |
if self.mousechild: |
|
99 |
childev = ev.childevent(self.mousechild) |
|
100 |
self.mousechild.mousemove(childev) |
|
101 |
else: |
|
102 |
self.handle('mousemove', ev) |
|
103 |
||
104 |
||
105 |
def mousewheel(self, ev): |
|
106 |
handled = False |
|
107 |
for child in reversed(self.children): |
|
108 |
if child.enclose(ev.wx, ev.wy): |
|
109 |
childev = ev.childevent(child) |
|
110 |
child.mousewheel(childev) |
|
111 |
handled = True |
|
112 |
break |
|
113 |
if not handled: |
|
114 |
self.handle('mousewheel', ev) |