How to distinguish a single click from a column move with wxGrid?

Hi,

I have a wx.Grid object with column moving enabled through the
wx.lib.gridmovers library. At the same time, I have implemented column
sorting when the user clicks on the column label. The sorting is bound
to the event EVT_GRID_LABEL_LEFT_CLICK.

The problem is, when ever the user is dragging the column label, the
sorting is triggered. That's before every EVT_GRID_COL_MOVE there is
always an EVT_GRID_LABEL_LEFT_CLICK event, and I can not reasonably
distinguish a simple single grid label click from a grid column move
event.

Any suggestions?

Best Regards

···

--
Hong Yuan

大管家网上建材超市
装修装潢建材一站式购物
http://www.homemaster.cn

Yuan HOng wrote:

Hi,

I have a wx.Grid object with column moving enabled through the
wx.lib.gridmovers library. At the same time, I have implemented column
sorting when the user clicks on the column label. The sorting is bound
to the event EVT_GRID_LABEL_LEFT_CLICK.

The problem is, when ever the user is dragging the column label, the
sorting is triggered. That's before every EVT_GRID_COL_MOVE there is
always an EVT_GRID_LABEL_LEFT_CLICK event, and I can not reasonably
distinguish a simple single grid label click from a grid column move
event.

Any suggestions?

This may look like a hack, and it may not even be applicable,
but here it goes.

First, trap the LEFT_DOWN event (when mouse left button is
pressed) and record the position and/or time of the press.
Then in the LEFT_UP event, compare the position/time of the
release event with the press. If no more than a certain
amount of time has passed and/or the mouse has not moved more
than a few pixels, then you have a click. Otherwise, you have
a drag on your hands.

-yzt

···

--
"Programming is an art that fights back!"

This may look like a hack, and it may not even be applicable,
but here it goes.

First, trap the LEFT_DOWN event (when mouse left button is
pressed) and record the position and/or time of the press.
Then in the LEFT_UP event, compare the position/time of the
release event with the press. If no more than a certain
amount of time has passed and/or the mouse has not moved more
than a few pixels, then you have a click. Otherwise, you have
a drag on your hands.

-yzt

Thanks for the tip. In trying to implement as described, I found that
the LEFT_DOWN event doesn't seem to be trapped by my program.

In the __init__ method of the grid control, I have the following:

self.Bind(gridlib.EVT_GRID_LABEL_LEFT_CLICK, self.OnGridLabelLeftClick)
self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)

The function self.OnLeftDown is never called.

Is it possible that the LEFT_DOWN event is intercepted by wx.Grid and
can not come through to my application?

···

--
Hong Yuan

大管家网上建材超市
装修装潢建材一站式购物
http://www.homemaster.cn

Yuan HOng wrote:

This may look like a hack, and it may not even be applicable,
but here it goes.

First, trap the LEFT_DOWN event (when mouse left button is
pressed) and record the position and/or time of the press.
Then in the LEFT_UP event, compare the position/time of the
release event with the press. If no more than a certain
amount of time has passed and/or the mouse has not moved more
than a few pixels, then you have a click. Otherwise, you have
a drag on your hands.

-yzt

Thanks for the tip. In trying to implement as described, I found that
the LEFT_DOWN event doesn't seem to be trapped by my program.

In the __init__ method of the grid control, I have the following:

self.Bind(gridlib.EVT_GRID_LABEL_LEFT_CLICK, self.OnGridLabelLeftClick)
self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)

The function self.OnLeftDown is never called.

Is it possible that the LEFT_DOWN event is intercepted by wx.Grid and
can not come through to my application?

--
Hong Yuan

The wx.Grid does not seem to have a EVT_LEFT_DOWN or _UP.
That's the extent of my knowledge. Maybe someone else can
help both of us out?

-yzt

···

--
"Programming is an art that fights back!"

Yuan HOng wrote:

Thanks for the tip. In trying to implement as described, I found that
the LEFT_DOWN event doesn't seem to be trapped by my program.

In the __init__ method of the grid control, I have the following:

self.Bind(gridlib.EVT_GRID_LABEL_LEFT_CLICK, self.OnGridLabelLeftClick)
self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)

The function self.OnLeftDown is never called.

Is it possible that the LEFT_DOWN event is intercepted by wx.Grid and
can not come through to my application?

The Grid class is composed of several child windows, so you need to bind
the event to the window returned from grid.GetGridColLabelWindow() to
get its mouse events.

···

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