Mercurial > fife-parpg
comparison engine/extensions/pychan/properties.py @ 235:4a5e8e638b0d
Added the 'position_techinque' attr, so it can be used from XML.
Factored out color properties and made them have value semantics.
author | phoku@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Tue, 24 Mar 2009 08:09:57 +0000 |
parents | |
children | 48c99636453e |
comparison
equal
deleted
inserted
replaced
234:e4dfdf4c11fd | 235:4a5e8e638b0d |
---|---|
1 # -*- coding: utf-8 -*- | |
2 import fife | |
3 | |
4 """ | |
5 Property bindings | |
6 ================= | |
7 | |
8 This module contains a set of property bindings for | |
9 the widgets, factored out to de-clutter the Widget. | |
10 | |
11 """ | |
12 class WrappedProperty(object): | |
13 def __init__(self, name): | |
14 self.name = name | |
15 def _getSetter(self,obj): | |
16 setter_name = 'set' + self.name | |
17 return getattr(obj.real_widget,setter_name) | |
18 def _getGetter(self,obj): | |
19 getter_name = 'get' + self.name | |
20 return getattr(obj.real_widget,getter_name) | |
21 | |
22 | |
23 class ColorProperty(WrappedProperty): | |
24 """ | |
25 A color property. Fakes a color attribute of a guichan widget. | |
26 This accepts either tuples of the colors (r,g,b) | |
27 or L{fife.Color} objects. | |
28 | |
29 Color objects have value semantics in this case. | |
30 """ | |
31 def __init__(self, name): | |
32 super(ColorProperty, self).__init__(name) | |
33 def __set__(self, obj, color): | |
34 if isinstance(color, tuple): | |
35 color = fife.Color(*color) | |
36 else: | |
37 # Force a copy to get value semantics | |
38 color = fife.Color(color.r,color.g,color.b,color.a) | |
39 self._getSetter(obj)(color) | |
40 def __get__(self, obj, objtype = None): | |
41 color = self._getGetter(obj)() | |
42 return fife.Color(color.r,color.g,color.b,color.a) | |
43 |