EVT_CONTEXT_MENU behaves differently on different selected grid cells

Hi,

I have a strange problem on a wx.Grid: it processes an EVT_CONTEXT_MENU when one cell is selected, but not when more than one is.

A demo program, sample_grid_test.py is attached.

The demo imports another module, Clipboard.py, also attached.

Basically, the TestFrame class - as a descendant of Clipboard.CopyAndPaste, is able to create a PopUp menu (lines 52-55 in Clipboard.py).
But, for reasons I don’t understand, this event is fired/processed only if just one grid cell is selected.

Anyone has an idea ?

Bye,

Ron.

Clipboard.py (4.98 KB)

sample_grid_test.py (1.31 KB)

Hi,

I have a strange problem on a wx.Grid: it processes an EVT_CONTEXT_MENU when one cell is selected, but not when more than one is.

A demo program, sample_grid_test.py is attached.

The demo imports another module, Clipboard.py, also attached.

Basically, the TestFrame class - as a descendant of Clipboard.CopyAndPaste, is able to create a PopUp menu (lines 52-55 in Clipboard.py).
But, for reasons I don’t understand, this event is fired/processed only if just one grid cell is selected.

Anyone has an idea ?

Bye,

Ron.

An update: After reading of InspectionTool class, I used it to see which events I might use besides EVT_CONTEXT_MENU.
EVT_RIGHT_UP seemed like a promissing candidate, but - as with EVT_CONTEXT_MENU, it does not fire when more than one grid cell is selected.

Barak, Ron wrote:

Hi,
I have a strange problem on a wx.Grid: it processes an EVT_CONTEXT_MENU when /one cell is selected/, but not when /more than one/ is.
A demo program, sample_grid_test.py is attached.
The demo imports another module, Clipboard.py, also attached.
Basically, the TestFrame class - as a descendant of Clipboard.CopyAndPaste, is able to create a PopUp menu (lines 52-55 in Clipboard.py).
But, for reasons I don't understand, this event is fired/processed only if just one grid cell is selected.
Anyone has an idea ?
Bye,
Ron.
An update: After reading of InspectionTool class, I used it to see which events I might use besides EVT_CONTEXT_MENU.
EVT_RIGHT_UP seemed like a promissing candidate, but - as with EVT_CONTEXT_MENU, it does not fire when more than one grid cell is selected.

Maybe you're looking for wx.grid.EVT_GRID_RANGE_SELECT ?

···

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org
Python Extension Building Network: http://www.pythonlibrary.org

Barak, Ron wrote:

Hi,
I have a strange problem on a wx.Grid: it processes an EVT_CONTEXT_MENU when /one cell is selected/, but not when /more than one/ is.
A demo program, sample_grid_test.py is attached.
The demo imports another module, Clipboard.py, also attached.
Basically, the TestFrame class - as a descendant of Clipboard.CopyAndPaste, is able to create a PopUp menu (lines 52-55 in Clipboard.py).
But, for reasons I don't understand, this event is fired/processed only if just one grid cell is selected.
Anyone has an idea ?

The grid window (the embedded window that shows the cells) is capturing various mouse events in it's own event handlers, and that is interfering with the sending of the EVT_CONTEXT_MENU. (It is normally sent by the system only when the other right-mouse button events are not handled.) You'll probably notice that if you press the Windows menu key on the keyboard then you'll get the context menu even every time.

An update: After reading of InspectionTool class, I used it to see which events I might use besides EVT_CONTEXT_MENU.
EVT_RIGHT_UP seemed like a promissing candidate, but - as with EVT_CONTEXT_MENU, it does not fire when more than one grid cell is selected.

Try using the EVT_GRID_CELL_RIGHT_CLICK event instead. It is sent by the grid and the event object will include grid things like which cell was clicked on, etc.

···

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

Hi Mike,

