how to insert a newline in a multiline grid cell ?

hello,

how to insert a newline in a multiline grid cell ?

On the internet I found, that ctrl-Enter should work,

after setting

self.SetDefaultEditor(wx.grid.GridCellAutoWrapStringEditor())

This works in the demo, but not in my application,

probably because I use a

self.Bind ( gridlib.EVT_GRID_CELL_CHANGE,     self.OnEditorChange )

I use the EVT_GRID_CELL_CHANGE to notify the
parent a change has taken place.

Now enetering a ctrl-enter, fires the EVT_GRID_CELL_CHANGE
event

and leaves the editor.

Is there an event property in the EVT_GRID_CELL_CHANGE
event,

so I can test if ctrl-Enter was pressed,

so I can Veto the event ?

thanks,

Stef Mientki

ok, I found a solution:

First of all, if the grid is the only component on a window, ctrl-enter
works, that’s why the demo works.

If there are more (focusable?) components on the window, ctrl-enter
doesn’t work.

But with the code below, even a normal Enter works (don’t ask me why)

` self.SetDefaultEditor ( wx.grid.GridCellAutoWrapStringEditor() )

self.Bind ( wx.EVT_KEY_DOWN, self._On_Key_Down )

def _On_Key_Down ( self, event ) :

if event.GetKeyCode() == wx.WXK_RETURN :

  event.EventObject.WriteText ( '\n' )

else :

  event.Skip ()

`

cheers,

Stef Mientki

···

On 15-06-2010 00:25, Stef Mientki wrote:

hello,

how to insert a newline in a multiline grid cell ?

On the internet I found, that ctrl-Enter should work,

after setting

self.SetDefaultEditor(wx.grid.GridCellAutoWrapStringEditor())

This works in the demo, but not in my application,

probably because I use a

self.Bind ( gridlib.EVT_GRID_CELL_CHANGE,     self.OnEditorChange )

I use the EVT_GRID_CELL_CHANGE to notify the
parent a change has taken place.

Now enetering a ctrl-enter, fires the EVT_GRID_CELL_CHANGE
event

and leaves the editor.

Is there an event property in the EVT_GRID_CELL_CHANGE
event,

so I can test if ctrl-Enter was pressed,

so I can Veto the event ?

thanks,

Stef Mientki

Here are some bits and pieces which might help. Sorry I don't have
time to look at this more coherently.

self.grid.SetFocus()
# http://www.nabble.com/Setting-focus-to-grid-td17920756.html
for window in self.grid.GetChildren():
    window.SetFocus()

I have had to resolve a lot of similar problems around controlling key
presses within custom grid widgets (e.g. 1) a composite textbox +
browse button control; 2) a choice box control) and you never know
what is going to be part of a cunning solution :wink:

Check out http://groups.google.com/group/wxpython-users/browse_thread/thread/d5169a1b1bbadaae?hl=en
re handling key presses in choice widgets inside grid cells

With text boxes in grids, be aware of style=wx.TE_PROCESS_ENTER

With dialogs be aware of potential role of wx.TAB_TRAVERSAL

Good luck!

···

On Jun 16, 9:37 am, Stef Mientki <stef.mien...@gmail.com> wrote:

ok, I found a solution:

First of all, if the grid is the only component on a window, ctrl-enter
works, that's why the demo works.

If there are more (focusable?) components on the window, ctrl-enter
doesn't work.
But with the code below, even a normal Enter works (don't ask me why)

self\.SetDefaultEditor \( wx\.grid\.GridCellAutoWrapStringEditor\(\) \)
self\.Bind \( wx\.EVT\_KEY\_DOWN, self\.\_On\_Key\_Down \)

def _On_Key_Down ( self, event ) :
if event.GetKeyCode() == wx.WXK_RETURN :
event.EventObject.WriteText ( '\n' )
else :
event.Skip ()

cheers,
Stef Mientki

On 15-06-2010 00:25, Stef Mientki wrote:

> hello,

> how to insert a newline in a multiline grid cell ?

> On the internet I found, that ctrl-Enter should work,
> after setting
> self.SetDefaultEditor(wx.grid.GridCellAutoWrapStringEditor())

> This works in the demo, but not in my application,
> probably because I use a

> self.Bind ( gridlib.EVT_GRID_CELL_CHANGE, self.OnEditorChange )

> I use the EVT_GRID_CELL_CHANGE to notify the parent a change has taken
> place.
> Now enetering a ctrl-enter, fires the EVT_GRID_CELL_CHANGE event
> and leaves the editor.

> Is there an event property in the EVT_GRID_CELL_CHANGE event,
> so I can test if ctrl-Enter was pressed,
> so I can Veto the event ?

> thanks,
> Stef Mientki