gifアニメーションを、wxの画面上で再生する方法

gifのアニメーションファイルは、通常の画像ファイルのようにwx.StaticBitmapで画面に貼り付けても静止画として表示されるだけ。アニメーションを再生させるには貼り付け方を変えなければいけない。どう変えるか?
wxPythonのデモの中に、複数のgifアニメーションを再生しているものがある(ファイル名は、AnimateCtrl.py)。そこで用いている貼り付け方法の概要は、

    ....
    ani = wx.animate.Animation(gifファイルのパス)
    ctrl = wx.animate.AnimationCtrl(self, -1, ani)
    ctrl.SetUseWindowBackgroundColour()
    ctrl.Play()
    ....

というもの。これだと動くアニメーションが画面に表示される。
Windowsでのデモだとこのように表示される。

しかし、環境を変えると(例えばLinuxなんかで)、動かなくなってしまう場合がでてくる。正確には、AttributeErrorでエラー終了する。なぜかと考えて、原因を調べる。
ちゃんと動くWindowsの場合。

IDLE 2.6.2
>>> import wx.animate
>>> dir(wx.animate)
['AC_DEFAULT_STYLE', 'AC_NO_AUTORESIZE', 'ANIMATION_TYPE_ANI', 'ANIMATION_TYPE_ANY', 
'ANIMATION_TYPE_GIF', 'ANIMATION_TYPE_INVALID', 'ANIM_DONOTREMOVE', 'ANIM_TOBACKGROUND', 
'ANIM_TOPREVIOUS', 'ANIM_UNSPECIFIED', 'AN_FIT_ANIMATION', 'Animation', 'AnimationBase', 
'AnimationCtrl', 'AnimationCtrlBase', 'AnimationCtrlNameStr', 'GIFAnimationCtrl', 
'NullAnimation', 'PreAnimationCtrl', '__builtins__', '__doc__', '__docfilter__', 
'__file__', '__name__', '__package__', '_animate', '_core', '_newclass', '_object', 
'_swig_getattr', '_swig_repr', '_swig_setattr', '_swig_setattr_nondynamic', 
'_swig_setattr_nondynamic_method', 'cvar', 'new', 'new_instancemethod', 'wx']

一方、AttributeErrorになるLinuxの場合。

Python 2.5.2 (r252:60911, Jan 24 2010, 17:44:40) 
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import wx.animate
>>> dir(wx.animate)
['ANIM_DONOTREMOVE', 'ANIM_TOBACKGROUND', 'ANIM_TOPREVIOUS', 'ANIM_UNSPECIFIED', 
'AN_FIT_ANIMATION', 'AnimationBase', 'AnimationBasePtr', 'AnimationControlNameStr', 
'AnimationPlayer', 'AnimationPlayerPtr', 'GIFAnimation', 'GIFAnimationCtrl', 
'GIFAnimationCtrlPtr', 'GIFAnimationPtr', 'PreGIFAnimationCtrl', '__builtins__', 
'__doc__', '__docfilter__', '__file__', '__name__', '_animate', '_core', '_newclass', 
'_object', '_swig_getattr', '_swig_setattr', '_swig_setattr_nondynamic', 
'_swig_setattr_nondynamic_method', 'cvar', 'wx']
>>>

あー、Linuxのwx.animateには、関数AnimationもAnimationCtrlもない。そこで、Linuxでも動かすことを考えたとき、どちらにも定義されている関数を使った実装をしよう。
始めのコード片を書き変えると、こんな感じになるか。

    ....
    ctrl = wx.animate.GIFAnimationCtrl(self, -1, 'gifファイルのパス')
    ctrl.GetPlayer().UseBackgroundColour(True)
    ctrl.Play()
    ....

これで、どちらの環境でも動くようになる。

参考:wxPython Animated Gif - Software Development | DaniWeb