Mercurial > fife-parpg
annotate demos/pychan_demo/poc_gui_animation.py @ 697:ecaa4d98f05f tip
Abstracted the GUI code and refactored the GUIChan-specific code into its own module.
* Most of the GUIChan code has been refactored into its own gui/guichan module. However, references to the GuiFont class still persist in the Engine and GuiManager code and these will need further refactoring.
* GuiManager is now an abstract base class which specific implementations (e.g. GUIChan) should subclass.
* The GUIChan GUI code is now a concrete implementation of GuiManager, most of which is in the new GuiChanGuiManager class.
* The GUI code in the Console class has been refactored out of the Console and into the GUIChan module as its own GuiChanConsoleWidget class. The rest of the Console class related to executing commands was left largely unchanged.
* Existing client code may need to downcast the GuiManager pointer received from FIFE::Engine::getGuiManager() to GuiChanGuiManager, since not all functionality is represented in the GuiManager abstract base class. Python client code can use the new GuiChanGuiManager.castTo static method for this purpose.
author | M. George Hansen <technopolitica@gmail.com> |
---|---|
date | Sat, 18 Jun 2011 00:28:40 -1000 |
parents | 8c9cdcc9bc4f |
children |
rev | line source |
---|---|
600
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
1 # -*- coding: utf-8 -*- |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
2 # #################################################################### |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
3 # Copyright (C) 2005-2010 by the FIFE team |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
4 # http://www.fifengine.de |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
5 # This file is part of FIFE. |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
6 # |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
7 # FIFE is free software; you can redistribute it and/or |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
8 # modify it under the terms of the GNU Lesser General Public |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
9 # License as published by the Free Software Foundation; either |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
10 # version 2.1 of the License, or (at your option) any later version. |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
11 # |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
12 # This library is distributed in the hope that it will be useful, |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
15 # Lesser General Public License for more details. |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
16 # |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
17 # You should have received a copy of the GNU Lesser General Public |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
18 # License along with this library; if not, write to the |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
19 # Free Software Foundation, Inc., |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
20 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
21 # #################################################################### |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
22 |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
23 """ proof-of-concept pychan demo app to test gui animations """ |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
24 |
613
8c9cdcc9bc4f
Renaming pychan_test.py to pychan_demo.py to make it a bit more obvious which file to execute.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
600
diff
changeset
|
25 from pychan_demo import PyChanExample |
600
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
26 from fife.extensions import pychan |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
27 |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
28 from fife.extensions.pychan.tools import callbackWithArguments as cbwa |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
29 from fife.extensions.fife_timer import Timer |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
30 |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
31 import time |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
32 import random |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
33 |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
34 ACTION_MOVE = 1 |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
35 ACTION_RESIZE = 2 |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
36 ACTION_COLOR = 3 |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
37 ACTIONS = [ACTION_MOVE, ACTION_RESIZE, ACTION_COLOR] |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
38 |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
39 DEFAULT_DELAY = 10 |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
40 |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
41 class PocAnimations(PyChanExample): |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
42 """ a small app (^^) to show how gui animations ~could~ be |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
43 made by using B{fife.TimeEvent}s |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
44 """ |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
45 def __init__(self): |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
46 super(PocAnimations,self).__init__('gui/poc_guianimation.xml') |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
47 |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
48 self._move_timer = None |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
49 self._resize_timer = None |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
50 self._color_timer = None |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
51 |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
52 def start(self): |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
53 """ |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
54 load XML file and setup callbacks |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
55 """ |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
56 self.widget = pychan.loadXML(self.xmlFile) |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
57 |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
58 self.widget.mapEvents({ |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
59 'closeButton' : self.stop, |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
60 |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
61 'example_move' : cbwa(self._start_anim, type=ACTION_MOVE), |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
62 'example_color' : cbwa(self._start_anim, type=ACTION_COLOR), |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
63 'example_resize': cbwa(self._start_anim, type=ACTION_RESIZE), |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
64 'example_all' : self._anim_all, |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
65 'delay' : self._set_delay_display, |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
66 }) |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
67 |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
68 self.move_example_widget = self.widget.findChild(name="move") |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
69 self.mew = self.move_example_widget |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
70 |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
71 self.resize_example_widget = self.widget.findChild(name="resize") |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
72 self.rew = self.resize_example_widget |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
73 |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
74 self.color_example_widget = self.widget.findChild(name="color") |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
75 self.cew = self.color_example_widget |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
76 |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
77 self.delay_slider = self.widget.findChild(name="delay") |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
78 self.delay_slider.setValue(float(DEFAULT_DELAY)) |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
79 |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
80 self.delay_display = self.widget.findChild(name="delay_label") |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
81 self.delay_display.text = unicode(str(DEFAULT_DELAY)) |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
82 |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
83 self.little_matrix = [] |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
84 for x in range(1,4): |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
85 for y in range(1,4): |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
86 name = "color_%s_%s" % (x, y) |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
87 widget = self.widget.findChild(name=name) |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
88 self.little_matrix.append(widget) |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
89 |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
90 self.widget.adaptLayout(True) |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
91 self.widget.show() |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
92 |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
93 def _set_delay_display(self): |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
94 """ set delay display according to slider value """ |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
95 value = self.delay_slider.getValue() |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
96 self.delay_display.text = unicode(str(int(value))) |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
97 |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
98 def _anim_all(self): |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
99 """ fire all animations """ |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
100 for action in ACTIONS: |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
101 self._start_anim(type=action) |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
102 |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
103 def _start_anim(self, type=None): |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
104 """ start the animation of the given type """ |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
105 self._reset_anim(type) |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
106 kwargs = { |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
107 'delay' : int(self.delay_slider.getValue()), |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
108 'callback' : None, |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
109 'repeat' : 0, |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
110 } |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
111 if type == ACTION_MOVE: |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
112 kwargs['callback'] = self._move |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
113 self._move_timer = Timer(**kwargs) |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
114 self._move_timer.start() |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
115 elif type == ACTION_RESIZE: |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
116 kwargs['callback'] = self._resize |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
117 self._resize_timer = Timer(**kwargs) |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
118 self._resize_timer.start() |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
119 elif type == ACTION_COLOR: |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
120 kwargs['callback'] = self._color |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
121 self._color_timer = Timer(**kwargs) |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
122 self._color_timer.start() |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
123 |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
124 def _reset_anim(self, type=None): |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
125 """ undo changes made by the animation (but leave alone disco matrix ^^) """ |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
126 if type == ACTION_MOVE: |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
127 if self._move_timer: |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
128 self._move_timer.stop() |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
129 self.mew.position = 0, 0 |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
130 elif type == ACTION_RESIZE: |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
131 if self._resize_timer: |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
132 self._resize_timer.stop() |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
133 SIZE = 100, 100 |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
134 self.rew.size = SIZE |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
135 self.rew.min_size = SIZE |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
136 self.rew.max_size = SIZE |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
137 self.widget.findChild(name="resize_wrapper").adaptLayout() |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
138 elif type == ACTION_COLOR: |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
139 if self._color_timer: |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
140 self._color_timer.stop() |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
141 COLOR = 255, 255, 255, 100 |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
142 self.cew.base_color = COLOR |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
143 |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
144 def _move(self): |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
145 """ move the mew widget """ |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
146 position = list(self.mew.position) |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
147 if position[0] < 100: |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
148 position[0] += 1 |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
149 self.mew.position = position |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
150 else: |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
151 self._reset_anim(ACTION_MOVE) |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
152 |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
153 def _resize(self): |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
154 """ resize the rew widget """ |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
155 size = list(self.rew.size) |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
156 if size[0] > 0: |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
157 size[0] -= 1 |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
158 size[1] -= 1 |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
159 self.rew.size = size |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
160 self.rew.min_size = size |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
161 self.rew.max_size = size |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
162 else: |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
163 self._reset_anim(ACTION_RESIZE) |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
164 |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
165 def _color(self): |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
166 """ tint the cew widgets """ |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
167 color = self.cew.base_color |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
168 red = color.r |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
169 if red > 1: |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
170 red -= 1 |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
171 self.cew.base_color = (red, 255, 255, 100) |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
172 |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
173 # disco! |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
174 for widget in self.little_matrix: |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
175 color = tuple(random.randint(1,255) for i in range(1,5)) |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
176 widget.background_color = color |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
177 else: |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
178 self._reset_anim(ACTION_COLOR) |
427150724fe1
- added new pychan demo: gui animations
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
179 |