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