Search code examples
python-2.7wxpython

How to manage wx.StatusBar text in interactions with menus


I have a main window with a wx.StatusBar, in what I think is pretty standard fashion:

class MainWindow(wx.Frame):
    "Obviously, the main window..."
    def __init__(self, parent, title, appState, installTypes):
        wx.Frame.__init__(self, parent, title=title)

        # [...]

        # and StatusBar (which puts itself in the bottom of the window)
        self.CreateStatusBar() 

I have a bunch of menus, which display their help in the StatusBar:

    # Auto-exit  toggle:
    menuOptionsAutoExit = optionsmenu.Append(ID_OPTIONS_AUTO_EXIT,
                                             _("&Auto-exit"), 
                                             _("Have CMH exit after showing the status"), 
                                             kind = wx.ITEM_CHECK)

But I also have events in my controller that need to be reported in the status bar. Each of these has two actions that need to be done in the StatusBar: displaying the notification ("something is happening") then removing that.

The problem is that if the user is moused over a menu item (so that item's help has replaced "something is happening" in the status bar) at the time that I do the "remove the message", the result is that the removal is missed, and after they mouse off the menu item, I'm left with "something is happening" forever.

I've tried pretty much every combination I can think of of using either SetStatusText() or PushStatusText() to put "something is happening", and PopStatusText() or SetStatusText('') to clear it. No matter what I do, by messing around with the menus in between setting the status message and clearing it I can end up with the "something is happening" stuck there.

What's the right recipe for this?

(wxpython 3.0.0.0, same behaviour under OSX and Win7)


Solution

  • A bit of a work around but, might work for you.

    self.CreateStatusBar(2)
    self.SetStatusText("A Custom StatusBar...", 1)
    wx.CallLater(10000, self.SetStatusText, "", 1)
    

    So, do not use the first field on the statusbar for your messages.