contextual menu on wx.TextCtrl

311 views
Skip to first unread message

f

unread,
Feb 11, 2005, 10:44:22 AM2/11/05
to wx-u...@lists.wxwidgets.org

Hello,

I've got wxPython-2.5.3.1-unicode-gtk2 running on linux

In my gui, I have several wx.TextCtrls, and I need to pop-up a custom
menu when the user right-click on the control.

The problem is that the gtk2 default menu with (cut, paste, input
method...) always appears.

I've discovered that the wx.EVT_RIGHT_UP event is never caught.

I hope somebody has a fix to that, I really need it cause of space
constraints in my gui. (i can't add button close to widget to drop a menu)


test program :

import wx

class App(wx.App):
def OnInit(self):
frame = wx.Frame(None, -1, 'test entry')
frame.Show()
panel = wx.Panel(frame)
tc = wx.TextCtrl(panel)
tc.Bind(wx.EVT_RIGHT_UP, self.OnRightClick)

return True
def OnRightClick(self, evt):
print evt
app = App()
app.MainLoop()

Robin Dunn

unread,
Feb 11, 2005, 12:51:53 PM2/11/05
to wx-u...@lists.wxwidgets.org
f wrote:
>
> Hello,
>
> I've got wxPython-2.5.3.1-unicode-gtk2 running on linux
>
> In my gui, I have several wx.TextCtrls, and I need to pop-up a custom
> menu when the user right-click on the control.
>
> The problem is that the gtk2 default menu with (cut, paste, input
> method...) always appears.
>
> I've discovered that the wx.EVT_RIGHT_UP event is never caught.
>
> I hope somebody has a fix to that, I really need it cause of space
> constraints in my gui. (i can't add button close to widget to drop a menu)
>

It looks to me that the native context menu is happening on right button
down, not up. Try intercepting that event. You may also want to try
wx.EVT_CONTEXT_MENU

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


Otto Wyss

unread,
Feb 11, 2005, 3:35:32 PM2/11/05
to wxWidgets-User
> It looks to me that the native context menu is happening on right button
> down, not up. Try intercepting that event. You may also want to try

That is IMO wrong, the context menu should always be triggert by right
button up.

O. Wyss

--
Development of frame buffer drivers: http://linux-fbdev.sf.net
Sample code snippets for wxWidgets: http://wxcode.sf.net
How to build well-designed applications: http://wxguide.sf.net
Desktop with a consistent look and feel: http://wyodesktop.sf.net

Otto Wyss

unread,
Feb 12, 2005, 3:58:16 AM2/12/05
to wxWidgets-User
> On Feb 11, 2005, at 3:35 PM, Otto Wyss wrote:
>
> >> It looks to me that the native context menu is happening on right
> >> button
> >> down, not up. Try intercepting that event. You may also want to try
> >
> > That is IMO wrong, the context menu should always be triggert by right
> > button up.
> >
> Excuse me?
>
> Only on OS/2 (where all dragging is done by right mouse button) and on
> Windows 95 (where dragging can be done with right mouse button) is this
> bastardization required.
>
> On the Mac (assuming I have a right-mouse button or I'm holding Ctrl
> while using the only button) I can click and hold the button. As soon
> as I click (down) the menu comes up and I simply move to the choice
> then release. This is exactly like the behavior for normal menus (the
> ones that drop from the menubar). With context menus triggered on up
> instead of down I must click (down and up) once, wait for the menu to
> appear, then move and click (down and up) again. Personally I feel the
> Mac behavior is better here although it does prevent the right button
> or Ctrl+button from being used to drag.
>
> In any case, the true point of this message is that different platforms
> have different behavior. The entire purpose of wxWidgets is to
> abstract these differences in behavior. I realize you aren't a fan of
> true native behavior and thus use wxUniversal. However, most of the
> rest of us want MSW behavior on MSW and Mac behavior on Mac and OS/2
> behavior on OS/2 and so on and so forth. Even differences like this
> which may seem trivial to you will seriously piss off a power user.
>
In general you are right that platforms have to be considered. But with
right-down you can't drag with the right button, regadless of the
platform. You don't have much choice than to use right-up what Windows
does.

On the Mac there isn't a right button so the discussion is mot except
that ctrl-click has to be maped to the right event. If usually the
ctrl-click-down brings up the context menu than this should be mapped to
the right-up event. That way context menus work everywhere.

David Elliott

unread,
Feb 11, 2005, 6:38:07 PM2/11/05
to wx-u...@lists.wxwidgets.org
On Feb 11, 2005, at 3:35 PM, Otto Wyss wrote:

>> It looks to me that the native context menu is happening on right
>> button
>> down, not up. Try intercepting that event. You may also want to try
>
> That is IMO wrong, the context menu should always be triggert by right
> button up.
>

Excuse me?

Only on OS/2 (where all dragging is done by right mouse button) and on
Windows 95 (where dragging can be done with right mouse button) is this
bastardization required.

On the Mac (assuming I have a right-mouse button or I'm holding Ctrl
while using the only button) I can click and hold the button. As soon
as I click (down) the menu comes up and I simply move to the choice
then release. This is exactly like the behavior for normal menus (the
ones that drop from the menubar). With context menus triggered on up
instead of down I must click (down and up) once, wait for the menu to
appear, then move and click (down and up) again. Personally I feel the
Mac behavior is better here although it does prevent the right button
or Ctrl+button from being used to drag.

In any case, the true point of this message is that different platforms
have different behavior. The entire purpose of wxWidgets is to
abstract these differences in behavior. I realize you aren't a fan of
true native behavior and thus use wxUniversal. However, most of the
rest of us want MSW behavior on MSW and Mac behavior on Mac and OS/2
behavior on OS/2 and so on and so forth. Even differences like this
which may seem trivial to you will seriously piss off a power user.

-Dave


David Elliott

unread,
Feb 12, 2005, 11:05:19 AM2/12/05
to wx-u...@lists.wxwidgets.org
On Feb 12, 2005, at 3:58 AM, Otto Wyss wrote:

> In general you are right that platforms have to be considered. But with
> right-down you can't drag with the right button, regadless of the
> platform. You don't have much choice than to use right-up what Windows
> does.
>
> On the Mac there isn't a right button so the discussion is mot except
> that ctrl-click has to be maped to the right event. If usually the
> ctrl-click-down brings up the context menu than this should be mapped
> to
> the right-up event. That way context menus work everywhere.
>

I agree this is an interesting hack (send right mouse up event on right
mouse or Ctrl+click down) but I suggest if what you are trying to do is
bring up a context menu that you catch the event for context menus
instead of the right-up event.

-Dave


Reply all
Reply to author
Forward
0 new messages