How to get only one event on mouse double click ?

Hi,

In the below code, if I double click with the mouse in a grid's cell,
I get:

on_grid_selected_cell
on_grid_cell_left_dclick

Is there something I could change in the code to get only
"on_grid_cell_left_dclick" ?

Thanks,
Ron.

···

--------------------------------------------------------------------------------------------------------------------------
#!/usr/bin/env python

import wx
import wx.grid

def on_grid_cell_left_dclick(evt):
    print "on_grid_cell_left_dclick"
    evt.Skip()

def on_grid_selected_cell(evt):
    print "on_grid_selected_cell"
    evt.Skip()

app = wx.PySimpleApp()

f = wx.Frame(None, -1, "")
p = wx.Panel(f, -1)
s = wx.BoxSizer(wx.VERTICAL)

g = wx.grid.Grid(p, -1)
g.CreateGrid(2, 2)
s.Add(g, 1, wx.EXPAND)

g.Bind(wx.grid.EVT_GRID_SELECT_CELL, on_grid_selected_cell)
g.Bind(wx.grid.EVT_GRID_CELL_LEFT_DCLICK , on_grid_cell_left_dclick)

p.SetSizer(s)
f.Show()

app.MainLoop()

Hi,

···

On Feb 2, 9:00 am, Ron Barak <wxpython-users.comve...@9ox.net> wrote:

Hi,

In the below code, if I double click with the mouse in a grid's cell,
I get:

on_grid_selected_cell
on_grid_cell_left_dclick

Is there something I could change in the code to get only
"on_grid_cell_left_dclick" ?

Thanks,
Ron.
--------------------------------------------------------------------------------------------------------------------------
#!/usr/bin/env python

import wx
import wx.grid

def on_grid_cell_left_dclick(evt):
print "on_grid_cell_left_dclick"
evt.Skip()

def on_grid_selected_cell(evt):
print "on_grid_selected_cell"
evt.Skip()

app = wx.PySimpleApp()

f = wx.Frame(None, -1, "")
p = wx.Panel(f, -1)
s = wx.BoxSizer(wx.VERTICAL)

g = wx.grid.Grid(p, -1)
g.CreateGrid(2, 2)
s.Add(g, 1, wx.EXPAND)

g.Bind(wx.grid.EVT_GRID_SELECT_CELL, on_grid_selected_cell)
g.Bind(wx.grid.EVT_GRID_CELL_LEFT_DCLICK , on_grid_cell_left_dclick)

p.SetSizer(s)
f.Show()

app.MainLoop()

At first, I couldn't get this example to work either, but then it just
started working. It looks like it works as long as you double-click on
a cell that is not already selected. If you select a cell and then
double-click that same cell, it does not work.

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

Blog: http://blog.pythonlibrary.org

PyCon 2010 Atlanta Feb 19-21 http://us.pycon.org/

There really isn't a good way to prevent the events from happening. The first click in a double click series always results in a EVT_LEFT_DOWN and EVT_LEFT_UP and then if the next click is soon enough then it results in the EVT_LEFT_DCLICK. The Grid catches these and processes them to generate its own events. There is no way to tell the system to not send the events for the first click if it's going to really be a double click, because by the time it knows that it will be too late.

···

On 2/2/10 7:00 AM, Ron Barak wrote:

Hi,

In the below code, if I double click with the mouse in a grid's cell,
I get:

on_grid_selected_cell
on_grid_cell_left_dclick

Is there something I could change in the code to get only
"on_grid_cell_left_dclick" ?

--
Robin Dunn
Software Craftsman

Thanks Robin.

On a slight tangent: Is there a way to simulate a mouse DCLICK ?
Following examples on the web, I produced:

                        clickEvent = wx.CommandEvent
(wx.grid.EVT_GRID_LABEL_LEFT_DCLICK, self.table.GetId())
                        self.this_pane.ProcessEvent(clickEvent)

But, I get the complaint:

Traceback (most recent call last):
  File "svm_ts_tool_in_progress.py", line 515, in OnSelectCell
    clickEvent = wx.CommandEvent(wx.grid.EVT_GRID_LABEL_LEFT_DCLICK,
self.table.GetId())
  File "c:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py",
