Package evas :: Module debug
[hide private]
[frames] | no frames]

Source Code for Module evas.debug

  1  # Copyright (C) 2007-2008 Gustavo Sverzut Barbieri 
  2  # 
  3  # This file is part of Python-Evas. 
  4  # 
  5  # Python-Evas is free software; you can redistribute it and/or 
  6  # modify it under the terms of the GNU Lesser General Public 
  7  # License as published by the Free Software Foundation; either 
  8  # version 2.1 of the License, or (at your option) any later version. 
  9  # 
 10  # Python-Evas is distributed in the hope that it will be useful, 
 11  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 12  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
 13  # Lesser General Public License for more details. 
 14  # 
 15  # You should have received a copy of the GNU Lesser General Public License 
 16  # along with this Python-Evas.  If not, see <http://www.gnu.org/licenses/>. 
 17   
 18  import evas 
 19  import evas.utils 
 20  import logging 
 21   
 22  log = logging.getLogger("evas.dbg") 
 23   
24 -class DebugObserver(object):
25 """Debug object events using an observer that prints debug messages. 26 27 Debug messages are printed using logging.debug() with "evas.dbg" logger. 28 29 One can control which messages to use by providing on_* parameter, later 30 used as attributes. 31 """
32 - def __init__(self, obj, 33 on_resize=True, 34 on_move=True, 35 on_hide=True, 36 on_show=True, 37 on_restack=False, 38 on_free=False, 39 on_mouse_in=False, 40 on_mouse_out=False, 41 on_mouse_down=False, 42 on_mouse_up=False, 43 on_mouse_move=False, 44 on_mouse_wheel=False, 45 on_key_down=False, 46 on_key_up=False, 47 on_focus_in=False, 48 on_focus_out=False):
49 self.on_resize = on_resize 50 self.on_move = on_move 51 self.on_hide = on_hide 52 self.on_show = on_show 53 self.on_restack = on_restack 54 self.on_free = on_free 55 self.on_mouse_in = on_mouse_in 56 self.on_mouse_out = on_mouse_out 57 self.on_mouse_down = on_mouse_down 58 self.on_mouse_up = on_mouse_up 59 self.on_mouse_move = on_mouse_move 60 self.on_mouse_wheel = on_mouse_wheel 61 self.on_key_down = on_key_down 62 self.on_key_up = on_key_up 63 self.on_focus_in = on_focus_in 64 self.on_focus_out = on_focus_out 65 evas.utils.connect_observer(obj, self) 66 self.obj = obj
67
68 - def unregister(self):
69 if self.obj: 70 evas.utils.disconnect_observer(self.obj, self) 71 self.obj = None
72
73 - def cb_on_resize(self, obj):
74 if self.on_resize: 75 w, h = obj.size_get() 76 log.debug("resize to %dx%d: %.20r...", w, h, obj)
77
78 - def cb_on_move(self, obj):
79 if self.on_move: 80 x, y = obj.pos_get() 81 log.debug("move to %d,%d: %.20r...", x, y, obj)
82
83 - def cb_on_hide(self, obj):
84 if self.on_hide: 85 log.debug("hide %.20r...", obj)
86
87 - def cb_on_show(self, obj):
88 if self.on_show: 89 log.debug("show %.20r...", obj)
90
91 - def cb_on_restack(self, obj):
92 if self.on_restack: 93 log.debug("restack %.20r...", obj)
94
95 - def cb_on_free(self, obj):
96 if self.on_free: 97 log.debug("clip unsset: %.20r...", obj)
98
99 - def cb_on_mouse_in(self, obj, e):
100 if self.on_mouse_in: 101 log.debug("mouse in %s: %.20r...", e, obj)
102
103 - def cb_on_mouse_out(self, obj, e):
104 if self.on_mouse_out: 105 log.debug("mouse out %s: %.20r...", e, obj)
106
107 - def cb_on_mouse_down(self, obj, e):
108 if self.on_mouse_down: 109 log.debug("mouse down %s: %.20r...", e, obj)
110
111 - def cb_on_mouse_up(self, obj, e):
112 if self.on_mouse_up: 113 log.debug("mouse up %s: %.20r...", e, obj)
114
115 - def cb_on_mouse_move(self, obj, e):
116 if self.on_mouse_move: 117 log.debug("mouse move %s: %.20r...", e, obj)
118
119 - def cb_on_mouse_wheel(self, obj, e):
120 if self.on_mouse_wheel: 121 log.debug("mouse wheel %s: %.20r...", e, obj)
122
123 - def cb_on_key_down(self, obj, e):
124 if self.on_key_down: 125 log.debug("key down %s: %.20r...", e, obj)
126
127 - def cb_on_key_up(self, obj, e):
128 if self.on_key_up: 129 log.debug("key up %s: %.20r...", e, obj)
130
131 - def cb_on_focus_in(self, obj, e):
132 if self.on_focus_in: 133 log.debug("focus in %s: %.20r...", e, obj)
134
135 - def cb_on_focus_out(self, obj, e):
136 if self.on_focus_out: 137 log.debug("focus out %s: %.20r...", e, obj)
138 139
140 -class VisualDebug(evas.ClippedSmartObject):
141 """Debug object events using an observer that lays on top of it. 142 143 This visual debug attaches an smart object that will follow the given 144 object and draw red lines on top and left and blue lines on bottom 145 and right with squares on these corners. 146 147 Text is used to display information: 148 - class, id, name 149 - geometry 150 - clip id, parent id 151 """
152 - def __init__(self, obj):
153 evas.ClippedSmartObject.__init__(self, obj.evas) 154 evas.utils.connect_observer(obj, self) 155 self.obj = obj 156 157 self.layer_set(self.obj.layer_get()) 158 self.stack_above(self.obj) 159 self.top = self.Rectangle(color=(255, 0, 0, 255)) 160 self.top.show() 161 self.left = self.Rectangle(color=(255, 0, 0, 255)) 162 self.left.show() 163 self.rel1 = self.Rectangle(color=(255, 0, 0, 255), size=(8, 8)) 164 self.rel1.show() 165 166 self.bottom = self.Rectangle(color=(0, 0, 255, 255)) 167 self.bottom.show() 168 self.right = self.Rectangle(color=(0, 0, 255, 255)) 169 self.right.show() 170 self.rel2 = self.Rectangle(color=(0, 0, 255, 255), size=(8, 8)) 171 self.rel2.show() 172 173 self.title = self.Text(color=(255, 255, 255, 255), 174 font=("sans", 10), 175 outline_color=(0, 0, 0, 255)) 176 self.title.style_set(evas.EVAS_TEXT_STYLE_SOFT_OUTLINE) 177 self.title.text_set("%s %#x %s" % 178 (self.obj.__class__.__name__, id(self.obj), 179 self.name_get())) 180 self.title.show() 181 182 self.desc = [] 183 for i in xrange(2): 184 t = self.Text(color=(255, 255, 255, 255), 185 font=("sans", 10), 186 outline_color=(0, 0, 0, 255)) 187 t.style_set(evas.EVAS_TEXT_STYLE_SOFT_OUTLINE) 188 t.show() 189 self.desc.append(t) 190 self.geometry_set(*self.obj.geometry_get()) 191 self._update_desc()
192
193 - def unregister(self):
194 if self.obj: 195 evas.utils.disconnect_observer(self.obj, self) 196 self.obj = None 197 self.hide()
198
199 - def show_desc(self):
200 self.title.show() 201 for d in self.desc: 202 d.show()
203
204 - def hide_desc(self):
205 self.title.hide() 206 for d in self.desc: 207 d.hide()
208
209 - def _update_desc(self):
210 clip = self.obj.clip_get() 211 if clip is None: 212 clip = 0 213 else: 214 clip = id(clip) 215 216 parent = self.obj.parent_get() 217 if parent is None: 218 parent = 0 219 else: 220 parent = id(parent) 221 self.desc[0].text_set("g=%s" % (self.obj.geometry_get(),)) 222 self.desc[1].text_set("c=%#x, p=%#x" % (clip, parent))
223
224 - def resize(self, w, h):
225 x, y = self.pos_get() 226 self.top.geometry_set(x - 1, y - 1, w + 2, 1) 227 self.bottom.geometry_set(x - 1, y + h + 1, w + 2, 1) 228 229 self.left.geometry_set(x - 1, y - 1, 1, h + 2) 230 self.right.geometry_set(x + w + 1, y - 1, 1, h + 2) 231 232 self.rel1.center_set(x, y) 233 self.rel2.center_set(x + w, y + h) 234 self.title.geometry_set(x, y, w, 20) 235 for i, d in enumerate(self.desc): 236 i += 1 237 d.geometry_set(x, y + 20 * i, w, 20)
238
239 - def cb_on_move(self, obj):
240 self.move(*obj.pos_get()) 241 self._update_desc()
242
243 - def cb_on_resize(self, obj):
244 self.resize(*obj.size_get()) 245 self._update_desc()
246
247 - def cb_on_restack(self, obj):
248 self.layer_set(self.obj.layer_get()) 249 self.stack_above(self.obj)
250
251 - def cb_on_hide(self, obj):
252 self.hide()
253
254 - def cb_on_show(self, obj):
255 self.show()
256
257 - def cb_on_free(self, obj):
258 self.delete()
259