- 论坛徽章:
- 0
|
#!/usr/bin/python
#coding:gbk
import wx
import wx.animate
ID_PLAY = 1
ID_SET_NULL_ANIMATION = 2
ID_SET_INACTIVE_BITMAP = 3
ID_SET_NO_AUTO_RESIZE = 4
ID_SET_BGCOLOR = 5
class MyFrame(wx.Frame):
def __init__(self, parent, id, title, pos, size, style):
wx.Frame.__init__(self, parent, id, title, pos, size, style | wx.NO_FULL_REPAINT_ON_RESIZE)
self.app = wx.Panel(self, pos=(300, 300))
wx.EVT_MENU(self, wx.ID_STOP, self.OnStop)
wx.EVT_MENU(self, ID_PLAY, self.OnPlay)
wx.EVT_MENU(self, ID_SET_NULL_ANIMATION, self.OnSetNullAnimation)
wx.EVT_MENU(self, ID_SET_NO_AUTO_RESIZE, self.OnSetNoAutoResize)
wx.EVT_MENU(self, wx.ID_ABOUT, self.OnAbout)
wx.EVT_MENU(self, wx.ID_EXIT, self.OnQuit)
wx.EVT_MENU(self, ID_SET_BGCOLOR, self.OnSetBgColor)
wx.EVT_MENU(self, wx.ID_OPEN, self.OnOpen)
#wx.EVT_SIZE(self, self.OnSize)
wx.EVT_UPDATE_UI(self, wx.ID_ANY, self.OnUpdateUI)
sz = wx.BoxSizer(wx.VERTICAL);
sz.Add(wx.StaticText(self.app, -1, "wxAnimationCtrl:"));
self.m_animationCtrl = wx.animate.AnimationCtrl(self.app, wx.ID_ANY)
if (self.m_animationCtrl.LoadFile("throbber.gif")):
self.m_animationCtrl.Play()
sz.Add(self.m_animationCtrl);
self.app.SetSizer(sz);
self.Layout()
def OnPlay(self, event):
if (not self.m_animationCtrl.Play()):
wx.LogError("Invalid animation")
def OnSetNullAnimation(self, event):
self.m_animationCtrl.SetAnimation(wx.animate.NullAnimation);
def OnSetNoAutoResize(self, event):
#// recreate the control with the new flag if necessary
rs = (event.IsChecked() and [wx.animate.AC_NO_AUTORESIZE] or [0] )[0]
style = wx.animate.AC_DEFAULT_STYLE | rs
if (style != self.m_animationCtrl.GetWindowStyle()):
#// save status of the control before destroying it
curr = self.m_animationCtrl.GetAnimation();
inactive = self.m_animationCtrl.GetInactiveBitmap();
bg = self.m_animationCtrl.GetBackgroundColour();
#// destroy & rebuild
old = self.m_animationCtrl;
self.m_animationCtrl = wx.animate.AnimationCtrl(self, wx.ID_ANY, curr, wx.DefaultPosition, wx.DefaultSize, style);
self.app.GetSizer().Replace(old, self.m_animationCtrl);
del(old)
#// load old status in new control
self.m_animationCtrl.SetInactiveBitmap(inactive);
self.m_animationCtrl.SetBackgroundColour(bg);
self.app.GetSizer().Layout();
def OnSetBgColor(self, event):
clr = wx.GetColourFromUser(self, self.m_animationCtrl.GetBackgroundColour(), "Choose the background colour")
print clr.IsOk()
if (clr.IsOk()):
self.m_animationCtrl.SetBackgroundColour(clr)
def OnStop(self, event):
self.m_animationCtrl.Stop();
def OnAbout(self, event):
msg = "This is the About dialog of the AccessTest sample.\n Welcome to %s" % wx.VERSION_STRING
wx.MessageBox(msg, "About AccessTest", wx.OK | wx.ICON_INFORMATION, self)
def OnQuit(self, event):
self.Close()
def OnOpen(self, event):
dialog = wx.FileDialog(self, "Please choose an animation", wx.EmptyString, wx.EmptyString, "*.gif;*.ani", wx.FD_OPEN);
filename = ""
if (dialog.ShowModal() == wx.ID_OK):
filename = dialog.GetPath()
#// enable one of the two chunk of codes to test different parts of wxAnimation/wxAnimationCtrl
if (self.m_animationCtrl.LoadFile(filename)):
self.m_animationCtrl.Play()
else:
wx.MessageBox("Sorry, this animation is not a valid format for wxAnimation.")
def OnSize(self, event):
pass
def OnUpdateUI(self, event):
#fp = open("event.log", "w")
#for x in dir(self.GetMenuBar()):
# print x
# fp.write(x +"\n")
#fp.close()
#exit()
#C++ FindItem = python FindItemById
self.GetMenuBar().FindItemById(wx.ID_STOP).Enable(self.m_animationCtrl.IsPlaying())
self.GetMenuBar().FindItemById(ID_PLAY).Enable(not self.m_animationCtrl.IsPlaying())
self.GetMenuBar().FindItemById(ID_SET_NO_AUTO_RESIZE).Enable(not self.m_animationCtrl.IsPlaying())
#######################################################
|
|
|