Update to the french documentation
[adesklets.git] / test / fading.py
blob07c7a2bae1e7725d5661f222e3d968f4d69b84da
1 """
2 fading.py - S.Fourmanoit <syfou@users.sourceforge.net>, 2005
4 adesklets test script for indirect mode, introduced in adesklets 0.2.0:
6 - It creates a transpaent window of the same size than supplied image
7 ('image/frog.png'; you do not like it? Maybe, but it's mine)
8 - It then draws the image on in
9 - It checks for the cursor entering and leaving its window visible parts,
10 firing a half second fade-out effect (ten frames) on leaving,
11 interrupting it as needed by new cursor change of position
13 To try it:
14 - Install adesklets with both python support enabled (default)
15 and GNU history support (default)
16 - Run python fading.py from this directory
17 """
18 import adesklets
20 class My_Events(adesklets.Events_handler):
21 witdh = 1
22 height = 1
23 fade = ()
24 image = 'images/frog.png'
26 def __init__(self):
27 adesklets.Events_handler.__init__(self)
29 def __del__(self):
30 adesklets.Events_handler.__del__(self)
32 def ready(self):
33 # Load the image, set the window accordingly
35 adesklets.context_set_image(adesklets.load_image(self.image))
36 self.width=adesklets.image_get_width();
37 self.height=adesklets.image_get_height();
38 adesklets.window_resize(self.width,self.height)
40 # Let's create our ten step fading tool: a plain color modifier
42 adesklets.context_set_color_modifier(adesklets.create_color_modifier())
43 adesklets.set_color_modifier_tables(
44 range(0,256)*3 + [max(0,val-26) for val in range(0,256)])
46 # Now, let's toggle the interpreter mode,
47 # and record the complete fading sequence
49 adesklets.start_recording()
50 for i in range(1,11):
51 adesklets.context_set_image(3)
52 adesklets.apply_color_modifier()
53 adesklets.context_set_image(0)
54 adesklets.blend_image_onto_image(3,1,
55 0,0,self.width,self.height,
56 0,0,self.width,self.height)
57 adesklets.time_gate(i*.05)
58 self.fade = adesklets.stop_recording()
60 # Let's finish seting up the window
62 adesklets.context_set_blend(False)
63 self._display()
64 adesklets.play_set_abort_on_events(True) # <== Note this !
65 adesklets.window_set_transparency(True);
66 adesklets.window_show()
68 def leave_notify(self,delayed,x,y):
69 # Fade-out event handler...
71 if not delayed:
72 print 'Fading out...',
73 adesklets.context_set_image(2)
74 adesklets.clone_image()
75 if adesklets.play(*self.fade) is None:
76 print 'ended.'
77 else:
78 print 'interrupted.'
79 adesklets.free_image(3)
81 def menu_fire(self,delayed,id,str):
82 # This will get generated first whenever
83 # the user moves the window, so the LeaveNotify
84 # afterwards will get delayed, thus go unseen.
85 pass
87 def enter_notify(self,delayed,x,y):
88 # ...that can be aborted (not interrupted!) by this one.
90 self._display()
92 def _display(self):
93 # Reset the window to the original image
95 adesklets.context_set_image(0)
96 adesklets.blend_image_onto_image(2,1,
97 0,0,self.width,self.height,
98 0,0,self.width,self.height)
99 My_Events().pause()