author | Radek Brich <radek.brich@devl.cz> |
Sun, 15 Feb 2015 12:48:23 +0100 | |
changeset 114 | 26c02bd94bd9 |
parent 113 | 6796adfdc7eb |
child 117 | 8680c2333546 |
permissions | -rw-r--r-- |
104
742e504ec053
Update TextBox: Replace "spot" with "cursor".
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
1 |
from tuikit.core.coords import Point, Size, Rect |
89 | 2 |
from tuikit.core.theme import default_theme |
109
105b1affc3c2
Update keypress propagation. Allow focus change by tab key. Add log property to Widget for smart logging.
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
3 |
from tuikit.core.signal import Signal |
87
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
4 |
|
94
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
93
diff
changeset
|
5 |
import logging |
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
93
diff
changeset
|
6 |
|
87
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
7 |
|
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
8 |
class Widget: |
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
9 |
|
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
10 |
"""Base class for all widgets.""" |
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
11 |
|
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
12 |
_num_instances = 0 |
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
13 |
|
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
14 |
def __init__(self): |
94
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
93
diff
changeset
|
15 |
self._num_instances += 1 |
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
93
diff
changeset
|
16 |
|
87
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
17 |
#: Widget name is used for logging etc. Not visible anywhere. |
105 | 18 |
self.name = '%s#%s' % (self.__class__.__name__, self._num_instances) |
87
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
19 |
|
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
20 |
#: Parent Widget |
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
21 |
self.parent = None |
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
22 |
#: Window owning this Widget |
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
23 |
self.window = None |
89 | 24 |
#: Theme |
25 |
self.theme = default_theme |
|
87
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
26 |
|
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
27 |
#: Position inside parent widget. Modified by layout manager. |
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
28 |
self.pos = Point() |
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
29 |
#: Actual size. Modified by layout manager. |
93 | 30 |
self._size = Size(10, 10) |
90
781774a8d568
Add timer, adjust inheritance of Widget, Container, Window.
Radek Brich <radek.brich@devl.cz>
parents:
89
diff
changeset
|
31 |
|
114
26c02bd94bd9
Add Widget.posreq. Add OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents:
113
diff
changeset
|
32 |
#: Requested position. Layout manager will use this when placing the widget. |
26c02bd94bd9
Add Widget.posreq. Add OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents:
113
diff
changeset
|
33 |
self.posreq = Point() |
87
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
34 |
#: Requested size. Layout manager will use this when placing the widget. |
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
35 |
self.sizereq = Size(1, 1) |
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
36 |
#: Minimal size of widget. Widget will never be sized smaller than this. |
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
37 |
self.sizemin = Size(1, 1) |
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
38 |
#: Maximum size of widget. Widget will never be sized bigger than this. |
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
39 |
#: None means no maximum size (infinite). |
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
40 |
self.sizemax = Size(None, None) |
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
41 |
|
97
0c2e0c09ba5c
Add TextField widget, keypress event, cursor.
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
42 |
#: Cursor is position where text input will occur. |
104
742e504ec053
Update TextBox: Replace "spot" with "cursor".
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
43 |
#: The cursor coordinates are relative to widget. |
112 | 44 |
self._cursor = Point() |
113 | 45 |
#: Cursor is displayed on screen only when the widget is focused. |
112 | 46 |
self._cursor_visible = False |
97
0c2e0c09ba5c
Add TextField widget, keypress event, cursor.
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
47 |
|
109
105b1affc3c2
Update keypress propagation. Allow focus change by tab key. Add log property to Widget for smart logging.
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
48 |
#: Hidden widget does not affect layout. |
105b1affc3c2
Update keypress propagation. Allow focus change by tab key. Add log property to Widget for smart logging.
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
49 |
self.hidden = False |
105b1affc3c2
Update keypress propagation. Allow focus change by tab key. Add log property to Widget for smart logging.
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
50 |
#: Allow keyboard focus for this widget. |
105b1affc3c2
Update keypress propagation. Allow focus change by tab key. Add log property to Widget for smart logging.
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
51 |
self.allow_focus = False |
105b1affc3c2
Update keypress propagation. Allow focus change by tab key. Add log property to Widget for smart logging.
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
52 |
|
105b1affc3c2
Update keypress propagation. Allow focus change by tab key. Add log property to Widget for smart logging.
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
53 |
self.sig_keypress = Signal(allow_stop=True) |
105 | 54 |
|
90
781774a8d568
Add timer, adjust inheritance of Widget, Container, Window.
Radek Brich <radek.brich@devl.cz>
parents:
89
diff
changeset
|
55 |
## position and size ## |
87
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
56 |
|
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
57 |
@property |
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
58 |
def x(self): |
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
59 |
return self.pos.x |
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
60 |
|
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
61 |
@property |
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
62 |
def y(self): |
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
63 |
return self.pos.y |
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
64 |
|
114
26c02bd94bd9
Add Widget.posreq. Add OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents:
113
diff
changeset
|
65 |
def move(self, x, y): |
26c02bd94bd9
Add Widget.posreq. Add OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents:
113
diff
changeset
|
66 |
"""Should be called only by layout manager.""" |
26c02bd94bd9
Add Widget.posreq. Add OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents:
113
diff
changeset
|
67 |
self.pos.update(x, y) |
26c02bd94bd9
Add Widget.posreq. Add OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents:
113
diff
changeset
|
68 |
|
87
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
69 |
@property |
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
70 |
def width(self): |
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
71 |
return self.size.w |
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
72 |
|
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
73 |
@property |
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
74 |
def height(self): |
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
75 |
return self.size.h |
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
76 |
|
93 | 77 |
@property |
78 |
def size(self): |
|
107
1822c37b2688
Refactoring. Add ImmutablePoint.
Radek Brich <radek.brich@devl.cz>
parents:
106
diff
changeset
|
79 |
return self._size.immutable() |
93 | 80 |
|
81 |
def resize(self, w, h): |
|
114
26c02bd94bd9
Add Widget.posreq. Add OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents:
113
diff
changeset
|
82 |
"""Should be called only by layout manager.""" |
93 | 83 |
self._size.update(w, h) |
84 |
||
106
abcadb7e2ef1
Use Point for mouse events, add them to Container and Widget.
Radek Brich <radek.brich@devl.cz>
parents:
105
diff
changeset
|
85 |
@property |
abcadb7e2ef1
Use Point for mouse events, add them to Container and Widget.
Radek Brich <radek.brich@devl.cz>
parents:
105
diff
changeset
|
86 |
def boundaries(self): |
abcadb7e2ef1
Use Point for mouse events, add them to Container and Widget.
Radek Brich <radek.brich@devl.cz>
parents:
105
diff
changeset
|
87 |
return Rect._make(self.pos, self._size) |
abcadb7e2ef1
Use Point for mouse events, add them to Container and Widget.
Radek Brich <radek.brich@devl.cz>
parents:
105
diff
changeset
|
88 |
|
94
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
93
diff
changeset
|
89 |
## drawing, looks ## |
87
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
90 |
|
94
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
93
diff
changeset
|
91 |
def draw(self, buffer): |
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
93
diff
changeset
|
92 |
"""Draw self into buffer.""" |
109
105b1affc3c2
Update keypress propagation. Allow focus change by tab key. Add log property to Widget for smart logging.
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
93 |
self.log.debug('Draw into %r at %s (exposed %s)', |
105b1affc3c2
Update keypress propagation. Allow focus change by tab key. Add log property to Widget for smart logging.
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
94 |
buffer, buffer.origin, self.exposed(buffer)) |
89 | 95 |
|
96 |
def set_theme(self, theme): |
|
97 |
self.theme = theme |
|
90
781774a8d568
Add timer, adjust inheritance of Widget, Container, Window.
Radek Brich <radek.brich@devl.cz>
parents:
89
diff
changeset
|
98 |
|
94
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
93
diff
changeset
|
99 |
@staticmethod |
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
93
diff
changeset
|
100 |
def exposed(buffer): |
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
93
diff
changeset
|
101 |
"""Exposed part of widget. |
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
93
diff
changeset
|
102 |
|
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
93
diff
changeset
|
103 |
Only this area needs to be drawn. |
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
93
diff
changeset
|
104 |
|
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
93
diff
changeset
|
105 |
Returns exposed Rect in widget's local coordinates, |
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
93
diff
changeset
|
106 |
where 0,0 is left top corner of widget to be drawn. |
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
93
diff
changeset
|
107 |
|
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
93
diff
changeset
|
108 |
""" |
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
93
diff
changeset
|
109 |
return buffer.clip_rect.moved(-buffer.origin.x, -buffer.origin.y) |
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
93
diff
changeset
|
110 |
|
97
0c2e0c09ba5c
Add TextField widget, keypress event, cursor.
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
111 |
@property |
0c2e0c09ba5c
Add TextField widget, keypress event, cursor.
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
112 |
def cursor(self): |
113 | 113 |
"""Return cursor coordinates. |
114 |
||
115 |
Returns None if cursor is set outside of widget boundaries. |
|
116 |
||
117 |
""" |
|
104
742e504ec053
Update TextBox: Replace "spot" with "cursor".
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
118 |
if self._cursor in Rect._make((0, 0), self._size): |
742e504ec053
Update TextBox: Replace "spot" with "cursor".
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
119 |
return self._cursor |
97
0c2e0c09ba5c
Add TextField widget, keypress event, cursor.
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
120 |
|
112 | 121 |
@property |
122 |
def cursor_visible(self): |
|
123 |
return self._cursor_visible |
|
97
0c2e0c09ba5c
Add TextField widget, keypress event, cursor.
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
124 |
|
111 | 125 |
## events ## |
97
0c2e0c09ba5c
Add TextField widget, keypress event, cursor.
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
126 |
|
111 | 127 |
def resize_event(self, ev): |
128 |
self.resize(ev.w, ev.h) |
|
129 |
||
130 |
def keypress_event(self, ev): |
|
109
105b1affc3c2
Update keypress propagation. Allow focus change by tab key. Add log property to Widget for smart logging.
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
131 |
"""Keypress event handler. |
97
0c2e0c09ba5c
Add TextField widget, keypress event, cursor.
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
132 |
|
109
105b1affc3c2
Update keypress propagation. Allow focus change by tab key. Add log property to Widget for smart logging.
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
133 |
Override to accept keyboard input. |
105b1affc3c2
Update keypress propagation. Allow focus change by tab key. Add log property to Widget for smart logging.
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
134 |
|
105b1affc3c2
Update keypress propagation. Allow focus change by tab key. Add log property to Widget for smart logging.
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
135 |
Returns True if event was consumed. |
105b1affc3c2
Update keypress propagation. Allow focus change by tab key. Add log property to Widget for smart logging.
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
136 |
|
105b1affc3c2
Update keypress propagation. Allow focus change by tab key. Add log property to Widget for smart logging.
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
137 |
Call this implementation from inherited classes |
105b1affc3c2
Update keypress propagation. Allow focus change by tab key. Add log property to Widget for smart logging.
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
138 |
if it does not consume the event. |
105b1affc3c2
Update keypress propagation. Allow focus change by tab key. Add log property to Widget for smart logging.
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
139 |
|
105b1affc3c2
Update keypress propagation. Allow focus change by tab key. Add log property to Widget for smart logging.
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
140 |
""" |
111 | 141 |
if self.sig_keypress(ev): |
109
105b1affc3c2
Update keypress propagation. Allow focus change by tab key. Add log property to Widget for smart logging.
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
142 |
return True |
111 | 143 |
self.log.debug('Not consumed: %s', ev) |
97
0c2e0c09ba5c
Add TextField widget, keypress event, cursor.
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
144 |
|
106
abcadb7e2ef1
Use Point for mouse events, add them to Container and Widget.
Radek Brich <radek.brich@devl.cz>
parents:
105
diff
changeset
|
145 |
def mousedown(self, button, pos): |
abcadb7e2ef1
Use Point for mouse events, add them to Container and Widget.
Radek Brich <radek.brich@devl.cz>
parents:
105
diff
changeset
|
146 |
self._log.debug('mousedown(btn=%r, pos=%r)', |
abcadb7e2ef1
Use Point for mouse events, add them to Container and Widget.
Radek Brich <radek.brich@devl.cz>
parents:
105
diff
changeset
|
147 |
button, pos) |
abcadb7e2ef1
Use Point for mouse events, add them to Container and Widget.
Radek Brich <radek.brich@devl.cz>
parents:
105
diff
changeset
|
148 |
|
abcadb7e2ef1
Use Point for mouse events, add them to Container and Widget.
Radek Brich <radek.brich@devl.cz>
parents:
105
diff
changeset
|
149 |
def mouseup(self, button, pos): |
abcadb7e2ef1
Use Point for mouse events, add them to Container and Widget.
Radek Brich <radek.brich@devl.cz>
parents:
105
diff
changeset
|
150 |
self._log.debug('mouseup(btn=%r, pos=%r)', |
abcadb7e2ef1
Use Point for mouse events, add them to Container and Widget.
Radek Brich <radek.brich@devl.cz>
parents:
105
diff
changeset
|
151 |
button, pos) |
abcadb7e2ef1
Use Point for mouse events, add them to Container and Widget.
Radek Brich <radek.brich@devl.cz>
parents:
105
diff
changeset
|
152 |
|
abcadb7e2ef1
Use Point for mouse events, add them to Container and Widget.
Radek Brich <radek.brich@devl.cz>
parents:
105
diff
changeset
|
153 |
def mousemove(self, button, pos, relpos): |
abcadb7e2ef1
Use Point for mouse events, add them to Container and Widget.
Radek Brich <radek.brich@devl.cz>
parents:
105
diff
changeset
|
154 |
self._log.debug('mousemove(btn=%r, pos=%r, relpos=%r)', |
abcadb7e2ef1
Use Point for mouse events, add them to Container and Widget.
Radek Brich <radek.brich@devl.cz>
parents:
105
diff
changeset
|
155 |
button, pos, relpos) |
abcadb7e2ef1
Use Point for mouse events, add them to Container and Widget.
Radek Brich <radek.brich@devl.cz>
parents:
105
diff
changeset
|
156 |
|
90
781774a8d568
Add timer, adjust inheritance of Widget, Container, Window.
Radek Brich <radek.brich@devl.cz>
parents:
89
diff
changeset
|
157 |
## timeouts ## |
781774a8d568
Add timer, adjust inheritance of Widget, Container, Window.
Radek Brich <radek.brich@devl.cz>
parents:
89
diff
changeset
|
158 |
|
781774a8d568
Add timer, adjust inheritance of Widget, Container, Window.
Radek Brich <radek.brich@devl.cz>
parents:
89
diff
changeset
|
159 |
def add_timeout(self, delay, callback, *args): |
781774a8d568
Add timer, adjust inheritance of Widget, Container, Window.
Radek Brich <radek.brich@devl.cz>
parents:
89
diff
changeset
|
160 |
"""Register `callback` to be called after `delay` seconds.""" |
781774a8d568
Add timer, adjust inheritance of Widget, Container, Window.
Radek Brich <radek.brich@devl.cz>
parents:
89
diff
changeset
|
161 |
self.parent.add_timeout(self, delay, callback, *args) |
781774a8d568
Add timer, adjust inheritance of Widget, Container, Window.
Radek Brich <radek.brich@devl.cz>
parents:
89
diff
changeset
|
162 |
|
781774a8d568
Add timer, adjust inheritance of Widget, Container, Window.
Radek Brich <radek.brich@devl.cz>
parents:
89
diff
changeset
|
163 |
def remove_timeout(self, callback, *args): |
781774a8d568
Add timer, adjust inheritance of Widget, Container, Window.
Radek Brich <radek.brich@devl.cz>
parents:
89
diff
changeset
|
164 |
"""Unregister callback previously registered with add_timeout. |
781774a8d568
Add timer, adjust inheritance of Widget, Container, Window.
Radek Brich <radek.brich@devl.cz>
parents:
89
diff
changeset
|
165 |
|
781774a8d568
Add timer, adjust inheritance of Widget, Container, Window.
Radek Brich <radek.brich@devl.cz>
parents:
89
diff
changeset
|
166 |
Removes all timeouts with the `callback` and `args`. |
781774a8d568
Add timer, adjust inheritance of Widget, Container, Window.
Radek Brich <radek.brich@devl.cz>
parents:
89
diff
changeset
|
167 |
|
781774a8d568
Add timer, adjust inheritance of Widget, Container, Window.
Radek Brich <radek.brich@devl.cz>
parents:
89
diff
changeset
|
168 |
""" |
781774a8d568
Add timer, adjust inheritance of Widget, Container, Window.
Radek Brich <radek.brich@devl.cz>
parents:
89
diff
changeset
|
169 |
self.parent.remove_timeout(self, callback, *args) |
109
105b1affc3c2
Update keypress propagation. Allow focus change by tab key. Add log property to Widget for smart logging.
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
170 |
|
105b1affc3c2
Update keypress propagation. Allow focus change by tab key. Add log property to Widget for smart logging.
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
171 |
## focus ## |
105b1affc3c2
Update keypress propagation. Allow focus change by tab key. Add log property to Widget for smart logging.
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
172 |
|
105b1affc3c2
Update keypress propagation. Allow focus change by tab key. Add log property to Widget for smart logging.
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
173 |
def can_focus(self): |
105b1affc3c2
Update keypress propagation. Allow focus change by tab key. Add log property to Widget for smart logging.
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
174 |
return not self.hidden and self.allow_focus |
105b1affc3c2
Update keypress propagation. Allow focus change by tab key. Add log property to Widget for smart logging.
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
175 |
|
105b1affc3c2
Update keypress propagation. Allow focus change by tab key. Add log property to Widget for smart logging.
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
176 |
def has_focus(self): |
105b1affc3c2
Update keypress propagation. Allow focus change by tab key. Add log property to Widget for smart logging.
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
177 |
if self.parent is None: |
105b1affc3c2
Update keypress propagation. Allow focus change by tab key. Add log property to Widget for smart logging.
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
178 |
return True |
105b1affc3c2
Update keypress propagation. Allow focus change by tab key. Add log property to Widget for smart logging.
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
179 |
return (self.parent.has_focus() |
105b1affc3c2
Update keypress propagation. Allow focus change by tab key. Add log property to Widget for smart logging.
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
180 |
and self.parent.focus_widget == self) |
105b1affc3c2
Update keypress propagation. Allow focus change by tab key. Add log property to Widget for smart logging.
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
181 |
|
105b1affc3c2
Update keypress propagation. Allow focus change by tab key. Add log property to Widget for smart logging.
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
182 |
## utilities ## |
105b1affc3c2
Update keypress propagation. Allow focus change by tab key. Add log property to Widget for smart logging.
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
183 |
|
105b1affc3c2
Update keypress propagation. Allow focus change by tab key. Add log property to Widget for smart logging.
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
184 |
@property |
105b1affc3c2
Update keypress propagation. Allow focus change by tab key. Add log property to Widget for smart logging.
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
185 |
def log(self): |
113 | 186 |
"""Logger for widget debugging. |
187 |
||
188 |
Logger name contains full module name, class name and instance number. |
|
189 |
||
190 |
""" |
|
191 |
return logging.getLogger('%s.%s' % (self.__module__, self.name)) |