source: sasview/guiframe/statusbar.py @ 353041d

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 353041d was 858f2ae5, checked in by Gervaise Alina <gervyh@…>, 16 years ago

improve status bar

  • Property mode set to 100644
File size: 4.4 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 ==20:
32            self.timer_stop.Stop() 
33            self.gauge.Hide()
34            self.count=0
35    def OnTimer(self, evt): 
36        """Update the progress bar while the timer is running
37        @param evt: wx.EVT_TIMER
38 
39        """ 
40        # Check stop flag that can be set from non main thread
41        if self.timer.IsRunning(): 
42            self.gauge.Pulse()
43       
44       
45    def set_progress(self):
46        self.gauge.Show(True)
47        if self.timer.IsRunning(): 
48            while(self.thread.isrunning()):
49                self.progress += 1
50               
51                # Update the Rqnge if it has changed
52                #if self.range >= 0 and self.range != self.gauge.GetRange():
53                #    self.gauge.SetRange(self.range)
54     
55                # Update the progress value if it is less than the range
56                if self.progress < self.gauge.GetRange()-20: 
57                    self.gauge.SetValue(int(self.progress)) 
58                else:
59                    self.gauge.SetValue(70) 
60                    self.progress =0
61                    self.timer.Stop()
62                    #self.gauge.Hide()
63            self.timer.Stop()
64            self.gauge.SetValue(90) 
65            self.progress =0
66           
67    def clear_gauge(self, msg=""):
68        self.timer.Stop()
69        self.SetStatusText( str(msg), 0)
70        self.progress =0
71        self.gauge.SetValue(0)
72        self.gauge.Hide() 
73         
74    def set_status(self, type=None,msg="", thread=None):
75        if type==None:
76            self.SetStatusText(str(msg),0)
77       
78        else:
79            self.thread= thread
80            #if self.thread !=None:
81            self.gauge.Show(True)
82            if type.lower()=="start":
83                self.timer.Stop()
84                self.SetStatusText( str(msg), 0)
85                self.progress +=10
86                self.gauge.SetValue(int(self.progress)) 
87                #self.timer.Start(1000)
88                #print "went here"
89                #self.set_progress()
90                self.progress +=10
91                if self.progress < self.gauge.GetRange()-20:
92                    self.gauge.SetValue(int(self.progress)) 
93            if type.lower()=="progress":
94                self.timer.Start(100)
95                self.SetStatusText( str(msg), 0)
96                self.gauge.Pulse()
97                print "in progress"
98               
99            if  type.lower()=="update":
100               
101                self.timer.Stop()
102                self.SetStatusText( str(msg), 0)
103                self.progress +=10
104                if self.progress < self.gauge.GetRange()-20:
105                    self.gauge.SetValue(int(self.progress)) 
106            if type.lower()=="stop":
107                print "it is complete"
108                self.gauge.Show(True)
109                self.timer.Stop()
110                self.SetStatusText( str(msg), 0)
111                self.progress =0
112                self.gauge.SetValue(90) 
113                self.timer_stop.Start(3)   
114           
115   
116   
117if __name__ == "__main__":
118     app = wx.PySimpleApp()
119     frame= wx.Frame(None,wx.ID_ANY,'test frame')
120     statusBar= MyStatusBar(frame,wx.ID_ANY)
121     frame.SetStatusBar(statusBar)
122     frame.Show(True)
123     statusBar.SetStatusText("status text..")
124     statusBar.set_status( "progress","progessing")
125     
126     
127     app.MainLoop()
128
Note: See TracBrowser for help on using the repository browser.