annotate 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
rev   line source
235
4a5e8e638b0d Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
1 # -*- coding: utf-8 -*-
4a5e8e638b0d Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
2 import fife
4a5e8e638b0d Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
3
4a5e8e638b0d Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
4 """
4a5e8e638b0d Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
5 Property bindings
4a5e8e638b0d Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
6 =================
4a5e8e638b0d Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
7
4a5e8e638b0d Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
8 This module contains a set of property bindings for
4a5e8e638b0d Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
9 the widgets, factored out to de-clutter the Widget.
4a5e8e638b0d Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
10
4a5e8e638b0d Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
11 """
4a5e8e638b0d Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
12 class WrappedProperty(object):
4a5e8e638b0d Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
13 def __init__(self, name):
4a5e8e638b0d Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
14 self.name = name
4a5e8e638b0d Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
15 def _getSetter(self,obj):
4a5e8e638b0d Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
16 setter_name = 'set' + self.name
4a5e8e638b0d Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
17 return getattr(obj.real_widget,setter_name)
4a5e8e638b0d Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
18 def _getGetter(self,obj):
4a5e8e638b0d Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
19 getter_name = 'get' + self.name
4a5e8e638b0d Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
20 return getattr(obj.real_widget,getter_name)
4a5e8e638b0d Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
21
4a5e8e638b0d Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
22
4a5e8e638b0d Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
23 class ColorProperty(WrappedProperty):
4a5e8e638b0d Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
24 """
4a5e8e638b0d Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
25 A color property. Fakes a color attribute of a guichan widget.
4a5e8e638b0d Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
26 This accepts either tuples of the colors (r,g,b)
4a5e8e638b0d Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
27 or L{fife.Color} objects.
4a5e8e638b0d Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
28
4a5e8e638b0d Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
29 Color objects have value semantics in this case.
4a5e8e638b0d Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
30 """
4a5e8e638b0d Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
31 def __init__(self, name):
4a5e8e638b0d Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
32 super(ColorProperty, self).__init__(name)
4a5e8e638b0d Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
33 def __set__(self, obj, color):
4a5e8e638b0d Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
34 if isinstance(color, tuple):
4a5e8e638b0d Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
35 color = fife.Color(*color)
4a5e8e638b0d Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
36 else:
4a5e8e638b0d Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
37 # Force a copy to get value semantics
4a5e8e638b0d Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
38 color = fife.Color(color.r,color.g,color.b,color.a)
4a5e8e638b0d Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
39 self._getSetter(obj)(color)
4a5e8e638b0d Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
40 def __get__(self, obj, objtype = None):
4a5e8e638b0d Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
41 color = self._getGetter(obj)()
4a5e8e638b0d Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
42 return fife.Color(color.r,color.g,color.b,color.a)
4a5e8e638b0d Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
43