[wxPython-users] wxGrid editing odds
Robin Dunn
robin at alldunn.com
Fri Mar 2 12:42:00 PST 2007
Andrea Gavana wrote:
> Hi All,
>
> I was playing with the wxPython demo, and precisely with the
> SimpleGrid demo in "Core Windows/Controls" => "Grid".
> Well, in this demo there is a cell labeled as "You can veto editing
> this cell". After I edited it and I want to close the editor, a
> question is raised:
>
> "Are you sure you wish to finish editing this cell?"
>
> Ok, this demonstrates the ability of Veto()-ing events in the Grid:
> the problem is, no matter which answer I choose (Yes or No) the editor
> is *always* closed and the editing ended (!). So, in other words,
> event.Veto() seems not to work with wx.grid.EVT_GRID_EDITOR_HIDDEN,
> unless I am missing something so obvious...
No, the obvious thing missing is in the wxGrid code:
//FIXME:add veto support
SendEvent( wxEVT_GRID_EDITOR_HIDDEN );
HideCellEditControl();
SaveEditControlValue();
> This is (maybe) slightly related to another problem I am having: I
> have a cell with a multiline text (GridCellAutoWrapStringEditor() and
> GridCellAutoWrapStringRenderer()) inside a grid. The grid is placed in
> a panel, and beside the grid there are 2 buttons. Well, I noticed that
> if I start editing the multiline cell, then the combination Ctrl+Enter
> does *not* enter a newline in the grid and allows me to continue
> editing, but it just closes the editor and move the focus to somewhere
> else (the buttons). Actually, it seems that Ctrl+Enter is used for
> navigation instead of for inserting a newline in the grid. This does
> not happen if the grid is the only child of the panel/frame.
Ctrl-Enter is indeed being used as a navigation key in wxMSW, and it
looks like there are several places in the code that are ensuring that
this is always the case, (so it wouldn't be easy to disable it.) I'll
check on wx-dev to make sure I'm not missing something, but in the
meantime I'd recommend just taking charge and giving your grid editor
another way to insert a newline, such as Shift-Enter.
self.grid.Bind(wx.grid.EVT_GRID_EDITOR_CREATED,
self.OnEditorCreated)
def OnEditorCreated(self, evt):
def HandleShiftEnter(evt):
if evt.KeyCode == wx.WXK_RETURN and evt.ShiftDown():
evt.GetEventObject().WriteText('\n')
else:
evt.Skip()
# This should probably only be done for cells that are using
# the GridCellAutoWrapStringEditor but for this sample we'll
# just do it for all...
# Since the grid pushes a new wx.EvtHandler onto the control's
# event ahndler stack, Bind to the first event handler on the
# stack instead of directly to the control so we can get first
# crack at the event.
ctrlEH = evt.GetControl().GetEventHandler()
ctrlEH.Bind(wx.EVT_KEY_DOWN, HandleShiftEnter)
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!
More information about the wxpython-users
mailing list