line 4560, in __init__
    _core_.CommandEvent_swiginit(self,_core_.new_CommandEvent(*args,
**kwargs))
TypeError: in method 'new_CommandEvent', expected argument 1 of type
'wxEventType'

Could you suggest what should I change ?

Thanks,
Ron.

···

On Feb 3, 3:17 am, Robin Dunn <ro...@alldunn.com> wrote:

On 2/2/10 7:00 AM, Ron Barak wrote:

> Hi,

> In the below code, if I double click with the mouse in a grid's cell,
> I get:

> on_grid_selected_cell
> on_grid_cell_left_dclick

> Is there something I could change in the code to get only
> "on_grid_cell_left_dclick" ?

There really isn't a good way to prevent the events from happening. The
first click in a double click series always results in a EVT_LEFT_DOWN
and EVT_LEFT_UP and then if the next click is soon enough then it
results in the EVT_LEFT_DCLICK. The Grid catches these and processes
them to generate its own events. There is no way to tell the system to
not send the events for the first click if it's going to really be a
double click, because by the time it knows that it will be too late.

--
Robin Dunn
Software Craftsmanhttp://wxPython.org

There are two problems. The noticeable one is that you are passing the wrong thing for the eventType. Try using wx.grid.EVT_GRID_LABEL_LEFT_DCLICK.typeId.

The second problem is that I think you are using the wrong event class. It's probably a wx.grid.GirdEvent. Check what is being passed to your event handler to be sure.

···

On 2/3/10 3:45 AM, Ron Barak wrote:

On a slight tangent: Is there a way to simulate a mouse DCLICK ?
Following examples on the web, I produced:

                         clickEvent = wx.CommandEvent
(wx.grid.EVT_GRID_LABEL_LEFT_DCLICK, self.table.GetId())
                         self.this_pane.ProcessEvent(clickEvent)

But, I get the complaint:

Traceback (most recent call last):
   File "svm_ts_tool_in_progress.py", line 515, in OnSelectCell
     clickEvent = wx.CommandEvent(wx.grid.EVT_GRID_LABEL_LEFT_DCLICK,
self.table.GetId())
   File "c:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py",
line 4560, in __init__
     _core_.CommandEvent_swiginit(self,_core_.new_CommandEvent(*args,
**kwargs))
TypeError: in method 'new_CommandEvent', expected argument 1 of type
'wxEventType'

Could you suggest what should I change ?

--
Robin Dunn
Software Craftsman

I'm pretty sure Robin meant wx.grid.GridEvent, not GirdEvent...

···

On Feb 3, 3:04 pm, Robin Dunn <ro...@alldunn.com> wrote:

On 2/3/10 3:45 AM, Ron Barak wrote:

> On a slight tangent: Is there a way to simulate a mouse DCLICK ?
> Following examples on the web, I produced:

> clickEvent = wx.CommandEvent
> (wx.grid.EVT_GRID_LABEL_LEFT_DCLICK, self.table.GetId())
> self.this_pane.ProcessEvent(clickEvent)

> But, I get the complaint:

> Traceback (most recent call last):
> File "svm_ts_tool_in_progress.py", line 515, in OnSelectCell
> clickEvent = wx.CommandEvent(wx.grid.EVT_GRID_LABEL_LEFT_DCLICK,
> self.table.GetId())
> File "c:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py",
> line 4560, in __init__
> _core_.CommandEvent_swiginit(self,_core_.new_CommandEvent(*args,
> **kwargs))
> TypeError: in method 'new_CommandEvent', expected argument 1 of type
> 'wxEventType'

> Could you suggest what should I change ?

There are two problems. The noticeable one is that you are passing the
wrong thing for the eventType. Try using
wx.grid.EVT_GRID_LABEL_LEFT_DCLICK.typeId.

The second problem is that I think you are using the wrong event class.
It's probably a wx.grid.GirdEvent. Check what is being passed to your
event handler to be sure.

--
Robin Dunn
Software Craftsmanhttp://wxPython.org

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

Blog: http://blog.pythonlibrary.org

PyCon 2010 Atlanta Feb 19-21 http://us.pycon.org/