[dd66fbd] | 1 | import wx |
---|
| 2 | class MyStatusBar(wx.StatusBar): |
---|
| 3 | def __init__(self,*args,**kargs): |
---|
| 4 | wx.StatusBar.__init__(self, *args,**kargs) |
---|
| 5 | #Layout of status bar |
---|
| 6 | self.SetFieldsCount(3) |
---|
| 7 | width,height = self.GetSize() |
---|
| 8 | self.gauge = wx.Gauge(self, size=(-1,height-4),style= wx.GA_PROGRESSBAR) |
---|
| 9 | rect = self.GetFieldRect(1) |
---|
| 10 | self.gauge.SetPosition((rect.x+ 10, rect.y-2)) |
---|
| 11 | self.gauge.Hide() |
---|
| 12 | #Progess |
---|
| 13 | |
---|
| 14 | self.progress = 0 # Current progress value of the bar |
---|
| 15 | self.timer = wx.Timer(self,-1) |
---|
| 16 | self.thread= None |
---|
[ef628a1] | 17 | self.Bind(wx.EVT_TIMER,self.OnTimer, self.timer) |
---|
[dd66fbd] | 18 | |
---|
| 19 | def OnTimer(self, evt): |
---|
| 20 | """Update the progress bar while the timer is running |
---|
| 21 | @param evt: wx.EVT_TIMER |
---|
| 22 | |
---|
| 23 | """ |
---|
| 24 | # Check stop flag that can be set from non main thread |
---|
[ef628a1] | 25 | self.gauge.Pulse() |
---|
[dd66fbd] | 26 | |
---|
| 27 | def set_progress(self): |
---|
| 28 | self.gauge.Show(True) |
---|
| 29 | if self.timer.IsRunning(): |
---|
| 30 | while(self.thread.isrunning()): |
---|
| 31 | self.progress += 1 |
---|
| 32 | |
---|
| 33 | # Update the Rqnge if it has changed |
---|
| 34 | #if self.range >= 0 and self.range != self.gauge.GetRange(): |
---|
| 35 | # self.gauge.SetRange(self.range) |
---|
| 36 | |
---|
| 37 | # Update the progress value if it is less than the range |
---|
| 38 | if self.progress < self.gauge.GetRange()-20: |
---|
| 39 | self.gauge.SetValue(int(self.progress)) |
---|
| 40 | else: |
---|
| 41 | self.gauge.SetValue(70) |
---|
| 42 | self.progress =0 |
---|
| 43 | self.timer.Stop() |
---|
| 44 | #self.gauge.Hide() |
---|
| 45 | self.timer.Stop() |
---|
| 46 | self.gauge.SetValue(90) |
---|
| 47 | self.progress =0 |
---|
| 48 | |
---|
| 49 | def clear_gauge(self, msg=""): |
---|
| 50 | self.timer.Stop() |
---|
| 51 | self.SetStatusText( str(msg), 0) |
---|
| 52 | self.progress =0 |
---|
| 53 | self.gauge.SetValue(0) |
---|
| 54 | self.gauge.Hide() |
---|
| 55 | |
---|
| 56 | def set_status(self, type=None,msg="", thread=None): |
---|
| 57 | if type==None: |
---|
| 58 | self.SetStatusText(str(msg),0) |
---|
| 59 | |
---|
| 60 | else: |
---|
| 61 | self.thread= thread |
---|
| 62 | if self.thread !=None: |
---|
| 63 | self.gauge.Show(True) |
---|
| 64 | if type.lower()=="start": |
---|
[ef628a1] | 65 | self.timer.Stop() |
---|
[dd66fbd] | 66 | self.SetStatusText( str(msg), 0) |
---|
[ef628a1] | 67 | self.progress +=10 |
---|
| 68 | self.gauge.SetValue(int(self.progress)) |
---|
[dd66fbd] | 69 | #self.timer.Start(1000) |
---|
| 70 | #print "went here" |
---|
| 71 | #self.set_progress() |
---|
| 72 | self.progress +=10 |
---|
| 73 | if self.progress < self.gauge.GetRange()-20: |
---|
| 74 | self.gauge.SetValue(int(self.progress)) |
---|
[ef628a1] | 75 | if type.lower()=="progress": |
---|
| 76 | self.timer.Start(100) |
---|
| 77 | self.SetStatusText( str(msg), 0) |
---|
| 78 | self.gauge.Pulse() |
---|
| 79 | print "in progress" |
---|
| 80 | |
---|
[dd66fbd] | 81 | if type.lower()=="update": |
---|
| 82 | |
---|
| 83 | self.timer.Stop() |
---|
| 84 | self.SetStatusText( str(msg), 0) |
---|
| 85 | self.progress +=10 |
---|
| 86 | if self.progress < self.gauge.GetRange()-20: |
---|
| 87 | self.gauge.SetValue(int(self.progress)) |
---|
| 88 | if type.lower()=="stop": |
---|
| 89 | print "it is complete" |
---|
| 90 | self.gauge.Show(True) |
---|
| 91 | self.timer.Stop() |
---|
| 92 | self.SetStatusText( str(msg), 0) |
---|
| 93 | self.progress =0 |
---|
| 94 | self.gauge.SetValue(90) |
---|
| 95 | |
---|
| 96 | |
---|
| 97 | |
---|
| 98 | |
---|
| 99 | if __name__ == "__main__": |
---|
| 100 | app = wx.PySimpleApp() |
---|
| 101 | frame= wx.Frame(None,wx.ID_ANY,'test frame') |
---|
| 102 | statusBar= MyStatusBar(frame,wx.ID_ANY) |
---|
| 103 | frame.SetStatusBar(statusBar) |
---|
| 104 | frame.Show(True) |
---|
| 105 | statusBar.SetStatusText("status text..") |
---|
| 106 | statusBar.set_status( "progress","progessing") |
---|
| 107 | |
---|
| 108 | |
---|
| 109 | app.MainLoop() |
---|
| 110 | |
---|