source: sasview/guiframe/statusbar.py @ 910792f

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 910792f was 12aa9b5, checked in by Gervaise Alina <gervyh@…>, 15 years ago

class and method commented

  • Property mode set to 100644
File size: 4.6 KB
Line 
1import wx
2class MyStatusBar(wx.StatusBar):
3    def __init__(self,*args,**kargs):
4         wx.StatusBar.__init__(self, *args,**kargs)
5         """
6             Implement statusbar functionalities
7         """
8         #Layout of status bar
9         self.SetFieldsCount(2) 
10         width,height = self.GetSize()
11         self.gauge = wx.Gauge(self, size=(-1,height-4),style= wx.GA_HORIZONTAL)
12         self.SetStatusWidths([-4, -1])
13         rect = self.GetFieldRect(1)
14         self.gauge.SetPosition((rect.x+5, rect.y-2))
15         
16         self.gauge.Hide()
17         ## Current progress value of the bar
18         self.progress = 0     
19         self.timer = wx.Timer(self,-1) 
20         self.timer_stop = wx.Timer(self,-1) 
21         self.thread= None
22         self.Bind(wx.EVT_TIMER,self.OnTimer, self.timer) 
23         self.Bind(wx.EVT_TIMER,self.OnTimer_stop, self.timer_stop) 
24         self.count=0
25       
26         
27    def OnTimer_stop(self, evt): 
28        """Clear the progress bar
29        @param evt: wx.EVT_TIMER
30 
31        """ 
32        self.count +=1
33        if self.count ==45:
34            self.timer_stop.Stop() 
35            self.gauge.Hide()
36            self.SetStatusText( "", 0)
37            self.count=0
38           
39           
40    def OnTimer(self, evt): 
41        """Update the progress bar while the timer is running
42        @param evt: wx.EVT_TIMER
43 
44        """ 
45        # Check stop flag that can be set from non main thread
46        if self.timer.IsRunning(): 
47            self.gauge.Pulse()
48       
49       
50    def set_progress(self):
51        """   
52            Set the gauge value given the status of a thread
53        """
54        self.gauge.Show(True)
55        if self.timer.IsRunning(): 
56            while(self.thread.isrunning()):
57                self.progress += 1
58                # Update the progress value if it is less than the range
59                if self.progress < self.gauge.GetRange()-20: 
60                    self.gauge.SetValue(int(self.progress)) 
61                else:
62                    self.gauge.SetValue(70) 
63                    self.progress =0
64                    self.timer.Stop()
65                   
66            self.timer.Stop()
67            self.gauge.SetValue(90) 
68            self.progress =0
69           
70           
71    def clear_gauge(self, msg=""):
72        """
73            Hide the gauge
74        """
75        self.timer.Stop()
76        self.SetStatusText( str(msg), 0)
77        self.progress =0
78        self.gauge.SetValue(0)
79        self.gauge.Hide() 
80         
81    def set_status(self, type=None,msg="", thread=None):
82        """
83            Update the status bar .
84            @param type: type of message send.
85            type  must be in ["start","progress","update","stop"]
86            @param msg: the message itself  as string
87            @param thread: if updatting using a thread status
88        """
89        if type==None:
90            self.SetStatusText(str(msg),0)
91       
92        else:
93            self.thread= thread
94            self.gauge.Show(True)
95            if type.lower()=="start":
96                self.timer.Stop()
97                self.SetStatusText( str(msg), 0)
98                self.progress +=10
99                self.gauge.SetValue(int(self.progress)) 
100             
101                self.progress +=10
102                if self.progress < self.gauge.GetRange()-20:
103                    self.gauge.SetValue(int(self.progress)) 
104                   
105            if type.lower()=="progress":
106                self.timer.Start(100)
107                self.SetStatusText( str(msg), 0)
108                self.gauge.Pulse()
109               
110            if  type.lower()=="update":
111               
112                self.timer.Stop()
113                self.SetStatusText( str(msg), 0)
114                self.progress +=10
115                if self.progress < self.gauge.GetRange()-20:
116                    self.gauge.SetValue(int(self.progress)) 
117                   
118            if type.lower()=="stop":
119                self.gauge.Show(True)
120                self.timer.Stop()
121                self.SetStatusText( str(msg), 0)
122                self.progress =0
123                self.gauge.SetValue(90) 
124                self.timer_stop.Start(3)   
125           
126   
127   
128if __name__ == "__main__":
129     app = wx.PySimpleApp()
130     frame= wx.Frame(None,wx.ID_ANY,'test frame')
131     statusBar= MyStatusBar(frame,wx.ID_ANY)
132     frame.SetStatusBar(statusBar)
133     frame.Show(True)
134     statusBar.SetStatusText("status text..")
135     statusBar.set_status( "progress","progessing")
136     
137     
138     app.MainLoop()
139
Note: See TracBrowser for help on using the repository browser.