Changeset 32c0841 in sasview for guiframe/statusbar.py
- Timestamp:
- Nov 23, 2010 11:21:20 AM (13 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:
- a54e4be
- Parents:
- 4a2b054
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
guiframe/statusbar.py
rd955bf19 r32c0841 2 2 from wx import StatusBar as wxStatusB 3 3 import wx.lib 4 from wx.lib import newevent4 #from wx.lib import newevent 5 5 (MessageEvent, EVT_MESSAGE) = wx.lib.newevent.NewEvent() 6 6 #numner of fields of the status bar … … 20 20 """ 21 21 def __init__(self, parent, *args, **kwargs): 22 wx.Panel.__init__(self, parent=parent,*args, **kwargs) 22 """ 23 """ 24 wx.Panel.__init__(self, parent=parent, *args, **kwargs) 23 25 self.parent = parent 24 26 self.sizer = wx.BoxSizer(wx.VERTICAL) … … 31 33 self.SetSizer(self.sizer) 32 34 33 def set_message(self, status=""): 34 msg = status+ "\n" 35 def set_message(self, status=""): 36 """ 37 """ 38 msg = status + "\n" 35 39 self.msg_txt.AppendText(str(msg)) 36 40 … … 63 67 """ 64 68 def __init__(self, parent, *args, **kargs): 65 66 69 wxStatusB.__init__(self, parent, *args, **kargs) 70 """ 67 71 Implement statusbar functionalities 68 """ 69 self.parent= parent 70 self.parent.SetStatusBarPane(MSG_POSITION) 71 72 #Layout of status bar 73 self.SetFieldsCount(NB_FIELDS) 74 self.SetStatusWidths([BUTTON_SIZE, -2, -1,BUTTON_SIZE]) 75 76 #display default message 77 self.msg_position = MSG_POSITION 78 79 #save the position of the gauge 80 width, height = self.GetSize() 81 self.gauge = wx.Gauge(self, size=(width/10,height-3), 82 style= wx.GA_HORIZONTAL) 83 84 self.gauge.Hide() 85 86 #status bar icon 87 self.bitmap_bt_warning = wx.BitmapButton(self, -1, size=(BUTTON_SIZE,-1), 72 """ 73 self.parent = parent 74 self.parent.SetStatusBarPane(MSG_POSITION) 75 #Layout of status bar 76 self.SetFieldsCount(NB_FIELDS) 77 self.SetStatusWidths([BUTTON_SIZE, -2, -1, BUTTON_SIZE]) 78 #display default message 79 self.msg_position = MSG_POSITION 80 #save the position of the gauge 81 width, height = self.GetSize() 82 self.gauge = wx.Gauge(self, size=(width/10, height-3), 83 style=wx.GA_HORIZONTAL) 84 self.gauge.Hide() 85 #status bar icon 86 self.bitmap_bt_warning = wx.BitmapButton(self, -1, 87 size=(BUTTON_SIZE,-1), 88 88 style=wx.NO_BORDER) 89 console_bmp =wx.ArtProvider.GetBitmap(wx.ART_TIP, wx.ART_TOOLBAR)90 89 console_bmp = wx.ArtProvider.GetBitmap(wx.ART_TIP, wx.ART_TOOLBAR) 90 self.bitmap_bt_console = wx.BitmapButton(self, -1, 91 91 size=(BUTTON_SIZE-5, height-4)) 92 93 94 95 92 self.bitmap_bt_console.SetBitmapLabel(console_bmp) 93 console_hint = "History of status bar messages" 94 self.bitmap_bt_console.SetToolTipString(console_hint) 95 self.bitmap_bt_console.Bind(wx.EVT_BUTTON, self._onMonitor, 96 96 id=self.bitmap_bt_console.GetId()) 97 self.reposition() 98 ## Current progress value of the bar 99 self.nb_start = 0 100 self.nb_progress = 0 101 self.nb_stop = 0 102 103 self.frame = None 104 self.list_msg = [] 105 self.progress = 0 106 self.timer = wx.Timer(self, -1) 107 self.timer_stop = wx.Timer(self, -1) 108 self.thread = None 109 self.Bind(wx.EVT_TIMER,self.OnTimer, self.timer) 110 self.Bind(wx.EVT_TIMER,self.OnTimer_stop, self.timer_stop) 111 self.Bind(wx.EVT_SIZE, self.OnSize) 112 self.Bind(wx.EVT_IDLE, self.OnIdle) 97 self.reposition() 98 ## Current progress value of the bar 99 self.nb_start = 0 100 self.nb_progress = 0 101 self.nb_stop = 0 102 self.frame = None 103 self.list_msg = [] 104 self.progress = 0 105 self.timer = wx.Timer(self, -1) 106 self.timer_stop = wx.Timer(self, -1) 107 self.thread = None 108 self.Bind(wx.EVT_TIMER, self._on_time, self.timer) 109 self.Bind(wx.EVT_TIMER, self._on_time_stop, self.timer_stop) 110 self.Bind(wx.EVT_SIZE, self.OnSize) 111 self.Bind(wx.EVT_IDLE, self.OnIdle) 113 112 114 113 def reposition(self): … … 116 115 """ 117 116 rect = self.GetFieldRect(GAUGE_POSITION) 118 self.gauge.SetPosition((rect.x +5, rect.y-2))117 self.gauge.SetPosition((rect.x + 5, rect.y - 2)) 119 118 rect = self.GetFieldRect(ICON_POSITION) 120 self.bitmap_bt_warning.SetPosition((rect.x +5, rect.y-2))119 self.bitmap_bt_warning.SetPosition((rect.x + 5, rect.y - 2)) 121 120 rect = self.GetFieldRect(CONSOLE_POSITION) 122 self.bitmap_bt_console.SetPosition((rect.x -5, rect.y-2))121 self.bitmap_bt_console.SetPosition((rect.x - 5, rect.y - 2)) 123 122 self.sizeChanged = False 124 123 125 124 def OnIdle(self, event): 125 """ 126 """ 126 127 if self.sizeChanged: 127 128 self.reposition() 128 129 129 130 def OnSize(self, evt): 131 """ 132 """ 130 133 self.reposition() 131 134 self.sizeChanged = True … … 139 142 """ 140 143 """ 141 wxStatusB.SetStatusText(self, text, MSG_POSITION)144 wxStatusB.SetStatusText(self, text, number) 142 145 self.list_msg.append(text) 143 icon_bmp = 146 icon_bmp = wx.ArtProvider.GetBitmap(wx.ART_INFORMATION, wx.ART_TOOLBAR) 144 147 self.bitmap_bt_warning.SetBitmapLabel(icon_bmp) 145 148 try: … … 153 156 def PopStatusText(self, *args, **kwds): 154 157 """ 158 Override status bar 155 159 """ 156 160 wxStatusB.PopStatusText(self, field=MSG_POSITION) … … 159 163 """ 160 164 """ 161 wxStatusB.PushStatusText(self, field=MSG_POSITION, string=string)165 wxStatusB.PushStatusText(self, field=MSG_POSITION, string=string) 162 166 163 167 def enable_clear_gauge(self): 164 168 """ 169 clear the progress bar 165 170 """ 166 171 flag = False 167 if (self.nb_start <= self.nb_stop) or (self.nb_progress <= self.nb_stop): 172 if (self.nb_start <= self.nb_stop) or \ 173 (self.nb_progress <= self.nb_stop): 168 174 flag = True 169 175 return flag 170 176 171 def OnTimer_stop(self, evt):177 def _on_time_stop(self, evt): 172 178 """ 173 179 Clear the progress bar … … 185 191 self.nb_stop = 0 186 192 187 def OnTimer(self, evt):193 def _on_time(self, evt): 188 194 """ 189 195 Update the progress bar while the timer is running … … 219 225 self.bitmap_bt_warning.SetBitmapLabel(icon_bmp) 220 226 if msg == "info": 221 icon_bmp = wx.ArtProvider.GetBitmap(wx.ART_INFORMATION, wx.ART_TOOLBAR) 227 icon_bmp = wx.ArtProvider.GetBitmap(wx.ART_INFORMATION, 228 wx.ART_TOOLBAR) 222 229 self.bitmap_bt_warning.SetBitmapLabel(icon_bmp) 223 230 … … 237 244 type = event.type 238 245 self.gauge.Show(True) 239 if type.lower() =="start":246 if type.lower() == "start": 240 247 self.nb_start += 1 241 248 self.timer.Stop() … … 243 250 self.gauge.SetValue(int(self.progress)) 244 251 self.progress += 10 245 if self.progress < self.gauge.GetRange() -20:252 if self.progress < self.gauge.GetRange() - 20: 246 253 self.gauge.SetValue(int(self.progress)) 247 if type.lower() =="progress":254 if type.lower() == "progress": 248 255 self.nb_progress += 1 249 256 self.timer.Start(100) 250 257 self.gauge.Pulse() 251 if type.lower() =="update":258 if type.lower() == "update": 252 259 self.progress += 10 253 if self.progress < self.gauge.GetRange()- 20:260 if self.progress < self.gauge.GetRange()- 20: 254 261 self.gauge.SetValue(int(self.progress)) 255 if type.lower() =="stop":262 if type.lower() == "stop": 256 263 self.nb_stop += 1 257 264 self.gauge.Show(True) … … 278 285 def _onMonitor(self, event): 279 286 """ 287 Pop up a frame with messages sent to the status bar 280 288 """ 281 289 self.frame = Console(parent=self) 282 283 290 self.frame.set_multiple_messages(self.list_msg) 284 291 self.frame.Show(True) … … 286 293 287 294 if __name__ == "__main__": 288 app = wx.PySimpleApp() 289 frame= wx.Frame(None,wx.ID_ANY,'test frame') 290 statusBar = StatusBar(frame, wx.ID_ANY) 291 frame.SetStatusBar(statusBar) 292 frame.Show(True) 293 294 event = MessageEvent() 295 event.type = "progress" 296 event.status = "statusbar...." 297 event.info = "error" 298 statusBar.set_status(event=event) 299 app.MainLoop() 295 app = wx.PySimpleApp() 296 frame = wx.Frame(None, wx.ID_ANY, 'test frame') 297 statusBar = StatusBar(frame, wx.ID_ANY) 298 frame.SetStatusBar(statusBar) 299 frame.Show(True) 300 event = MessageEvent() 301 event.type = "progress" 302 event.status = "statusbar...." 303 event.info = "error" 304 statusBar.set_status(event=event) 305 app.MainLoop() 300 306
Note: See TracChangeset
for help on using the changeset viewer.