author | Radek Brich <radek.brich@devl.cz> |
Wed, 03 Sep 2014 19:17:04 +0200 | |
changeset 112 | ce2e67e7bbb8 |
parent 111 | b055add74b18 |
child 113 | 6796adfdc7eb |
permissions | -rw-r--r-- |
87
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
1 |
from tuikit.core.coords import Point, Size |
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. |
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
18 |
self.name = '{}{}'.format( |
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
19 |
self.__class__.__name__, |
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
20 |
self._num_instances) |
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
21 |
|
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
22 |
#: Parent Widget |
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
23 |
self.parent = None |
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
24 |
#: Window owning this Widget |
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
25 |
self.window = None |
89 | 26 |
#: Theme |
27 |
self.theme = default_theme |
|
87
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
28 |
|
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
29 |
#: 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
|
30 |
self.pos = Point() |
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
31 |
#: Actual size. Modified by layout manager. |
93 | 32 |
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
|
33 |
|
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. |
112 | 43 |
self._cursor = Point() |
44 |
#: Cursor is displayed on screen only if the widget is focused. |
|
45 |
self._cursor_visible = False |
|
97
0c2e0c09ba5c
Add TextField widget, keypress event, cursor.
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
46 |
|
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
|
47 |
#: 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
|
48 |
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
|
49 |
#: 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
|
50 |
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
|
51 |
|
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 |
self.sig_keypress = Signal(allow_stop=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
|
53 |
|
90
781774a8d568
Add timer, adjust inheritance of Widget, Container, Window.
Radek Brich <radek.brich@devl.cz>
parents:
89
diff
changeset
|
54 |
## position and size ## |
87
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
55 |
|
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
56 |
@property |
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
57 |
def x(self): |
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
58 |
return self.pos.x |
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
59 |
|
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
60 |
@property |
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
61 |
def y(self): |
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
62 |
return self.pos.y |
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
63 |
|
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
64 |
@property |
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
65 |
def width(self): |
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
66 |
return self.size.w |
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
67 |
|
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
68 |
@property |
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
69 |
def height(self): |
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
70 |
return self.size.h |
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
71 |
|
93 | 72 |
@property |
73 |
def size(self): |
|
74 |
return self._size.readonly() |
|
75 |
||
76 |
def resize(self, w, h): |
|
77 |
self._size.update(w, h) |
|
78 |
||
94
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
93
diff
changeset
|
79 |
## drawing, looks ## |
87
ee5ea9671f28
Add core Widget, Container. Add widgets Label.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
80 |
|
94
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
93
diff
changeset
|
81 |
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
|
82 |
"""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
|
83 |
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
|
84 |
buffer, buffer.origin, self.exposed(buffer)) |
89 | 85 |
|
86 |
def set_theme(self, theme): |
|
87 |
self.theme = theme |
|
90
781774a8d568
Add timer, adjust inheritance of Widget, Container, Window.
Radek Brich <radek.brich@devl.cz>
parents:
89
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 |
@staticmethod |
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
93
diff
changeset
|
90 |
def exposed(buffer): |
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
93
diff
changeset
|
91 |
"""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
|
92 |
|
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
93
diff
changeset
|
93 |
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
|
94 |
|
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
93
diff
changeset
|
95 |
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
|
96 |
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
|
97 |
|
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
93
diff
changeset
|
98 |
""" |
e50dae408fe9
Add origin to Buffer. Use it to simplify hierarchical drawing.
Radek Brich <radek.brich@devl.cz>
parents:
93
diff
changeset
|
99 |
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
|
100 |
|
97
0c2e0c09ba5c
Add TextField widget, keypress event, cursor.
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
101 |
@property |
0c2e0c09ba5c
Add TextField widget, keypress event, cursor.
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
102 |
def cursor(self): |
112 | 103 |
return self._cursor |
104 |
||
105 |
@property |
|
106 |
def cursor_visible(self): |
|
107 |
return self._cursor_visible |
|
97
0c2e0c09ba5c
Add TextField widget, keypress event, cursor.
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
108 |
|
111 | 109 |
## events ## |
97
0c2e0c09ba5c
Add TextField widget, keypress event, cursor.
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
110 |
|
111 | 111 |
def resize_event(self, ev): |
112 |
self.resize(ev.w, ev.h) |
|
113 |
||
114 |
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
|
115 |
"""Keypress event handler. |
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
|
116 |
|
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
|
117 |
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
|
118 |
|
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
|
119 |
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
|
120 |
|
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
|
121 |
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
|
122 |
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
|
123 |
|
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
|
124 |
""" |
111 | 125 |
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
|
126 |
return True |
111 | 127 |
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
|
128 |
|
90
781774a8d568
Add timer, adjust inheritance of Widget, Container, Window.
Radek Brich <radek.brich@devl.cz>
parents:
89
diff
changeset
|
129 |
## timeouts ## |
781774a8d568
Add timer, adjust inheritance of Widget, Container, Window.
Radek Brich <radek.brich@devl.cz>
parents:
89
diff
changeset
|
130 |
|
781774a8d568
Add timer, adjust inheritance of Widget, Container, Window.
Radek Brich <radek.brich@devl.cz>
parents:
89
diff
changeset
|
131 |
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
|
132 |
"""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
|
133 |
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
|
134 |
|
781774a8d568
Add timer, adjust inheritance of Widget, Container, Window.
Radek Brich <radek.brich@devl.cz>
parents:
89
diff
changeset
|
135 |
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
|
136 |
"""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
|
137 |
|
781774a8d568
Add timer, adjust inheritance of Widget, Container, Window.
Radek Brich <radek.brich@devl.cz>
parents:
89
diff
changeset
|
138 |
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
|
139 |
|
781774a8d568
Add timer, adjust inheritance of Widget, Container, Window.
Radek Brich <radek.brich@devl.cz>
parents:
89
diff
changeset
|
140 |
""" |
781774a8d568
Add timer, adjust inheritance of Widget, Container, Window.
Radek Brich <radek.brich@devl.cz>
parents:
89
diff
changeset
|
141 |
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
|
142 |
|
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
|
143 |
## 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
|
144 |
|
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
|
145 |
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
|
146 |
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
|
147 |
|
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
|
148 |
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
|
149 |
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
|
150 |
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
|
151 |
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
|
152 |
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
|
153 |
|
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
|
154 |
## 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
|
155 |
|
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
|
156 |
@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
|
157 |
def log(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
|
158 |
return logging.getLogger('tuikit.' + self.name) |