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