source: sasview/guiframe/statusbar.py @ 6c0568b

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 6c0568b was acd91458, checked in by Jae Cho <jhjcho@…>, 15 years ago

shorter time status bar

  • Property mode set to 100644
File size: 4.2 KB
Line 
1import wx
2class MyStatusBar(wx.StatusBar):
3    def __init__(self,*args,**kargs):
4         wx.StatusBar.__init__(self, *args,**kargs)
5         #Layout of status bar
6         self.SetFieldsCount(2) 
7         width,height = self.GetSize()
8         self.gauge = wx.Gauge(self, size=(-1,height-4),style= wx.GA_HORIZONTAL)
9         self.SetStatusWidths([-4, -1])
10         rect = self.GetFieldRect(1)
11         self.gauge.SetPosition((rect.x+5, rect.y-2))
12         
13         self.gauge.Hide()
14         
15         #Progess
16
17         self.progress = 0       # Current progress value of the bar
18         self.timer = wx.Timer(self,-1) 
19         self.timer_stop = wx.Timer(self,-1) 
20         self.thread= None
21         self.Bind(wx.EVT_TIMER,self.OnTimer, self.timer) 
22         self.Bind(wx.EVT_TIMER,self.OnTimer_stop, self.timer_stop) 
23         self.count=0
24         
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
31        if self.count ==45:
32            self.timer_stop.Stop() 
33            self.gauge.Hide()
34            self.SetStatusText( "", 0)
35            self.count=0
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
42        if self.timer.IsRunning(): 
43            self.gauge.Pulse()
44       
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
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()
92                #print "in progress"
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:
100                    self.gauge.SetValue(int(self.progress)) 
101                   
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) 
108                self.timer_stop.Start(3)   
109           
110   
111   
112if __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
Note: See TracBrowser for help on using the repository browser.