comparison demos/pychan_demo/colortester.py @ 438:db994c01cc9a

- added color tester app to pychan demo FEATURES: - use sliders to paint background and base rgba color of some example widgets
author chewie@33b003aa-7bff-0310-803a-e67f0ece8222
date Tue, 02 Mar 2010 11:49:27 +0000
parents
children 59c92d10d7bc
comparison
equal deleted inserted replaced
437:e236185eec40 438:db994c01cc9a
1 # -*- coding: utf-8 -*-
2
3 # ####################################################################
4 # Copyright (C) 2005-2010 by the FIFE team
5 # http://www.fifengine.de
6 # This file is part of FIFE.
7 #
8 # FIFE is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU Lesser General Public
10 # License as published by the Free Software Foundation; either
11 # version 2.1 of the License, or (at your option) any later version.
12 #
13 # This library is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # Lesser General Public License for more details.
17 #
18 # You should have received a copy of the GNU Lesser General Public
19 # License along with this library; if not, write to the
20 # Free Software Foundation, Inc.,
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 # ####################################################################
23
24 """ pychan demo app for testing rgba colors on widgets """
25
26 from pychan_test import PyChanExample
27 from fife.extensions import pychan
28
29 class ColorExample(PyChanExample):
30 """ a small app (^^) to show how guichan uses colors on various widgets """
31 def __init__(self):
32 super(ColorExample,self).__init__('gui/colortester.xml')
33
34 def start(self):
35 """
36 load XML file and setup callbacks
37 """
38 self.widget = pychan.loadXML(self.xmlFile)
39 self.widget.mapEvents({
40 'base_rslider': self.update_basecolor,
41 'base_gslider': self.update_basecolor,
42 'base_bslider': self.update_basecolor,
43 'base_aslider': self.update_basecolor,
44
45 'background_rslider': self.update_background_color,
46 'background_gslider': self.update_background_color,
47 'background_bslider': self.update_background_color,
48 'background_aslider': self.update_background_color,
49
50 'closeButton':self.stop,
51 })
52 # alpha value needs to be set, otherwise you don't see colors ;-)
53 self.widget.findChild(name="base_aslider").setValue(float(255))
54 self.widget.findChild(name="background_aslider").setValue(float(255))
55
56 # init stuff
57 self.update_basecolor()
58 self.update_background_color()
59 self.widget.show()
60
61 def update_basecolor(self):
62 """
63 Update rgba base colors of all examples and show the values
64 """
65 r = int(self.widget.findChild(name="base_rslider").getValue())
66 g = int(self.widget.findChild(name="base_gslider").getValue())
67 b = int(self.widget.findChild(name="base_bslider").getValue())
68 a = int(self.widget.findChild(name="base_aslider").getValue())
69
70 # update slider labels
71 self.widget.findChild(name="base_rvalue").text = unicode(str(r), "utf-8")
72 self.widget.findChild(name="base_gvalue").text = unicode(str(g), "utf-8")
73 self.widget.findChild(name="base_bvalue").text = unicode(str(b), "utf-8")
74 self.widget.findChild(name="base_avalue").text = unicode(str(a), "utf-8")
75
76 rgba = (r, g, b, a)
77
78 # background_color, foreground_color, base_color, selection_color (listbox)
79 self.widget.findChild(name="example1").base_color = rgba
80 self.widget.findChild(name="example2").base_color = rgba
81 self.widget.findChild(name="example3").base_color = rgba
82 self.widget.findChild(name="example4").base_color = rgba
83 self.widget.findChild(name="example5").base_color = rgba
84 self.widget.findChild(name="example6").base_color = rgba
85 self.widget.findChild(name="example7").base_color = rgba
86 self.widget.findChild(name="example8").base_color = rgba
87
88 def update_background_color(self):
89 """
90 Update rgba background colors of all examples and show the values
91 """
92 r = int(self.widget.findChild(name="background_rslider").getValue())
93 g = int(self.widget.findChild(name="background_gslider").getValue())
94 b = int(self.widget.findChild(name="background_bslider").getValue())
95 a = int(self.widget.findChild(name="background_aslider").getValue())
96
97 # update slider labels
98 self.widget.findChild(name="background_rvalue").text = unicode(str(r), "utf-8")
99 self.widget.findChild(name="background_gvalue").text = unicode(str(g), "utf-8")
100 self.widget.findChild(name="background_bvalue").text = unicode(str(b), "utf-8")
101 self.widget.findChild(name="background_avalue").text = unicode(str(a), "utf-8")
102
103 rgba = (r, g, b, a)
104
105 # background_color, foreground_color, background_color, selection_color (listbox)
106 self.widget.findChild(name="example1").background_color = rgba
107 self.widget.findChild(name="example2").background_color = rgba
108 self.widget.findChild(name="example3").background_color = rgba
109 self.widget.findChild(name="example4").background_color = rgba
110 self.widget.findChild(name="example5").background_color = rgba
111 self.widget.findChild(name="example6").background_color = rgba
112 self.widget.findChild(name="example7").background_color = rgba
113 self.widget.findChild(name="example8").background_color = rgba