Restoring statusbar text field

Hi Andrea,

Well, I don't know the internal magic of wx.Menu, but aren't wx-dev
using statusbar methods like PushStatusText and PopStatusText to
handle longHelps for menus in order to restore the previous statusbar
text?

Apparently that doesn't happen. I have been using this work-around for
a long time now:

class StatusBar(wx.StatusBar):
    def __init__(self, parent, viewer):
        super(StatusBar, self).__init__(parent, -1)
        self.SetFieldsCount(2)
        self.parent = parent
        self.viewer = viewer
        patterns.Publisher().registerObserver(self.onSelect,
            eventType=self.viewer.selectEventType())
        patterns.Publisher().registerObserver(self.onSelect,
            eventType=self.viewer.viewerChangeEventType())
        self.scheduledStatusDisplay = None
        self.onSelect(None)
        parent.Bind(wx.EVT_MENU_HIGHLIGHT_ALL, self.resetStatusBar)
        parent.Bind(wx.EVT_TOOL_ENTER, self.resetStatusBar)

    def resetStatusBar(self, event):
        ''' Unfortunately, the menu's and toolbar don't restore the
            previous statusbar text after they have displayed their help
            text, so we have to do it by hand. '''
        try:
            id = event.GetSelection() # for CommandEvent from the Toolbar
        except AttributeError:
            id = event.GetMenuId() # for MenuEvent
        if id == -1:
            self._displayStatus()
        event.Skip()

    def onSelect(self, *args, **kwargs):
        # Give viewer a chance to update first:
        wx.CallAfter(self._displayStatus)

    def _displayStatus(self):
        status1, status2 = self.viewer.statusMessages()
        super(StatusBar, self).SetStatusText(status1, 0)
        super(StatusBar, self).SetStatusText(status2, 1)

    def SetStatusText(self, message, pane=0, delay=3000):
        if self.scheduledStatusDisplay:
            self.scheduledStatusDisplay.Stop()
        super(StatusBar, self).SetStatusText(message, pane)
        self.scheduledStatusDisplay = wx.FutureCall(delay, self._displayStatus)

    def Destroy(self):
        patterns.Publisher().removeObserver(self.onSelect,
            eventType=self.viewer.selectEventType())
        patterns.Publisher().removeObserver(self.onSelect,
            eventType=self.viewer.viewerChangeEventType())
        self.parent.Unbind(wx.EVT_MENU_HIGHLIGHT_ALL)
        self.parent.Unbind(wx.EVT_TOOL_ENTER)
        if self.scheduledStatusDisplay:
            self.scheduledStatusDisplay.Stop()
        super(StatusBar, self).Destroy()

HTH, Frank

···

2007/3/28, Andrea Gavana <andrea.gavana@gmail.com>:

Hi Frank,

I see a

  from wx.lib.statusbarmixins import Stack, History, Observer

in wxPython's future :slight_smile:

Stack:
  - push/pop messages before/after menu item long help display

History:
  - keep history of last N status messages and display
    them in a tooltip when mouse hovers over statusbar

Observer:
  - add wx.lib.pubsub (since its already in wxPython)
    observer pattern such that status messages can
    be sent via a signal

Also, delayed display and scheduled clearing of status text
messages are nice ! :slight_smile:

Karsten

···

--
GPG key ID E4071346 @ wwwkeys.pgp.net
E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346

Well, yeah, uhm, I'm covered in work coding GNUmed ... But I
am certainly willing to review code anyone comes up with and
come up with ideas (yeah, as if that was any work :wink:

Karsten

···

On Wed, Mar 28, 2007 at 10:48:48PM +0200, Frank Niessink wrote:

>I see a
>
> from wx.lib.statusbarmixins import Stack, History, Observer
>
>in wxPython's future :slight_smile:

That would be cool! When do you think you will be finished? :wink:

--
GPG key ID E4071346 @ wwwkeys.pgp.net
E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346

Hi Frank,

Hi Andrea,

> Well, I don't know the internal magic of wx.Menu, but aren't wx-dev
> using statusbar methods like PushStatusText and PopStatusText to
> handle longHelps for menus in order to restore the previous statusbar
> text?

Apparently that doesn't happen. I have been using this work-around for
a long time now:

<snip>
<snap>

Thank you for your help. I thought this was such a basic and
easy-to-implement feature that wxWidgets should have had it from the
start. I am obviously missing something :-D.

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.virgilio.it/infinity77/

···

On 3/28/07, Frank Niessink wrote:

2007/3/28, Andrea Gavana <andrea.gavana@gmail.com>: