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.
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.
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:
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:
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!