Package ecore :: Package evas :: Module utils
[hide private]
[frames] | no frames]

Source Code for Module ecore.evas.utils

 1  # Copyright (C) 2007-2008 Gustavo Sverzut Barbieri 
 2  # 
 3  # This file is part of Python-Ecore. 
 4  # 
 5  # Python-Ecore 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-Ecore 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-Ecore.  If not, see <http://www.gnu.org/licenses/>. 
17   
18  __callbacks = ( 
19      "resize", 
20      "move", 
21      "show", 
22      "hide", 
23      "delete_request", 
24      "destroy", 
25      "focus_in", 
26      "focus_out", 
27      "sticky", 
28      "unsticky", 
29      "mouse_in", 
30      "mouse_out", 
31      "pre_render", 
32      "post_render", 
33      ) 
34   
35 -def __get_callback(observer, name):
36 try: 37 attr = getattr(observer, "cb_on_%s" % name) 38 if callable(attr): 39 return attr 40 except AttributeError, e: 41 return None
42
43 -def connect_observer(ecore_evas, observer):
44 """Connect methods from observer to Ecore_Evas callbacks. 45 46 Observer must have methods with name scheme: cb_on_<callback>, 47 examples: 48 - cb_on_resize 49 - cb_on_move 50 - cb_on_show 51 """ 52 for cb_name in __callbacks: 53 cb = __get_callback(observer, cb_name) 54 if cb: 55 setter = getattr(ecore_evas, "callback_%s_set" % cb_name) 56 setter(cb)
57 58
59 -def connect_callbacks_by_name(ecore_evas, mapping):
60 """Connect callbacks specified in mapping to Ecore_Evas callbacks. 61 62 Mapping must be a dict or a list of tuples with callback name and 63 desired function, example: 64 - mapping = (("resize", my_on_resize), ("show", my_on_show)) 65 - mapping = {"resize": my_on_resize, "show": my_on_show} 66 """ 67 if isinstance(mapping, dict): 68 mapping = mapping.iteritems() 69 for name, func in mapping: 70 try: 71 setter = getattr(ecore_evas, "callback_%s_set" % name) 72 except AttributeError, e: 73 raise ValueError("invalid callback name: %s" % name) 74 setter(func)
75