Changeset db10f97 in sasview
- Timestamp:
- Apr 12, 2010 9:03:12 AM (15 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- f304194
- Parents:
- b7f29fc
- Location:
- guiframe
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
guiframe/gui_manager.py
rba535a6 rdb10f97 23 23 import os, sys 24 24 import xml 25 25 26 try: 26 27 # Try to find a local config … … 45 46 46 47 import logging 47 48 49 48 50 49 def quit_guiframe(parent=None): … … 279 278 """ 280 279 # Status bar 281 from statusbar import MyStatusBar282 self.sb = MyStatusBar(self,wx.ID_ANY)280 from statusbar import StatusBar 281 self.sb = StatusBar(self, wx.ID_ANY) 283 282 self.SetStatusBar(self.sb) 284 283 … … 291 290 292 291 self._mgr.Update() 292 293 def SetStatusText(self, *args, **kwds): 294 number = self.sb.get_msg_position() 295 wx.Frame.SetStatusText(number=number, *args, **kwds) 296 297 def PopStatusText(self, *args, **kwds): 298 field = self.sb.get_msg_position() 299 wx.Frame.PopStatusText(field=field) 300 301 def PushStatusText(self, *args, **kwds): 302 field = self.sb.get_msg_position() 303 wx.Frame.PushStatusText(self, field=field,string=string) 293 304 294 305 def add_perspective(self, plugin): … … 613 624 Display status message 614 625 """ 615 #self.sb.clear_gauge( msg="") 616 mythread=None 617 mytype= None 618 if hasattr(evt, "curr_thread"): 619 mythread= evt.curr_thread 620 if hasattr(evt, "type"): 621 mytype= evt.type 622 self.sb.set_status( type=mytype,msg=str(evt.status),thread=mythread) 626 self.sb.set_status(event=evt) 623 627 624 625 626 628 def _on_view(self, evt): 627 629 """ -
guiframe/statusbar.py
rb3c0c00 rdb10f97 1 1 import wx 2 class MyStatusBar(wx.StatusBar): 3 def __init__(self,*args,**kargs): 4 wx.StatusBar.__init__(self, *args,**kargs) 2 from wx import StatusBar as wxStatusB 3 import wx.lib 4 from wx.lib import newevent 5 #numner of fields of the status bar 6 NB_FIELDS = 3 7 #position of the status bar's fields 8 ICON_POSITION = 0 9 MSG_POSITION = 1 10 GAUGE_POSITION = 2 11 BUTTON_SIZE = 40 12 class StatusBar(wxStatusB): 13 def __init__(self, parent, *args, **kargs): 14 wxStatusB.__init__(self, parent, *args, **kargs) 5 15 """ 6 16 Implement statusbar functionalities 7 17 """ 18 self.parent= parent 19 self.parent.SetStatusBarPane(MSG_POSITION) 20 8 21 #Layout of status bar 9 self.SetFieldsCount(2) 10 width,height = self.GetSize() 11 self.gauge = wx.Gauge(self, size=(width/10,height-3),style= wx.GA_HORIZONTAL) 12 self.SetStatusWidths([-4, -1]) 13 rect = self.GetFieldRect(1) 22 self.SetFieldsCount(NB_FIELDS) 23 self.SetStatusWidths([BUTTON_SIZE, -2, -1]) 24 25 #display default message 26 self.msg_position = MSG_POSITION 27 self.SetStatusText(text="No Message available...") 28 29 #save the position of the gauge 30 width, height = self.GetSize() 31 self.gauge = wx.Gauge(self, size=(width/10,height-3), 32 style= wx.GA_HORIZONTAL) 33 rect = self.GetFieldRect(GAUGE_POSITION) 14 34 self.gauge.SetPosition((rect.x+5, rect.y-2)) 35 self.gauge.Hide() 15 36 16 self.gauge.Hide() 37 #status bar icon 38 icon_bmp = wx.ArtProvider.GetBitmap(wx.ART_INFORMATION, wx.ART_TOOLBAR) 39 self.bitmap_bt_warning = wx.BitmapButton(self, -1, size=(BUTTON_SIZE,-1), 40 style=wx.NO_BORDER) 41 self.bitmap_bt_warning.SetBitmapLabel(icon_bmp) 42 rect = self.GetFieldRect(ICON_POSITION) 43 self.bitmap_bt_warning.SetPosition((rect.x+5, rect.y-2)) 44 17 45 ## Current progress value of the bar 18 46 self.progress = 0 19 self.timer = wx.Timer(self, -1)20 self.timer_stop = wx.Timer(self, -1)21 self.thread = None47 self.timer = wx.Timer(self, -1) 48 self.timer_stop = wx.Timer(self, -1) 49 self.thread = None 22 50 self.Bind(wx.EVT_TIMER,self.OnTimer, self.timer) 23 51 self.Bind(wx.EVT_TIMER,self.OnTimer_stop, self.timer_stop) 24 self.count=025 52 26 53 def get_msg_position(self): 54 """ 55 """ 56 return self.msg_position 57 58 def SetStatusText(self, text="", number=MSG_POSITION): 59 """ 60 """ 61 wxStatusB.SetStatusText(self, text, MSG_POSITION) 62 63 def PopStatusText(self, *args, **kwds): 64 wxStatusB.PopStatusText(self, field=MSG_POSITION) 65 66 def PushStatusText(self, *args, **kwds): 67 wxStatusB.PushStatusText(self, field=MSG_POSITION,string=string) 68 27 69 def OnTimer_stop(self, evt): 28 70 """Clear the progress bar … … 30 72 31 73 """ 32 self.count +=1 33 if self.count <=10: 34 self.timer_stop.Stop() 35 self.gauge.Hide() 36 #self.SetStatusText( "", 0) 37 self.count=0 38 39 74 count = 0 75 if count <= 10: 76 count += 1 77 self.timer_stop.Stop() 78 self.gauge.Hide() 79 #self.SetStatusText( "", GAUGE_POSITION) 80 40 81 def OnTimer(self, evt): 41 82 """Update the progress bar while the timer is running … … 46 87 if self.timer.IsRunning(): 47 88 self.gauge.Pulse() 48 49 50 def set_progress(self): 51 """ 52 Set the gauge value given the status of a thread 53 """ 89 """ 90 def set_progress(self): 91 #Set the gauge value given the status of a thread 54 92 self.gauge.Show(True) 55 93 if self.timer.IsRunning(): … … 61 99 else: 62 100 self.gauge.SetValue(70) 63 self.progress = 0101 self.progress = 0 64 102 self.timer.Stop() 65 66 103 self.timer.Stop() 67 104 self.gauge.SetValue(90) 68 105 self.progress =0 69 70 106 """ 71 107 def clear_gauge(self, msg=""): 72 108 """ 73 109 Hide the gauge 74 110 """ 75 self.timer.Stop() 76 self.SetStatusText( str(msg), 0) 77 self.progress =0 111 self.SetStatusText(str(msg), MSG_POSITION) 112 self.progress = 0 78 113 self.gauge.SetValue(0) 79 114 self.gauge.Hide() 80 115 81 def set_status(self, type=None,msg="", thread=None): 116 def set_icon(self, event): 117 """ 118 display icons related to the type of message sent to the statusbar 119 when available 120 """ 121 if not hasattr(event, "info"): 122 return 123 msg = event.info.lower() 124 if msg == "warning": 125 icon_bmp = wx.ArtProvider.GetBitmap(wx.ART_WARNING, wx.ART_TOOLBAR) 126 self.bitmap_bt_warning.SetBitmapLabel(icon_bmp) 127 if msg == "error": 128 icon_bmp = wx.ArtProvider.GetBitmap(wx.ART_ERROR, wx.ART_TOOLBAR) 129 self.bitmap_bt_warning.SetBitmapLabel(icon_bmp) 130 if msg == "info": 131 icon_bmp = wx.ArtProvider.GetBitmap(wx.ART_INFORMATION, wx.ART_TOOLBAR) 132 self.bitmap_bt_warning.SetBitmapLabel(icon_bmp) 133 134 def set_message(self, event): 135 """ 136 display received message on the statusbar 137 """ 138 if hasattr(event, "status"): 139 self.SetStatusText(str(event.status)) 140 141 def set_gauge(self, event): 142 """ 143 change the state of the gauge according the state of the current job 144 """ 145 if not hasattr(event, "type"): 146 return 147 type = event.type 148 self.gauge.Show(True) 149 if type.lower()=="start": 150 self.timer.Stop() 151 self.progress += 10 152 self.gauge.SetValue(int(self.progress)) 153 self.progress += 10 154 if self.progress < self.gauge.GetRange()-20: 155 self.gauge.SetValue(int(self.progress)) 156 if type.lower()=="progress": 157 self.timer.Start(100) 158 self.gauge.Pulse() 159 if type.lower()=="update": 160 self.timer.Stop() 161 self.progress += 10 162 if self.progress < self.gauge.GetRange()-20: 163 self.gauge.SetValue(int(self.progress)) 164 if type.lower()=="stop": 165 self.gauge.Show(True) 166 self.timer.Stop() 167 self.progress = 0 168 self.gauge.SetValue(90) 169 self.timer_stop.Start(3) 170 171 def set_status(self, event): 82 172 """ 83 173 Update the status bar . … … 87 177 @param thread: if updatting using a thread status 88 178 """ 89 if type==None: 90 self.SetStatusText(str(msg),0) 179 self.set_icon(event=event) 180 self.set_message(event=event) 181 self.set_gauge(event=event) 91 182 92 else:93 self.SetStatusText(str(msg),0)94 self.thread= thread95 self.gauge.Show(True)96 if type.lower()=="start":97 self.timer.Stop()98 self.SetStatusText( str(msg), 0)99 self.progress +=10100 self.gauge.SetValue(int(self.progress))101 102 self.progress +=10103 if self.progress < self.gauge.GetRange()-20:104 self.gauge.SetValue(int(self.progress))105 106 if type.lower()=="progress":107 self.timer.Start(100)108 self.SetStatusText( str(msg), 0)109 self.gauge.Pulse()110 111 if type.lower()=="update":112 113 self.timer.Stop()114 self.SetStatusText( str(msg), 0)115 self.progress +=10116 if self.progress < self.gauge.GetRange()-20:117 self.gauge.SetValue(int(self.progress))118 119 if type.lower()=="stop":120 self.gauge.Show(True)121 self.timer.Stop()122 self.SetStatusText( str(msg), 0)123 self.progress =0124 self.gauge.SetValue(90)125 self.timer_stop.Start(3)126 127 128 129 183 if __name__ == "__main__": 130 184 app = wx.PySimpleApp() 131 185 frame= wx.Frame(None,wx.ID_ANY,'test frame') 132 statusBar = MyStatusBar(frame,wx.ID_ANY)186 statusBar = StatusBar(frame, wx.ID_ANY) 133 187 frame.SetStatusBar(statusBar) 134 188 frame.Show(True) 135 statusBar.SetStatusText("status text..") 136 statusBar.set_status( "progress","progessing") 137 138 189 (NewPlotEvent, EVT_NEW_PLOT) = wx.lib.newevent.NewEvent() 190 event = NewPlotEvent() 191 event.type = "progress" 192 event.status = "statusbar...." 193 event.info = "info" 194 statusBar.set_status(event=event) 139 195 app.MainLoop() 140 196
Note: See TracChangeset
for help on using the changeset viewer.