From 7124f7c3c4a36e7d42bb51cd9fe47d76dd98efc9 Mon Sep 17 00:00:00 2001 From: Lionel Dricot Date: Wed, 25 Mar 2009 22:53:08 +0200 Subject: [PATCH] Fix bug 576733: animated-marker.py not working and not very pythonistic --- AUTHORS | 1 + bindings/python/demos/animated-marker.py | 199 ++++++++++++----------- 2 files changed, 106 insertions(+), 94 deletions(-) diff --git a/AUTHORS b/AUTHORS index 00dbc49..1bbb107 100644 --- a/AUTHORS +++ b/AUTHORS @@ -9,3 +9,4 @@ Denk Padje Mike Sheldon Emmanuel Rodriguez Emmanuele Bassi +Lionel Dricot diff --git a/bindings/python/demos/animated-marker.py b/bindings/python/demos/animated-marker.py index e7e218f..18f743a 100755 --- a/bindings/python/demos/animated-marker.py +++ b/bindings/python/demos/animated-marker.py @@ -1,5 +1,9 @@ #!/usr/bin/env python +#This is a demonstration of the libchamplain python binding. +#It will display a blue "pulsating" dot on a given position on the map +#A old legend that this position is the bed of Pierlux. You will have to find out... + import champlain import clutter import cluttercairo @@ -8,99 +12,106 @@ import math import gobject MARKER_SIZE = 10 - -def create_marker(): - - orange = clutter.Color(0xf3, 0x94, 0x07, 0xbb) - white = clutter.Color(0xff, 0xff, 0xff, 0xff) - timeline = clutter.Timeline() - - marker = champlain.Marker() - bg = cluttercairo.CairoTexture(MARKER_SIZE, MARKER_SIZE) - cr = bg.cairo_create() - - cr.set_source_rgb(0, 0, 0) - cr.arc(MARKER_SIZE / 2.0, MARKER_SIZE / 2.0, MARKER_SIZE / 2.0, 0, 2 * math.pi) - cr.close_path() - - cr.set_source_rgba(0.1, 0.1, 0.9, 1.0) - cr.fill() - - del cr - - marker.add(bg) - bg.set_anchor_point_from_gravity(clutter.GRAVITY_CENTER) - bg.set_position(0, 0) - - bg = cluttercairo.CairoTexture(2 * MARKER_SIZE, 2 * MARKER_SIZE) - cr = bg.cairo_create() - - cr.set_source_rgb(0, 0, 0) - cr.arc(MARKER_SIZE, MARKER_SIZE, 0.9 * MARKER_SIZE, 0, 2 * math.pi) - cr.close_path() - - cr.set_line_width(2.0) - cr.set_source_rgba(0.1, 0.1, 0.7, 1.0) - cr.stroke() - - del cr - - marker.add(bg) - bg.lower_bottom() - bg.set_position(0, 0) - bg.set_anchor_point_from_gravity(clutter.GRAVITY_CENTER) - - timeline.set_duration(1000) - timeline.set_loop(True) - - alpha = clutter.Alpha() - alpha.set_timeline(timeline) - alpha.set_func(clutter.sine_inc_func) - - behaviour = clutter.BehaviourScale(0.5, 0.5, 2.0, 2.0) - - behaviour.set_alpha(alpha) - behaviour.apply(bg) - - behaviour = clutter.BehaviourOpacity(255, 0) - behaviour.set_alpha(alpha) - behaviour.apply(bg) - - timeline.start() - - #Set marker position on the map - marker.set_position(45.528178, -73.563788) - - return marker; - - -def main(): - - gobject.threads_init() - - clutter.init() - stage = clutter.stage_get_default() - stage.set_size(800, 600) - - actor = champlain.View() - actor.set_size(800, 600) - stage.add(actor) - - layer = champlain.Layer() - layer.show() - actor.add_layer(layer) - - marker = create_marker() - layer.add(marker) - - # Finish initialising the map view - actor.set_property("zoom-level", 5) - actor.set_property("scroll-mode", champlain.SCROLL_MODE_KINETIC) - - actor.center_on(45.466, -73.75) - stage.show() - clutter.main() - +MARKER_COLOR = [0.1,0.1,0.9,1.0] + +POSITION = [45.528178, -73.563788] +SCREEN_SIZE = [800,600] + +#The AnimatedMarker will extend the champlain.Marker class +class AnimatedMarker(champlain.Marker) : + def __init__(self,color=None) : + champlain.Marker.__init__(self) + + orange = clutter.Color(0xf3, 0x94, 0x07, 0xbb) + white = clutter.Color(0xff, 0xff, 0xff, 0xff) + if not color : + color = MARKER_COLOR + + #Cairo definition of the inner marker + bg_in = cluttercairo.CairoTexture(MARKER_SIZE, MARKER_SIZE) + cr_in = bg_in.cairo_create() + cr_in.set_source_rgb(0, 0, 0) + cr_in.arc(MARKER_SIZE / 2.0, MARKER_SIZE / 2.0, MARKER_SIZE / 2.0, 0, 2 * math.pi) + cr_in.close_path() + cr_in.set_source_rgba(*color) + cr_in.fill() + self.add(bg_in) + bg_in.set_anchor_point_from_gravity(clutter.GRAVITY_CENTER) + bg_in.set_position(0, 0) + + #Cairo definition of the outside circle (that will be animated) + bg_out = cluttercairo.CairoTexture(2 * MARKER_SIZE, 2 * MARKER_SIZE) + cr_out = bg_out.cairo_create() + cr_out.set_source_rgb(0, 0, 0) + cr_out.arc(MARKER_SIZE, MARKER_SIZE, 0.9 * MARKER_SIZE, 0, 2 * math.pi) + cr_out.close_path() + cr_out.set_line_width(2.0) + cr_out.set_source_rgba(*color) + cr_out.stroke() + self.add(bg_out) + bg_out.lower_bottom() + bg_out.set_position(0, 0) + bg_out.set_anchor_point_from_gravity(clutter.GRAVITY_CENTER) + + #The timeline of our animation + self.timeline = clutter.Timeline() + self.timeline.set_duration(1000) + self.timeline.set_loop(True) + + self.alpha = clutter.Alpha() + self.alpha.set_timeline(self.timeline) + self.alpha.set_func(clutter.sine_inc_func) + + #The "growing" behaviour + self.grow_behaviour = clutter.BehaviourScale(0.5, 0.5, 2.0, 2.0) + self.grow_behaviour.set_alpha(self.alpha) + self.grow_behaviour.apply(bg_out) + + #The fade out behaviour + self.fade_behaviour = clutter.BehaviourOpacity(255, 0) + self.fade_behaviour.set_alpha(self.alpha) + self.fade_behaviour.apply(bg_out) + + #If you want the marked to be animated without calling start_animation + #Uncomment the following line + #self.timeline.start() + + def stop_animation(self) : + self.timeline.stop() + + def start_animation(self) : + self.timeline.start() + + +def main() : + gobject.threads_init() + clutter.init() + stage = clutter.stage_get_default() + actor = champlain.View() + layer = champlain.Layer() + marker = AnimatedMarker() + #Starting the animation, that's what we want after all ! + marker.start_animation() + #Set marker position on the map + marker.set_position(*POSITION) + + stage.set_size(*SCREEN_SIZE) + actor.set_size(*SCREEN_SIZE) + stage.add(actor) + + layer.show() + actor.add_layer(layer) + layer.add(marker) + + # Finish initialising the map view + actor.set_property("zoom-level", 5) + actor.set_property("scroll-mode", champlain.SCROLL_MODE_KINETIC) + actor.center_on(*POSITION) + + stage.show() + + clutter.main() + if __name__ == "__main__": - main() + main() -- 2.39.5