Menu UpdateUI events

Robin Dunn wrote:

Will Sadkin wrote:
> [...]
> So here's what I want to do: use EVT_RIGHT_UP to bring up
> my own menu, but hook in to the update UI chain to a) do my
> own enabling/disabling of the menu items, and b) suppress
> the default "update ui" behavior of the base control.
>
> Can someone enlighten me on how to do this?

Attach the EVT_UPDATE_UI handlers to the textctrl and don't call
event.Skip() in the handlers.

Ok, well I tried that, but the event doesn't even fire. Here's a
code snippet:

    EVT_RIGHT_UP(self, self._OnContextMenu )

    def _OnContextMenu(self, event):
        dbg('OnContextMenu()', indent=1)
        self._contextMenu = wxMenu()
        self._contextMenu.Append(wxID_UNDO, "Undo", "")
    [...]
    EVT_UPDATE_UI(self._contextMenu, wxID_UNDO, self.UndoUIUpdate)

        self.PopupMenu(self._contextMenu, event.GetPosition())
        self._contextMenu.Destroy()
    self._contextMenu = None
        dbg(indent=0)

    def UndoUIUpdate(self, event=None):
        dbg('UndoUIUpdate')
        if self._prevValue is None or self._prevValue == self._curValue:
            dbg('no previous value to undo')
            self._contextMenu.Enable(wxID_UNDO, False)
        else:
            dbg('previous value present to undo')
            self._contextMenu.Enable(wxID_UNDO, True)

The menu pops up, but the UndoUIUpdate never gets called.
If I call UndoUIUpdate directly in the 1st function,
its action gets overridden by the base control before the
menu actually pops!

Vadim Zeitlin wrote (on wx-users):

Is there any way for me to hook into this menu,
and replace the implementations of cut and paste?
I tried hooking up EVT_MENU on the above Ids, but
these events don't seem to fire...

Because they're not wxWindows events at all...

If you want to have such popup menu on all platforms
your best bet would be to simply show your own.

After experimenting, my workaround is simply to use
a different (new) ID, and enable/disable the menu
item on creation, since it's ephemeral anyway.

But I would like to know what's going on, and if
there's a more proper way to work around this...)

(wxWindows 2.4.1.2, MSW, python 2.2.3)

/Will Sadkin
Parlance Corporation
www.nameconnector.com

Will Sadkin wrote:

Robin Dunn wrote:

Will Sadkin wrote:

[...]
So here's what I want to do: use EVT_RIGHT_UP to bring up
my own menu, but hook in to the update UI chain to a) do my
own enabling/disabling of the menu items, and b) suppress the default "update ui" behavior of the base control.

Can someone enlighten me on how to do this?

Attach the EVT_UPDATE_UI handlers to the textctrl and don't call event.Skip() in the handlers.

Ok, well I tried that, but the event doesn't even fire. Here's a
code snippet:

    EVT_RIGHT_UP(self, self._OnContextMenu )

    def _OnContextMenu(self, event):
        dbg('OnContextMenu()', indent=1)
        self._contextMenu = wxMenu()
        self._contextMenu.Append(wxID_UNDO, "Undo", "")
    [...]
    EVT_UPDATE_UI(self._contextMenu, wxID_UNDO, self.UndoUIUpdate)

Try using just 'self' here for the first parameter.

ยทยทยท

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!