From: Mike Driscoll [mailto:mike@pythonlibrary.org]
Sent: Monday, March 02, 2009 18:11
To: wxpython-users@lists.wxwidgets.org
Subject: Re: [wxpython-users] Update:
EVT_CONTEXT_MENU/EVT_RIGHT_UP behave differently on selected
grid cells

Barak, Ron wrote:

Hi,

I have a strange problem on a wx.Grid: it processes an
EVT_CONTEXT_MENU when /one cell is selected/, but not when
/more than
one/ is.

A demo program, sample_grid_test.py is attached.
The demo imports another module, Clipboard.py, also attached.

Basically, the TestFrame class - as a descendant of
Clipboard.CopyAndPaste, is able to create a PopUp menu
(lines 52-55 in
Clipboard.py).
But, for reasons I don’t understand, this event is fired/processed
only if just one grid cell is selected.

Anyone has an idea ?

Bye,
Ron.

An update: After reading of InspectionTool class, I used it to see
which events I might use besides EVT_CONTEXT_MENU.
EVT_RIGHT_UP seemed like a promising candidate, but - as with
EVT_CONTEXT_MENU, it does not fire when more than one grid cell is
selected.

Maybe you’re looking for wx.grid.EVT_GRID_RANGE_SELECT ?
I’m not sure I understand you.
Say, on Windows, I right-click on a grid cell, I want the popup menu to appear whether there’s one cell selected or more than one cell selected.
Actually, the popup menu does not appear when no cell is selected at all.

BTW, when the underlying widget for CopyAndPaste is a ListBox instead of a Grid, a right-click always works, no matter how many lines are selected, or even if no lines are selected at all.

Using EventWatcher, I see that when I right-click on a non-selected grid cell, the following event are produced:

But, when I click a single selected cell, events 1-15 are produced (line 9 is of interest).

For comparison sake, when the underlying widget is ListCtrl, a right click produces events 227-229, regardless if a line is selected or not:

So, seems there’s some hidden mistake in my attached programs, that makes EVT_CONTEXT_MENU be fired only if exactly one grid cell is chosen ?!

Bye,
Ron.

sample_grid_test.py (1.44 KB)

Clipboard.py (4.59 KB)

···

-----Original Message-----


Mike Driscoll

Blog: http://blog.pythonlibrary.org
Python Extension Building Network: http://www.pythonlibrary.org

Hi Robin,

From: Robin Dunn [mailto:robin@alldunn.com]
Sent: Tuesday, March 03, 2009 03:45
To: wxpython-users@lists.wxwidgets.org
Subject: Re: [wxpython-users] Update:
EVT_CONTEXT_MENU/EVT_RIGHT_UP behave differently on selected
grid cells

Barak, Ron wrote:
> Hi,
>
> I have a strange problem on a wx.Grid: it processes an
> EVT_CONTEXT_MENU when /one cell is selected/, but not when
/more than one/ is.
>
> A demo program, sample_grid_test.py is attached.
> The demo imports another module, Clipboard.py, also attached.
>
> Basically, the TestFrame class - as a descendant of
> Clipboard.CopyAndPaste, is able to create a PopUp menu
(lines 52-55 in
> Clipboard.py).
> But, for reasons I don't understand, this event is fired/processed
> only if just one grid cell is selected.
>
> Anyone has an idea ?

Thanks for the solution. Now I get my popup menu every time :wink:

The grid window (the embedded window that shows the cells) is
capturing various mouse events in it's own event handlers,
and that is interfering with the sending of the
EVT_CONTEXT_MENU. (It is normally sent by the system only
when the other right-mouse button events are not handled.)
You'll probably notice that if you press the Windows menu key

Took me a while to find what is the "Windows menu key" and where it is on my laptop (never used this key before),
but, indeed it brings the popup.

Is there a document somewhere explaining the reasons for grid not sending unprocessed events with a Skip() ?
Or am I completely misunderstanding the issue ?

Bye,
Ron.

···

-----Original Message-----

on the keyboard then you'll get the context menu even every time.

