Changeset 1805b87 in sasview for src/sas/guiframe
- Timestamp:
- Mar 20, 2015 3:45:36 PM (10 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:
- bf6b8d1, dea2f6e
- Parents:
- 8eee1d7
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/guiframe/gui_statusbar.py
rb3efb7d r1805b87 1 """ 2 Defines and draws the status bar that should appear along the bottom of the 3 main SasView window. 4 """ 1 5 import wx 2 6 import sys 7 import logging 3 8 from wx import StatusBar as wxStatusB 4 9 from wx.lib import newevent … … 6 11 from sas.guiframe.gui_style import GUIFRAME_ICON 7 12 8 # Number of fields on the status bar 13 # Number of fields on the status bar 9 14 NB_FIELDS = 4 10 15 #position of the status bar's fields 11 16 ICON_POSITION = 0 12 MSG_POSITION 13 GAUGE_POSITION 14 CONSOLE_POSITION 17 MSG_POSITION = 1 18 GAUGE_POSITION = 2 19 CONSOLE_POSITION = 3 15 20 BUTTON_SIZE = 40 16 21 STATUS_BAR_ICON_SIZE = 12 17 22 CONSOLE_WIDTH = 500 18 23 CONSOLE_HEIGHT = 300 24 FRAME_ICON = wx.Icon(GUIFRAME_ICON.FRAME_ICON_PATH,wx.BITMAP_TYPE_ICON) 25 19 26 if sys.platform.count("win32") > 0: 20 27 FONT_VARIANT = 0 … … 28 35 class ConsolePanel(wx.Panel): 29 36 """ 37 Interaction class for adding messages to the Console log. 30 38 """ 31 39 def __init__(self, parent, *args, **kwargs): 32 """33 """34 40 wx.Panel.__init__(self, parent=parent, *args, **kwargs) 35 41 self.parent = parent 36 42 self.sizer = wx.BoxSizer(wx.VERTICAL) 37 43 38 44 self.msg_txt = wx.richtext.RichTextCtrl(self, size=(CONSOLE_WIDTH-40, 39 45 CONSOLE_HEIGHT-60), 40 46 style=wx.VSCROLL|wx.HSCROLL|wx.NO_BORDER) 41 47 42 48 self.msg_txt.SetEditable(False) 43 49 self.msg_txt.SetValue('No message available') 44 50 self.sizer.Add(self.msg_txt, 1, wx.EXPAND|wx.ALL, 10) 45 51 self.SetSizer(self.sizer) 46 52 47 53 def set_message(self, status="", event=None): 48 54 """ 55 Adds a message to the console log as well as the main sasview.log 56 57 :param status: A status message to be sent to the console log. 58 :param event: A wx event. 49 59 """ 50 60 status = str(status) … … 52 62 return 53 63 color = (0, 0, 0) #black 54 icon_bmp = wx.ArtProvider.GetBitmap(wx.ART_INFORMATION, 55 wx.ART_TOOLBAR) 64 icon_bmp = wx.ArtProvider.GetBitmap(wx.ART_INFORMATION, wx.ART_TOOLBAR) 56 65 if hasattr(event, "info"): 57 66 icon_type = event.info.lower() 58 67 if icon_type == "warning": 68 logging.warning(status) 59 69 color = (0, 0, 255) # blue 60 icon_bmp = 61 70 icon_bmp = wx.ArtProvider.GetBitmap(wx.ART_WARNING, 71 wx.ART_TOOLBAR) 62 72 if icon_type == "error": 73 logging.error(status) 63 74 color = (255, 0, 0) # red 64 icon_bmp = wx.ArtProvider.GetBitmap(wx.ART_ERROR,65 75 icon_bmp = wx.ArtProvider.GetBitmap(wx.ART_ERROR, 76 wx.ART_TOOLBAR) 66 77 if icon_type == "info": 67 icon_bmp = 68 78 icon_bmp = wx.ArtProvider.GetBitmap(wx.ART_INFORMATION, 79 wx.ART_TOOLBAR) 69 80 self.msg_txt.Newline() 70 81 self.msg_txt.WriteBitmap(icon_bmp) … … 73 84 self.msg_txt.AppendText(status) 74 85 self.msg_txt.EndTextColour() 75 76 86 87 77 88 class Console(wx.Frame): 78 89 """ 90 The main class defining the Console window. 79 91 """ 80 92 def __init__(self, parent=None, status="", *args, **kwds): … … 86 98 self.panel.set_message(status=status) 87 99 wx.EVT_CLOSE(self, self.Close) 88 100 89 101 def set_multiple_messages(self, messages=[]): 90 102 """ 103 Method to send an arbitrary number of messages to the console log 104 105 :param messages: A list of strings to be sent to the console log. 91 106 """ 92 107 if messages: 93 108 for status in messages: 94 109 self.panel.set_message(status=status) 95 110 96 111 def set_message(self, status, event=None): 97 112 """ 113 Exposing the base ConsolePanel set_message 114 115 :param status: A status message to be sent to the console log. 116 :param event: A wx event. 98 117 """ 99 118 self.panel.set_message(status=str(status), event=event) 100 119 101 120 def Close(self, event): 102 121 """ 122 Calling close on the panel will hide the panel. 123 124 :param event: A wx event. 103 125 """ 104 126 self.Hide() 105 127 106 128 class StatusBar(wxStatusB): 107 129 """ … … 116 138 width = STATUS_BAR_ICON_SIZE 117 139 height = STATUS_BAR_ICON_SIZE 118 self.SetFieldsCount(NB_FIELDS) 140 self.SetFieldsCount(NB_FIELDS) 119 141 # Leave some space for the resize handle in the last field 120 142 console_btn_width = 80 121 143 self.SetStatusWidths([width+4, -2, -1, width+console_btn_width]) 122 self.SetMinHeight(height )123 144 self.SetMinHeight(height + 10) 145 124 146 #display default message 125 self.msg_position = MSG_POSITION 126 147 self.msg_position = MSG_POSITION 148 127 149 # Create progress bar 128 150 gauge_width = 5 * width 129 151 self.gauge = wx.Gauge(self, size=(gauge_width, height), 130 152 style=wx.GA_HORIZONTAL) 131 153 self.gauge.Hide() 132 154 133 155 # Create status bar icon reflecting the type of status 134 156 # for the last message 135 self.status_color = wx.StaticText(self, id=wx.NewId(), label=" ", size=wx.Size(15,15)) 157 self.status_color = wx.StaticText(self, id=wx.NewId(), label=" ", 158 size=wx.Size(15, 15)) 136 159 self.status_color.SetBackgroundColour(GREEN) 137 160 self.status_color.SetForegroundColour(GREEN) 138 161 139 162 # Create the button used to show the console dialog 140 self.console_button = wx.Button(self, wx.NewId(), "Console", 141 size=(console_btn_width, -1))163 self.console_button = wx.Button(self, wx.NewId(), "Console", 164 size=(console_btn_width, -1)) 142 165 font = self.console_button.GetFont() 143 166 _, pixel_h = font.GetPixelSize() 144 font.SetPixelSize(wx.Size(0, int(pixel_h*0.9)))167 font.SetPixelSize(wx.Size(0, int(pixel_h*0.9))) 145 168 self.console_button.SetFont(font) 146 169 self.console_button.SetToolTipString("History of status bar messages") 147 170 self.console_button.Bind(wx.EVT_BUTTON, self._onMonitor, 148 id=self.console_button.GetId())149 171 id=self.console_button.GetId()) 172 150 173 self.reposition() 151 ## Current progress value of the bar 174 ## Current progress value of the bar 152 175 self.nb_start = 0 153 176 self.nb_progress = 0 … … 163 186 except: 164 187 try: 165 FRAME_ICON = wx.Icon(GUIFRAME_ICON.FRAME_ICON_PATH,166 wx.BITMAP_TYPE_ICON)167 188 self.frame.SetIcon(FRAME_ICON) 168 189 except: … … 174 195 self.timer_stop = wx.Timer(self, -1) 175 196 self.thread = None 176 self.Bind(wx.EVT_TIMER, self._on_time, self.timer) 177 self.Bind(wx.EVT_TIMER, self._on_time_stop, self.timer_stop) 178 self.Bind(wx.EVT_SIZE, self. OnSize)179 self.Bind(wx.EVT_IDLE, self. OnIdle)180 197 self.Bind(wx.EVT_TIMER, self._on_time, self.timer) 198 self.Bind(wx.EVT_TIMER, self._on_time_stop, self.timer_stop) 199 self.Bind(wx.EVT_SIZE, self.on_size) 200 self.Bind(wx.EVT_IDLE, self.on_idle) 201 181 202 def reposition(self): 182 203 """ 183 204 Place the various fields in their proper position 184 205 """ 185 206 rect = self.GetFieldRect(GAUGE_POSITION) … … 189 210 rect = self.GetFieldRect(CONSOLE_POSITION) 190 211 self.console_button.SetPosition((rect.x, rect.y)) 191 self.sizeChanged = False 192 193 def OnIdle(self, event): 194 """ 195 """ 196 if self.sizeChanged: 212 self.size_changed = False 213 214 def on_idle(self, event): 215 """ 216 When the window is idle, check if the window has been resized 217 """ 218 if self.size_changed: 197 219 self.reposition() 198 199 def OnSize(self, evt): 200 """ 220 221 def on_size(self, evt): 222 """ 223 If the window is resized, redraw the window. 201 224 """ 202 225 self.reposition() 203 self.size Changed = True204 226 self.size_changed = True 227 205 228 def get_msg_position(self): 206 229 """ 230 Get the last known message that was displayed on the console window. 207 231 """ 208 232 return self.msg_position 209 233 210 234 def SetStatusText(self, text="", number=MSG_POSITION, event=None): 211 235 """ 212 """ 213 wxStatusB.SetStatusText(self, text.split('\n',1)[0], number) 236 Set the text that will be displayed in the status bar. 237 """ 238 wxStatusB.SetStatusText(self, text.split('\n', 1)[0], number) 214 239 self.list_msg.append(text) 215 240 self.status_color.SetBackgroundColour(GREEN) 216 241 self.status_color.SetForegroundColour(GREEN) 217 242 218 if self.frame is not None 243 if self.frame is not None: 219 244 self.frame.set_message(status=text, event=event) 220 245 221 246 def PopStatusText(self, *args, **kwds): 222 247 """ 223 Override status bar 248 Override status bar 224 249 """ 225 250 wxStatusB.PopStatusText(self, field=MSG_POSITION) 226 251 227 252 def PushStatusText(self, *args, **kwds): 228 253 """ … … 231 256 text = "PushStatusText: What is this string?" 232 257 wxStatusB.PushStatusText(self, field=MSG_POSITION, string=text) 233 258 234 259 def enable_clear_gauge(self): 235 260 """ … … 242 267 # flag = True 243 268 return flag 244 245 def _on_time_stop(self, evt): 269 270 def _on_time_stop(self, evt): 246 271 """ 247 272 Clear the progress bar 248 249 :param evt: wx.EVT_TIMER 250 251 """ 273 274 :param evt: wx.EVT_TIMER 275 """ 252 276 count = 0 253 while (count <= 100):277 while count <= 100: 254 278 count += 1 255 self.timer_stop.Stop() 279 self.timer_stop.Stop() 256 280 self.clear_gauge(msg="") 257 self.nb_progress = 0 258 self.nb_start = 0 281 self.nb_progress = 0 282 self.nb_start = 0 259 283 self.nb_stop = 0 260 261 def _on_time(self, evt): 262 """ 263 Update the progress bar while the timer is running 264 265 :param evt: wx.EVT_TIMER 266 267 """ 268 # Check stop flag that can be set from non main thread 269 if self.timer.IsRunning(): 284 285 def _on_time(self, evt): 286 """ 287 Update the progress bar while the timer is running 288 289 :param evt: wx.EVT_TIMER 290 """ 291 # Check stop flag that can be set from non main thread 292 if self.timer.IsRunning(): 270 293 self.gauge.Pulse() 271 294 272 295 def clear_gauge(self, msg=""): 273 296 """ … … 276 299 self.progress = 0 277 300 self.gauge.SetValue(0) 278 self.gauge.Hide() 279 301 self.gauge.Hide() 302 280 303 def set_icon(self, event): 281 304 """ … … 290 313 return 291 314 if not hasattr(event, "info"): 292 return 293 315 return 316 294 317 # Get the size of the button images 295 318 height = STATUS_BAR_ICON_SIZE 296 319 297 320 msg = event.info.lower() 298 321 if msg == "warning": … … 305 328 self.status_color.SetBackgroundColour(GREEN) 306 329 self.status_color.SetForegroundColour(GREEN) 307 330 308 331 def set_dialog(self, event): 309 332 """ … … 311 334 """ 312 335 if not hasattr(event, "info"): 313 return 336 return 314 337 msg = event.info.lower() 315 338 if msg == "error": … … 326 349 if hasattr(event, "status"): 327 350 self.SetStatusText(text=str(event.status), event=event) 328 351 329 352 def set_gauge(self, event): 330 353 """ … … 339 362 #self.timer.Stop() 340 363 self.progress += 5 341 self.gauge.SetValue(int(self.progress)) 364 self.gauge.SetValue(int(self.progress)) 342 365 self.progress += 5 343 366 if self.progress < self.gauge.GetRange() - 20: 344 self.gauge.SetValue(int(self.progress)) 367 self.gauge.SetValue(int(self.progress)) 345 368 if type.lower() == "progress": 346 369 self.nb_progress += 1 … … 350 373 self.progress += 5 351 374 if self.progress < self.gauge.GetRange()- 20: 352 self.gauge.SetValue(int(self.progress)) 375 self.gauge.SetValue(int(self.progress)) 353 376 if type.lower() == "stop": 354 377 self.nb_stop += 1 … … 357 380 self.timer.Stop() 358 381 self.progress = 0 359 self.gauge.SetValue(100) 360 self.timer_stop.Start(5) 361 382 self.gauge.SetValue(100) 383 self.timer_stop.Start(5) 384 362 385 def set_status(self, event): 363 386 """ 364 387 Update the status bar . 365 388 366 389 :param type: type of message send. 367 390 type must be in ["start","progress","update","stop"] 368 391 :param msg: the message itself as string 369 :param thread: if updatting using a thread status 370 392 :param thread: if updatting using a thread status 393 371 394 """ 372 395 self.set_message(event=event) … … 375 398 # dialog on error 376 399 self.set_dialog(event=event) 377 400 378 401 def _onMonitor(self, event): 379 402 """ … … 382 405 self.frame.Show(False) 383 406 self.frame.Show(True) 384 385 407 408 386 409 class SPageStatusbar(wxStatusB): 387 410 def __init__(self, parent, timeout=None, *args, **kwds): 388 411 wxStatusB.__init__(self, parent, *args, **kwds) 389 self.SetFieldsCount(1) 412 self.SetFieldsCount(1) 390 413 self.timeout = timeout 391 414 width, height = parent.GetSizeTuple() 392 self.gauge = wx.Gauge(self, style=wx.GA_HORIZONTAL, 415 self.gauge = wx.Gauge(self, style=wx.GA_HORIZONTAL, 393 416 size=(width, height/10)) 394 417 rect = self.GetFieldRect(0) … … 396 419 if self.timeout is not None: 397 420 self.gauge.SetRange(int(self.timeout)) 398 self.timer = wx.Timer(self, -1) 399 self.Bind(wx.EVT_TIMER, self._on_time, self.timer) 421 self.timer = wx.Timer(self, -1) 422 self.Bind(wx.EVT_TIMER, self._on_time, self.timer) 400 423 self.timer.Start(1) 401 424 self.pos = 0 402 403 def _on_time(self, evt): 404 """ 405 Update the progress bar while the timer is running 406 407 :param evt: wx.EVT_TIMER 408 409 """ 410 # Check stop flag that can be set from non main thread 411 if self.timeout is None and self.timer.IsRunning(): 425 426 def _on_time(self, evt): 427 """ 428 Update the progress bar while the timer is running 429 430 :param evt: wx.EVT_TIMER 431 432 """ 433 # Check stop flag that can be set from non main thread 434 if self.timeout is None and self.timer.IsRunning(): 412 435 self.gauge.Pulse() 413 414 436 437 415 438 if __name__ == "__main__": 416 439 app = wx.PySimpleApp()
Note: See TracChangeset
for help on using the changeset viewer.