wx.grid - opening editor with one click

Hi all,

I'm creating a wxPython app that uses wx.Grid and I need to place custom editors (wx.ComboCtrl) in one row of that grid.

The problem I'm facing now is that user needs to click once on a cell to set focus on it (outline is drawn around clicked cell) and then click again to open editor (a combo box).

My event handler, bound to EVT_GRID_CELL_LEFT_CLICK, calls grid.ShowCellEditControl() (and prints something on console, so I know that event is received), but ShowCellEditControl() seems to fail for the first click, but works after second click.

I've found its source in generic\grid.cpp and the only place it seems to be able to quit without showing anything is "if ( !IsVisible( m_currentCellCoords, false ) )".

Now my question is - how can I set 'm_currentCellCoords' from Python level? It seems like setting it to currently clicked cell and *then* calling ShowCellEditControl() will do the trick.

Any suggestions?

Kind regards,

Adam Bielanski.

Take a look at the wx.lib.mixins.grid.GridAutoEditMixin class.

···

On 6/18/12 5:55 AM, Adam Bielański wrote:

Hi all,

I'm creating a wxPython app that uses wx.Grid and I need to place custom
editors (wx.ComboCtrl) in one row of that grid.

The problem I'm facing now is that user needs to click once on a cell to
set focus on it (outline is drawn around clicked cell) and then click
again to open editor (a combo box).

My event handler, bound to EVT_GRID_CELL_LEFT_CLICK, calls
grid.ShowCellEditControl() (and prints something on console, so I know
that event is received), but ShowCellEditControl() seems to fail for the
first click, but works after second click.

I've found its source in generic\grid.cpp and the only place it seems to
be able to quit without showing anything is "if ( !IsVisible(
m_currentCellCoords, false ) )".

Now my question is - how can I set 'm_currentCellCoords' from Python
level? It seems like setting it to currently clicked cell and *then*
calling ShowCellEditControl() will do the trick.

Any suggestions?

--
Robin Dunn
Software Craftsman

Man, you're simply awesome....

I took this task from my friend here, who struggled with it for several hours. I also spent some time on it, totally unaware of such mixin.

Tested it a moment ago it looks like it works, right out of the box.

Tomorrow I'll take a closer look to see how it works :slight_smile:

Thank you very much!

Adam Bielanski.

W dniu 2012-06-18 17:15, Robin Dunn pisze:

···

On 6/18/12 5:55 AM, Adam Bielański wrote:

Hi all,

I'm creating a wxPython app that uses wx.Grid and I need to place custom
editors (wx.ComboCtrl) in one row of that grid.

The problem I'm facing now is that user needs to click once on a cell to
set focus on it (outline is drawn around clicked cell) and then click
again to open editor (a combo box).

My event handler, bound to EVT_GRID_CELL_LEFT_CLICK, calls
grid.ShowCellEditControl() (and prints something on console, so I know
that event is received), but ShowCellEditControl() seems to fail for the
first click, but works after second click.

I've found its source in generic\grid.cpp and the only place it seems to
be able to quit without showing anything is "if ( !IsVisible(
m_currentCellCoords, false ) )".

Now my question is - how can I set 'm_currentCellCoords' from Python
level? It seems like setting it to currently clicked cell and *then*
calling ShowCellEditControl() will do the trick.

Any suggestions?

Take a look at the wx.lib.mixins.grid.GridAutoEditMixin class.

I’ve found much easier sollution somewhere on Cpp-WX forums:

grid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, OnGridClicked)

def OnGridClicked(e):
e.GetEventObject().SetGridCursor(e.GetRow(), e.GetCol())
e.Skip()

Dne pondělí, 18. června 2012 14:55:08 UTC+2 Adam Bielański napsal(a):

···

Hi all,

I’m creating a wxPython app that uses wx.Grid and I need to place custom editors
(wx.ComboCtrl) in one row of that grid.

The problem I’m facing now is that user needs to click once on a cell to set
focus on it (outline is drawn around clicked cell) and then click again to open
editor (a combo box).

My event handler, bound to EVT_GRID_CELL_LEFT_CLICK, calls
grid.ShowCellEditControl() (and prints something on console, so I know that
event is received), but ShowCellEditControl() seems to fail for the first click,
but works after second click.

I’ve found its source in generic\grid.cpp and the only place it seems to be able
to quit without showing anything is “if ( !IsVisible( m_currentCellCoords, false
) )”.

Now my question is - how can I set ‘m_currentCellCoords’ from Python level? It
seems like setting it to currently clicked cell and then calling
ShowCellEditControl() will do the trick.

Any suggestions?

Kind regards,

Adam Bielanski.