[wxPython] [Bug] Grid event mappings "polluting" other grids

I've just noticed that in one of my apps, where I have a root window with a
grid and dependent windows also with grids, the root window's
EVT_GRID_CELL_LEFT_DCLICK "pollutes" the other grids if they don't define
EVT_GRID_CELL_LEFT_DCLICK themselves. That is, double-clicking on a grid in
a child window calls the parent window's handler. Since my child windows
are all editor/renderer based, I really don't want to define
EVT_GRID_CELL_LEFT_DCLICK handlers for them.

Oh, in the app, here's what the hierarchy looks like:

Frame
  Panel
    Grid -- root grid with EVT_GRID_CELL_LEFT_DCLICK
  
  Dialog
    Grid -- child grids, no DCLICK handlers

Enjoy,
Mike

A simplified test case is here (dclicking on the child dialogs should do
nothing AFAICS):

8<__________________ grid_events.py __________
import os, getopt, sys
from wxPython.wx import *
from wxPython.grid import *

class Test(wxFrame):
  def __init__( self, parent= NULL ):
    wxFrame.__init__( self, parent, -1, 'First')
    s = wxGrid( self, -1 )
    s.CreateGrid( 2,3 )
    EVT_GRID_CELL_LEFT_DCLICK( self, self.OnDClick)
  def OnDClick( self, event ):
    print 'Test', event.GetRow(), event.GetCol()
    self.frame = Test2( self )
## self.frame.Show( TRUE )
    self.frame.ShowModal( )
    
class Test2(wxDialog):
  def __init__( self, parent= NULL ):
    wxDialog.__init__( self, parent, -1, 'Second')
    s = wxGrid( self, -1, size = (300,300) )
    s.CreateGrid( 2,3 )
## EVT_GRID_CELL_LEFT_DCLICK( self, self.OnDClick)
    self.Layout()
  def OnDClick( self, event ):
    print 'Test2', event.GetRow(), event.GetCol()
    
class TestApp(wxApp):
  def OnInit(self):
    # add image handlers...
    wxImage_AddHandler(wxJPEGHandler())
    wxImage_AddHandler(wxPNGHandler())
    wxImage_AddHandler(wxGIFHandler())
    frame =Test()
    frame.Show (1)
    self.SetTopWindow(frame)
    return true

if __name__ == "__main__":
  application = TestApp(0)
  application.MainLoop ()

···

__________________________________
Mike C. Fletcher
Designer, VR Plumber
http://members.home.com/mcfletch

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/wxpython-users

I've just noticed that in one of my apps, where I have a root window with

a

grid and dependent windows also with grids, the root window's
EVT_GRID_CELL_LEFT_DCLICK "pollutes" the other grids if they don't define
EVT_GRID_CELL_LEFT_DCLICK themselves. That is, double-clicking on a grid

in

a child window calls the parent window's handler. Since my child windows
are all editor/renderer based, I really don't want to define
EVT_GRID_CELL_LEFT_DCLICK handlers for them.

I've often wondered why the EVT_GRID_* macros don't take an ID parameter.
That would solve your problem.

To work around it you can add something to your OnDClick that checks the ID
from the event with the grid's ID, like this:

        if event.GetId() == self.grid.GetId():

Or you can use self.Connect instead of EVT_GRID_CELL_LEFT_DCLICK and pass it
the grid's ID. Then your event hadnler will only get called for events from
that grid.

P.S. Please remember to send me tabless samples otherwise they look like
this when I get them:

···

class Test(wxFrame):
def __init__( self, parent= NULL ):
wxFrame.__init__( self, parent, -1, 'First')
s = wxGrid( self, -1 )
s.CreateGrid( 2,3 )
EVT_GRID_CELL_LEFT_DCLICK( self, self.OnDClick)
def OnDClick( self, event ):
print 'Test', event.GetRow(), event.GetCol()
self.frame = Test2( self )
## self.frame.Show( TRUE )
self.frame.ShowModal( )

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

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/wxpython-users