| 4 | |
| 5 | |
| 6 | class LoadAnimation(wx.Window): |
| 7 | def __init__(self, parent, id=wx.ID_ANY, label="", pos=wx.DefaultPosition, size=wx.DefaultSize, style=0): |
| 8 | wx.Window.__init__(self, parent, id, pos=pos, size=size, style=style) |
| 9 | |
| 10 | self.label = label |
| 11 | |
| 12 | self.animTimerId = wx.NewId() |
| 13 | self.animTimer = wx.Timer(self, self.animTimerId) |
| 14 | self.animTimerPeriod = 50 |
| 15 | |
| 16 | self.animCount = 0 |
| 17 | self.animDir = 1 |
| 18 | self.bars = 10 |
| 19 | self.padding = 2 |
| 20 | |
| 21 | self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground) |
| 22 | self.Bind(wx.EVT_TIMER, self.OnTimer) |
| 23 | self.Bind(wx.EVT_PAINT, self.OnPaint) |
| 24 | |
| 25 | self.animTimer.Start(self.animTimerPeriod) |
| 26 | |
| 27 | self.SetBackgroundStyle(wx.BG_STYLE_PAINT) |
| 28 | |
| 29 | def Play(self): |
| 30 | if self.animTimer.IsRunning(): |
| 31 | self.animTimer.Stop() |
| 32 | self.animCount = 0 |
| 33 | self.animTimer.Start(self.animTimerPeriod) |
| 34 | |
| 35 | def Stop(self): |
| 36 | if self.animTimer.IsRunning(): |
| 37 | self.animTimer.Stop() |
| 38 | |
| 39 | def OnTimer(self, event): |
| 40 | self.animCount += self.animDir |
| 41 | |
| 42 | if self.animCount >= self.bars: |
| 43 | self.animCount = self.bars - 1 |
| 44 | self.animDir = -1 |
| 45 | |
| 46 | if self.animCount < 0: |
| 47 | self.animCount = 0 |
| 48 | self.animDir = 1 |
| 49 | |
| 50 | self.Refresh() |
| 51 | |
| 52 | def OnEraseBackground(self, event): |
| 53 | pass |
| 54 | |
| 55 | def OnPaint(self, event): |
| 56 | rect = self.GetClientRect() |
| 57 | dc = wx.AutoBufferedPaintDC(self) |
| 58 | windowColor = wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOW) |
| 59 | dc.SetBackground(wx.Brush(windowColor)) |
| 60 | dc.Clear() |
| 61 | |
| 62 | barColor = wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOWTEXT) |
| 63 | shadeColor = colorUtils.GetSuitable(barColor, 0.75) |