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
14 - Install adesklets with both python support enabled (default)
15 and GNU history support (default)
16 - Run python fading.py from this directory
20 class My_Events(adesklets
.Events_handler
):
24 image
= 'images/frog.png'
27 adesklets
.Events_handler
.__init
__(self
)
30 adesklets
.Events_handler
.__del
__(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()
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)
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...
72 print 'Fading out...',
73 adesklets
.context_set_image(2)
74 adesklets
.clone_image()
75 if adesklets
.play(*self
.fade
) is None:
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.
87 def enter_notify(self
,delayed
,x
,y
):
88 # ...that can be aborted (not interrupted!) by this one.
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
)