@@ -46,6 +46,8 @@ class GifOverlay(base.VideoOverlay):
4646 base_size = None
4747 #: The :class:`~cairo.Matrix` defining the zoom & shift to scale the gif
4848 transform = None
49+ #: `int` tracking the callback for the next redraw
50+ loop = - 1
4951
5052 def __init__ (self , * args , ** kwargs ):
5153 super (GifOverlay , self ).__init__ (* args , ** kwargs )
@@ -59,6 +61,15 @@ def __init__(self, *args, **kwargs):
5961 self .movie_zone .connect ('configure-event' , self .set_transform )
6062
6163
64+ def unload (self ):
65+ """ Unload the media file and tear down playback mechanisms.
66+ """
67+ if self .loop >= 0 :
68+ GLib .Source .remove (self .loop )
69+ self .loop = - 1
70+ self .anim_iter = None
71+ self .anim = None
72+
6273 def _set_file (self , filepath ):
6374 """ Sets the media file to be played by the widget.
6475
@@ -101,12 +112,18 @@ def draw(self, widget, ctx):
101112 def advance_gif (self ):
102113 """ Advance the gif, queue redrawing if the frame changed, and schedule the next frame.
103114 """
115+ if self .anim_iter is None :
116+ return False
117+
104118 if self .anim_iter .advance ():
105119 self .movie_zone .queue_draw ()
106120
107121 delay = self .anim_iter .get_delay_time ()
108122 if delay >= 0 :
109- GLib .timeout_add (delay , self .advance_gif )
123+ self .loop = GLib .timeout_add (interval = delay , function = self .advance_gif )
124+ else :
125+ self .loop = - 1
126+ return False
110127
111128
112129 def do_set_time (self , t ):
0 commit comments