Changeset 1805b87 in sasview


Ignore:
Timestamp:
Mar 20, 2015 1:45:36 PM (9 years ago)
Author:
krzywon
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
Message:

Errors and warnings that are posted to the console log are now sent to
the sasview.log file. Normal INFO: messages are omitted. Fixed pylint
issues in the file I modified.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/guiframe/gui_statusbar.py

    rb3efb7d r1805b87  
     1""" 
     2Defines and draws the status bar that should appear along the bottom of the 
     3main SasView window. 
     4""" 
    15import wx 
    26import sys 
     7import logging 
    38from wx import StatusBar as wxStatusB 
    49from wx.lib import newevent 
     
    611from sas.guiframe.gui_style import GUIFRAME_ICON 
    712 
    8 # Number of fields on the status bar  
     13# Number of fields on the status bar 
    914NB_FIELDS = 4 
    1015#position of the status bar's fields 
    1116ICON_POSITION = 0 
    12 MSG_POSITION  = 1 
    13 GAUGE_POSITION  = 2 
    14 CONSOLE_POSITION  = 3 
     17MSG_POSITION = 1 
     18GAUGE_POSITION = 2 
     19CONSOLE_POSITION = 3 
    1520BUTTON_SIZE = 40 
    1621STATUS_BAR_ICON_SIZE = 12 
    1722CONSOLE_WIDTH = 500 
    1823CONSOLE_HEIGHT = 300 
     24FRAME_ICON = wx.Icon(GUIFRAME_ICON.FRAME_ICON_PATH,wx.BITMAP_TYPE_ICON) 
     25 
    1926if sys.platform.count("win32") > 0: 
    2027    FONT_VARIANT = 0 
     
    2835class ConsolePanel(wx.Panel): 
    2936    """ 
     37    Interaction class for adding messages to the Console log. 
    3038    """ 
    3139    def __init__(self, parent, *args, **kwargs): 
    32         """ 
    33         """ 
    3440        wx.Panel.__init__(self, parent=parent, *args, **kwargs) 
    3541        self.parent = parent 
    3642        self.sizer = wx.BoxSizer(wx.VERTICAL) 
    37          
     43 
    3844        self.msg_txt = wx.richtext.RichTextCtrl(self, size=(CONSOLE_WIDTH-40, 
    3945                                                CONSOLE_HEIGHT-60), 
    4046                                   style=wx.VSCROLL|wx.HSCROLL|wx.NO_BORDER) 
    41          
     47 
    4248        self.msg_txt.SetEditable(False) 
    4349        self.msg_txt.SetValue('No message available') 
    4450        self.sizer.Add(self.msg_txt, 1, wx.EXPAND|wx.ALL, 10) 
    4551        self.SetSizer(self.sizer) 
    46          
     52 
    4753    def set_message(self, status="", event=None): 
    4854        """ 
     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. 
    4959        """ 
    5060        status = str(status) 
     
    5262            return 
    5363        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) 
    5665        if hasattr(event, "info"): 
    5766            icon_type = event.info.lower() 
    5867            if icon_type == "warning": 
     68                logging.warning(status) 
    5969                color = (0, 0, 255) # blue 
    60                 icon_bmp =  wx.ArtProvider.GetBitmap(wx.ART_WARNING, 
    61                                                      wx.ART_TOOLBAR) 
     70                icon_bmp = wx.ArtProvider.GetBitmap(wx.ART_WARNING, 
     71                                                    wx.ART_TOOLBAR) 
    6272            if icon_type == "error": 
     73                logging.error(status) 
    6374                color = (255, 0, 0) # red 
    64                 icon_bmp =  wx.ArtProvider.GetBitmap(wx.ART_ERROR,  
    65                                                      wx.ART_TOOLBAR) 
     75                icon_bmp = wx.ArtProvider.GetBitmap(wx.ART_ERROR, 
     76                                                    wx.ART_TOOLBAR) 
    6677            if icon_type == "info": 
    67                 icon_bmp =  wx.ArtProvider.GetBitmap(wx.ART_INFORMATION, 
    68                                                      wx.ART_TOOLBAR) 
     78                icon_bmp = wx.ArtProvider.GetBitmap(wx.ART_INFORMATION, 
     79                                                    wx.ART_TOOLBAR) 
    6980        self.msg_txt.Newline() 
    7081        self.msg_txt.WriteBitmap(icon_bmp) 
     
    7384        self.msg_txt.AppendText(status) 
    7485        self.msg_txt.EndTextColour() 
    75          
    76          
     86 
     87 
    7788class Console(wx.Frame): 
    7889    """ 
     90    The main class defining the Console window. 
    7991    """ 
    8092    def __init__(self, parent=None, status="", *args, **kwds): 
     
    8698        self.panel.set_message(status=status) 
    8799        wx.EVT_CLOSE(self, self.Close) 
    88          
     100 
    89101    def set_multiple_messages(self, messages=[]): 
    90102        """ 
     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.  
    91106        """ 
    92107        if messages: 
    93108            for status in messages: 
    94109                self.panel.set_message(status=status) 
    95                  
     110 
    96111    def set_message(self, status, event=None): 
    97112        """ 
     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. 
    98117        """ 
    99118        self.panel.set_message(status=str(status), event=event) 
    100          
     119 
    101120    def Close(self, event): 
    102121        """ 
     122        Calling close on the panel will hide the panel. 
     123 
     124        :param event: A wx event. 
    103125        """ 
    104126        self.Hide() 
    105          
     127 
    106128class StatusBar(wxStatusB): 
    107129    """ 
     
    116138        width = STATUS_BAR_ICON_SIZE 
    117139        height = STATUS_BAR_ICON_SIZE 
    118         self.SetFieldsCount(NB_FIELDS)  
     140        self.SetFieldsCount(NB_FIELDS) 
    119141        # Leave some space for the resize handle in the last field 
    120142        console_btn_width = 80 
    121143        self.SetStatusWidths([width+4, -2, -1, width+console_btn_width]) 
    122         self.SetMinHeight(height) 
    123          
     144        self.SetMinHeight(height + 10) 
     145 
    124146        #display default message 
    125         self.msg_position = MSG_POSITION  
    126          
     147        self.msg_position = MSG_POSITION 
     148 
    127149        # Create progress bar 
    128150        gauge_width = 5 * width 
    129151        self.gauge = wx.Gauge(self, size=(gauge_width, height), 
    130                                style=wx.GA_HORIZONTAL) 
     152                              style=wx.GA_HORIZONTAL) 
    131153        self.gauge.Hide() 
    132          
     154 
    133155        # Create status bar icon reflecting the type of status 
    134156        # 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)) 
    136159        self.status_color.SetBackgroundColour(GREEN) 
    137160        self.status_color.SetForegroundColour(GREEN) 
    138161 
    139162        # 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)) 
    142165        font = self.console_button.GetFont() 
    143166        _, 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))) 
    145168        self.console_button.SetFont(font) 
    146169        self.console_button.SetToolTipString("History of status bar messages") 
    147170        self.console_button.Bind(wx.EVT_BUTTON, self._onMonitor, 
    148                                 id=self.console_button.GetId()) 
    149          
     171                                 id=self.console_button.GetId()) 
     172 
    150173        self.reposition() 
    151         ## Current progress value of the bar  
     174        ## Current progress value of the bar 
    152175        self.nb_start = 0 
    153176        self.nb_progress = 0 
     
    163186                except: 
    164187                    try: 
    165                         FRAME_ICON = wx.Icon(GUIFRAME_ICON.FRAME_ICON_PATH, 
    166                                               wx.BITMAP_TYPE_ICON) 
    167188                        self.frame.SetIcon(FRAME_ICON) 
    168189                    except: 
     
    174195        self.timer_stop = wx.Timer(self, -1) 
    175196        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 
    181202    def reposition(self): 
    182203        """ 
    183             Place the various fields in their proper position 
     204        Place the various fields in their proper position 
    184205        """ 
    185206        rect = self.GetFieldRect(GAUGE_POSITION) 
     
    189210        rect = self.GetFieldRect(CONSOLE_POSITION) 
    190211        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: 
    197219            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. 
    201224        """ 
    202225        self.reposition()  
    203         self.sizeChanged = True 
    204          
     226        self.size_changed = True 
     227 
    205228    def get_msg_position(self): 
    206229        """ 
     230        Get the last known message that was displayed on the console window. 
    207231        """ 
    208232        return self.msg_position 
    209      
     233 
    210234    def SetStatusText(self, text="", number=MSG_POSITION, event=None): 
    211235        """ 
    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) 
    214239        self.list_msg.append(text) 
    215240        self.status_color.SetBackgroundColour(GREEN) 
    216241        self.status_color.SetForegroundColour(GREEN) 
    217242 
    218         if self.frame is not None : 
     243        if self.frame is not None: 
    219244            self.frame.set_message(status=text, event=event) 
    220          
     245 
    221246    def PopStatusText(self, *args, **kwds): 
    222247        """ 
    223         Override status bar  
     248        Override status bar 
    224249        """ 
    225250        wxStatusB.PopStatusText(self, field=MSG_POSITION) 
    226          
     251 
    227252    def PushStatusText(self, *args, **kwds): 
    228253        """ 
     
    231256        text = "PushStatusText: What is this string?" 
    232257        wxStatusB.PushStatusText(self, field=MSG_POSITION, string=text) 
    233          
     258 
    234259    def enable_clear_gauge(self): 
    235260        """ 
     
    242267        #    flag = True 
    243268        return flag 
    244      
    245     def _on_time_stop(self, evt):  
     269 
     270    def _on_time_stop(self, evt): 
    246271        """ 
    247272        Clear the progress bar 
    248          
    249         :param evt: wx.EVT_TIMER  
    250    
    251         """  
     273 
     274        :param evt: wx.EVT_TIMER 
     275        """ 
    252276        count = 0 
    253         while(count <= 100): 
     277        while count <= 100: 
    254278            count += 1 
    255         self.timer_stop.Stop()  
     279        self.timer_stop.Stop() 
    256280        self.clear_gauge(msg="") 
    257         self.nb_progress = 0  
    258         self.nb_start = 0  
     281        self.nb_progress = 0 
     282        self.nb_start = 0 
    259283        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(): 
    270293            self.gauge.Pulse() 
    271     
     294 
    272295    def clear_gauge(self, msg=""): 
    273296        """ 
     
    276299        self.progress = 0 
    277300        self.gauge.SetValue(0) 
    278         self.gauge.Hide()  
    279           
     301        self.gauge.Hide() 
     302 
    280303    def set_icon(self, event): 
    281304        """ 
     
    290313            return 
    291314        if not hasattr(event, "info"): 
    292             return  
    293          
     315            return 
     316 
    294317        # Get the size of the button images 
    295318        height = STATUS_BAR_ICON_SIZE 
    296          
     319 
    297320        msg = event.info.lower() 
    298321        if msg == "warning": 
     
    305328            self.status_color.SetBackgroundColour(GREEN) 
    306329            self.status_color.SetForegroundColour(GREEN) 
    307      
     330 
    308331    def set_dialog(self, event): 
    309332        """ 
     
    311334        """ 
    312335        if not hasattr(event, "info"): 
    313             return  
     336            return 
    314337        msg = event.info.lower() 
    315338        if msg == "error": 
     
    326349        if hasattr(event, "status"): 
    327350            self.SetStatusText(text=str(event.status), event=event) 
    328         
     351   
    329352    def set_gauge(self, event): 
    330353        """ 
     
    339362            #self.timer.Stop() 
    340363            self.progress += 5 
    341             self.gauge.SetValue(int(self.progress))  
     364            self.gauge.SetValue(int(self.progress)) 
    342365            self.progress += 5 
    343366            if self.progress < self.gauge.GetRange() - 20: 
    344                 self.gauge.SetValue(int(self.progress))  
     367                self.gauge.SetValue(int(self.progress)) 
    345368        if type.lower() == "progress": 
    346369            self.nb_progress += 1 
     
    350373            self.progress += 5 
    351374            if self.progress < self.gauge.GetRange()- 20: 
    352                 self.gauge.SetValue(int(self.progress))    
     375                self.gauge.SetValue(int(self.progress)) 
    353376        if type.lower() == "stop": 
    354377            self.nb_stop += 1 
     
    357380                self.timer.Stop() 
    358381                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 
    362385    def set_status(self, event): 
    363386        """ 
    364387        Update the status bar . 
    365          
     388 
    366389        :param type: type of message send. 
    367390            type  must be in ["start","progress","update","stop"] 
    368391        :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 
    371394        """ 
    372395        self.set_message(event=event) 
     
    375398        # dialog on error 
    376399        self.set_dialog(event=event) 
    377          
     400 
    378401    def _onMonitor(self, event): 
    379402        """ 
     
    382405        self.frame.Show(False) 
    383406        self.frame.Show(True) 
    384          
    385          
     407 
     408 
    386409class SPageStatusbar(wxStatusB): 
    387410    def __init__(self, parent, timeout=None, *args, **kwds): 
    388411        wxStatusB.__init__(self, parent, *args, **kwds) 
    389         self.SetFieldsCount(1)  
     412        self.SetFieldsCount(1) 
    390413        self.timeout = timeout 
    391414        width, height = parent.GetSizeTuple() 
    392         self.gauge = wx.Gauge(self, style=wx.GA_HORIZONTAL,  
     415        self.gauge = wx.Gauge(self, style=wx.GA_HORIZONTAL, 
    393416                              size=(width, height/10)) 
    394417        rect = self.GetFieldRect(0) 
     
    396419        if self.timeout is not None: 
    397420            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) 
    400423        self.timer.Start(1) 
    401424        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(): 
    412435            self.gauge.Pulse() 
    413              
    414          
     436 
     437 
    415438if __name__ == "__main__": 
    416439    app = wx.PySimpleApp() 
Note: See TracChangeset for help on using the changeset viewer.