>
> An update: After reading of InspectionTool class, I used it to see
> which events I might use besides EVT_CONTEXT_MENU.
> EVT_RIGHT_UP seemed like a promising candidate, but - as with
> EVT_CONTEXT_MENU, it does not fire when more than one grid
cell is selected.

Try using the EVT_GRID_CELL_RIGHT_CLICK event instead. It is
sent by the grid and the event object will include grid
things like which cell was clicked on, etc.

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

Hi,

Robin resolved the issue with his answer:

The grid window (the embedded window that shows the cells) is capturing various mouse events in it’s own event handlers, and that is interfering with the sending of the EVT_CONTEXT_MENU. (It is normally sent by the system only when the other right-mouse button events are not handled.) You’ll probably notice that if you press the Windows menu key on the keyboard then you’ll get the context menu even every time.

Try using the EVT_GRID_CELL_RIGHT_CLICK event instead. It is sent by the grid and the event object will include grid things like which cell was clicked on, etc.

Bye,
Ron.

···

From: Barak, Ron [mailto:Ron.Barak@lsi.com]
Sent: Tuesday, March 03, 2009 11:52
To:
wxpython-users@lists.wxwidgets.org
Subject: RE: [wxpython-users] Update: EVT_CONTEXT_MENU/EVT_RIGHT_UP behave differently on selected grid cells

Hi Mike,

-----Original Message-----
From: Mike Driscoll [mailto:mike@pythonlibrary.org]
Sent: Monday, March 02, 2009 18:11
To: wxpython-users@lists.wxwidgets.org
Subject: Re: [wxpython-users] Update:
EVT_CONTEXT_MENU/EVT_RIGHT_UP behave differently on selected
grid cells

Barak, Ron wrote:

Hi,

I have a strange problem on a wx.Grid: it processes an
EVT_CONTEXT_MENU when /one cell is selected/, but not when
/more than
one/ is.

A demo program, sample_grid_test.py is attached.
The demo imports another module, Clipboard.py, also attached.

Basically, the TestFrame class - as a descendant of
Clipboard.CopyAndPaste, is able to create a PopUp menu
(lines 52-55 in
Clipboard.py).
But, for reasons I don’t understand, this event is fired/processed
only if just one grid cell is selected.

Anyone has an idea ?

Bye,
Ron.

An update: After reading of InspectionTool class, I used it to see
which events I might use besides EVT_CONTEXT_MENU.
EVT_RIGHT_UP seemed like a promising candidate, but - as with
EVT_CONTEXT_MENU, it does not fire when more than one grid cell is
selected.

Maybe you’re looking for wx.grid.EVT_GRID_RANGE_SELECT ?
I’m not sure I understand you.
Say, on Windows, I right-click on a grid cell, I want the popup menu to appear whether there’s one cell selected or more than one cell selected.
Actually, the popup menu does not appear when no cell is selected at all.

BTW, when the underlying widget for CopyAndPaste is a ListBox instead of a Grid, a right-click always works, no matter how many lines are selected, or even if no lines are selected at all.

Using EventWatcher, I see that when I right-click on a non-selected grid cell, the following event are produced:

But, when I click a single selected cell, events 1-15 are produced (line 9 is of interest).

For comparison sake, when the underlying widget is ListCtrl, a right click produces events 227-229, regardless if a line is selected or not:

So, seems there’s some hidden mistake in my attached programs, that makes EVT_CONTEXT_MENU be fired only if exactly one grid cell is chosen ?!

Bye,
Ron.


Mike Driscoll

Blog: http://blog.pythonlibrary.org
Python Extension Building Network: http://www.pythonlibrary.org

Barak, Ron wrote:

Is there a document somewhere explaining the reasons for grid not sending unprocessed events with a Skip() ?

Well, strictly speaking they are not unprocessed. The grid will at least remove any active cell editor and it will send the grid events corresponding to the right mouse button events.

···

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