From 6bbcd84574dfe7c96d954dde2960d0140ba12d8c Mon Sep 17 00:00:00 2001 From: HomeWorld Date: Sun, 16 Jan 2011 14:49:43 +0200 Subject: [PATCH] Changed fit backup busy animation --- gui/mainFrame.py | 20 ++--------- gui/utils/animUtils.py | 76 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 17 deletions(-) create mode 100644 gui/utils/animUtils.py diff --git a/gui/mainFrame.py b/gui/mainFrame.py index d22b2ed06..df6b751e4 100644 --- a/gui/mainFrame.py +++ b/gui/mainFrame.py @@ -451,8 +451,6 @@ class MainFrame(wx.Frame): saveDialog.Destroy() def closeWaitDialog(self): - if self.waitDialog.timer.IsRunning(): - self.waitDialog.timer.Stop() self.waitDialog.Destroy() def openGraphFrame(self, event): @@ -477,31 +475,19 @@ class MainFrame(wx.Frame): if not wnd: wnd = self InspectionTool().Show(wnd, True) - +import utils.animUtils as animUtils class WaitDialog(wx.Dialog): def __init__(self, parent): - wx.Dialog.__init__ (self, parent, id=wx.ID_ANY, title=u"Please wait ...", size=(200,30), + wx.Dialog.__init__ (self, parent, id=wx.ID_ANY, title=u"Please wait ...", size=(300,30), style=wx.NO_BORDER) mainSizer = wx.BoxSizer( wx.HORIZONTAL ) - self.progress = wx.Gauge( self, wx.ID_ANY, 100, wx.DefaultPosition, wx.DefaultSize, wx.GA_HORIZONTAL | wx.GA_SMOOTH ) + self.progress = animUtils.LoadAnimation(self,label = "Processing", size=(300,30)) mainSizer.Add( self.progress, 1, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 0 ) - self.progress.SetRange(20) - self.progress.SetValue(0) - self.cycle = 0 self.SetSizer( mainSizer ) self.Layout() - self.timer = wx.Timer(self,wx.ID_ANY) - self.timer.Start(100) self.Bind(wx.EVT_CLOSE,self.OnClose) - self.Bind(wx.EVT_TIMER,self.OnTimer) self.CenterOnParent() - def OnTimer(self, event): - self.cycle += 1 - if self.cycle > self.progress.GetRange(): - self.cycle = 0 - self.progress.SetValue(self.cycle) - def OnClose(self, event): pass diff --git a/gui/utils/animUtils.py b/gui/utils/animUtils.py new file mode 100644 index 000000000..a8e5265d7 --- /dev/null +++ b/gui/utils/animUtils.py @@ -0,0 +1,76 @@ +import wx +import gui.utils.colorUtils as colorUtils + +class LoadAnimation(wx.Window): + def __init__ (self, parent, id = wx.ID_ANY, label = "", pos = wx.DefaultPosition, size = wx.DefaultSize, style = 0): + wx.Window.__init__(self, parent, id, pos = pos, size = size, style = style) + + self.label = label + + self.animTimerId = wx.NewId() + self.animTimer = wx.Timer(self, self.animTimerId) + self.animTimerPeriod = 50 + + self.animCount = 0 + self.animDir = 1 + self.bars = 10 + self.padding = 2 + + + self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground) + self.Bind(wx.EVT_TIMER, self.OnTimer) + self.Bind(wx.EVT_PAINT, self.OnPaint) + + self.animTimer.Start(self.animTimerPeriod) + + def OnTimer(self, event): + self.animCount += self.animDir + + if self.animCount >= self.bars: + self.animCount = self.bars - 1 + self.animDir = -1 + + if self.animCount < 0: + self.animCount = 0 + self.animDir = 1 + + self.Refresh() + + def OnEraseBackground(self, event): + pass + + def OnPaint(self, event): + rect = self.GetClientRect() + dc = wx.BufferedPaintDC(self) + windowColor = wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW) + dc.SetBackground(wx.Brush(windowColor)) + dc.Clear() + + barColor = wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOWTEXT) + shadeColor = colorUtils.GetSuitableColor(barColor, 0.75) + + barWidth = (rect.width) / self.bars + barHeight = rect.height - self.padding * 2 + + x = self.padding + + for bar in xrange(self.bars): + if bar != self.animCount: + dc.SetPen(wx.Pen(shadeColor)) + dc.SetBrush(wx.Brush(shadeColor)) + bh = barHeight + y = self.padding + else: + barColor = colorUtils.GetSuitableColor(barColor,float(self.animCount/2)/10) + dc.SetPen(wx.Pen(barColor)) + dc.SetBrush(wx.Brush(barColor)) + bh = rect.height + y = 0 + + dc.DrawRectangle(x, y, barWidth, bh) + x += barWidth + + textColor = wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOWTEXT) + dc.SetTextForeground(textColor) + dc.DrawLabel(self.label,rect,wx.ALIGN_CENTER) +