1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 from fife import fife
25 from exceptions import RuntimeError
26
30
31 """
32 Property bindings
33 =================
34
35 This module contains a set of property bindings for
36 the widgets, factored out to de-clutter the Widget.
37
38 """
43 setter_name = 'set' + self.name
44 return getattr(obj.real_widget,setter_name)
46 getter_name = 'get' + self.name
47 return getattr(obj.real_widget,getter_name)
48
49
51 """
52 A color property. Fakes a color attribute of a guichan widget.
53 This accepts either tuples of the colors (r,g,b)
54 or L{fife.Color} objects.
55
56 Color objects have value semantics in this case.
57 """
61 if isinstance(color, tuple):
62 color = fife.Color(*color)
63 else:
64
65 color = fife.Color(color.r,color.g,color.b,color.a)
66 self._getSetter(obj)(color)
67 - def __get__(self, obj, objtype = None):
70
72 """
73 This unifies the way Images and Image attributes are handled
74 inside PyChan.
75 """
80 image_info = getattr(obj, self.prop_name, {})
81 if not image:
82 image_info["source"] = ""
83 image_info["image"] = fife.GuiImage()
84 image_info["image"]._source = ""
85 self._getSetter(obj)(None)
86
87 elif isinstance(image, str):
88 image_info["source"] = image
89
90
91
92 image_info["image"] = get_manager().loadImage(image)
93 image_info["image"].source = image
94 self._getSetter(obj)(image_info["image"])
95
96 elif isinstance(image,fife.GuiImage):
97
98
99
100 image_info["source"] = getattr(image,"source","")
101 image_info["image"] = image
102 if image_info["source"]:
103 image_info["image"] = get_manager().loadImage(image_info["source"])
104 self._getSetter(obj)(image_info["image"])
105 else:
106 attribute_name = "%s.%s" % (obj.__class__.__name__,self.name)
107 error_message = "%s only accepts GuiImage and python strings, not '%s'"
108 raise RuntimeError(error_message % (attribute_name, repr(image)))
109
110 setattr(obj, self.prop_name, image_info)
111
112 - def __get__(self, obj, objtype = None):
119