[wxPython-users] Menu accelerators triggered when editing text in TextCtrl

Frank Niessink frank at niessink.com
Sat Sep 1 13:40:42 PDT 2007


2007/8/28, Robin Dunn <robin at alldunn.com>:
> Frank Niessink wrote:
> >
> > My app uses accelerators for things like cut, copy, paste, etc.
> > Defined as '&Cut\tCtrl-C' etc. On Mac OSX (wxPython 2.8.4.0) these
> > global accelerators are triggered when editing text in a dialog
> > window, instead of the native cut, copy, paste functionality of the
> > TextCtrl. What's the best way to prevent this from happening? Should I
> > use an accelerator table for the mainwindow instead of the automatic
> > accelerators or are there other options?
>
> IIRC there is something in the Apple HIG that requires that the main
> frame's Edit menu and the common clipboard menu items remain active even
> when modal dialogs are active, and so this is why it works this way in
> wxMac.  However I've also seen the problem you describe but was never
> satisfied with the workarounds I tried.  I had an idea a few days ago
> that I haven't had a chance yet to try...  Does it work if you give the
> text widgets themselves an accelerator table?  I know that the textctrl
> class already has EVT_MENU bindings for the standard clipboard IDs so it
> may just work with no other effort on your part, as long as they are
> able to get the menu events from the accelerators.

I tried: self.SetAcceleratorTable(wx.AcceleratorTable([]))
where self is the TextCtrl, but that didn't make a difference. BTW, if the
Cut, Copy or Paste menu items on the main menubar are disabled (e.g.
Copy and Cut are disabled when there are no tasks selected in the main
window), then Ctrl-C and Ctrl-X work on the text in the TextCtrl. So I
guess a work around could be to have the handlers disable themselves
whenever a textctrl has focus.

Cheers, Frank




More information about the wxpython-users mailing list