Mercurial > fife-parpg
annotate engine/extensions/pychan/properties.py @ 331:48c99636453e
Added Licence header to all pypthon modules in extension/
Commit 3k, Yay :-)
author | phoku@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Mon, 24 Aug 2009 12:01:34 +0000 |
parents | 4a5e8e638b0d |
children | 457e626296ba |
rev | line source |
---|---|
331
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
235
diff
changeset
|
1 #!/usr/bin/env python |
235
4a5e8e638b0d
Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
331
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
235
diff
changeset
|
3 |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
235
diff
changeset
|
4 # #################################################################### |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
235
diff
changeset
|
5 # Copyright (C) 2005-2009 by the FIFE team |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
235
diff
changeset
|
6 # http://www.fifengine.de |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
235
diff
changeset
|
7 # This file is part of FIFE. |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
235
diff
changeset
|
8 # |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
235
diff
changeset
|
9 # FIFE is free software; you can redistribute it and/or |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
235
diff
changeset
|
10 # modify it under the terms of the GNU Lesser General Public |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
235
diff
changeset
|
11 # License as published by the Free Software Foundation; either |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
235
diff
changeset
|
12 # version 2.1 of the License, or (at your option) any later version. |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
235
diff
changeset
|
13 # |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
235
diff
changeset
|
14 # This library is distributed in the hope that it will be useful, |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
235
diff
changeset
|
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
235
diff
changeset
|
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
235
diff
changeset
|
17 # Lesser General Public License for more details. |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
235
diff
changeset
|
18 # |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
235
diff
changeset
|
19 # You should have received a copy of the GNU Lesser General Public |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
235
diff
changeset
|
20 # License along with this library; if not, write to the |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
235
diff
changeset
|
21 # Free Software Foundation, Inc., |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
235
diff
changeset
|
22 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
235
diff
changeset
|
23 # #################################################################### |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
235
diff
changeset
|
24 |
235
4a5e8e638b0d
Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
25 import fife |
4a5e8e638b0d
Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
26 |
4a5e8e638b0d
Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
27 """ |
4a5e8e638b0d
Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
28 Property bindings |
4a5e8e638b0d
Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
29 ================= |
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 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
|
32 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
|
33 |
4a5e8e638b0d
Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
34 """ |
4a5e8e638b0d
Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
35 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
|
36 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
|
37 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
|
38 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
|
39 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
|
40 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
|
41 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
|
42 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
|
43 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
|
44 |
4a5e8e638b0d
Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
45 |
4a5e8e638b0d
Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
46 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
|
47 """ |
4a5e8e638b0d
Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
48 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
|
49 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
|
50 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
|
51 |
4a5e8e638b0d
Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
52 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
|
53 """ |
4a5e8e638b0d
Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
54 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
|
55 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
|
56 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
|
57 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
|
58 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
|
59 else: |
4a5e8e638b0d
Added the 'position_techinque' attr, so it can be used from XML.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
60 # 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
|
61 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
|
62 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
|
63 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
|
64 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
|
65 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
|
66 |