wxGrid editing odds

Andrea Gavana andrea.gavana at gmail.com
Fri Mar 2 04:25:47 PST 2007


Hi All,

    I was playing with the wxPython demo, and precisely with the
SimpleGrid demo in "Core Windows/Controls" =3D> "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...
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.
I attach a sample that demonstrates the problem. Does anyone have a
suggestion? Thank you for your help.

This is Windows XP, Python 2.5, wxPython 2.8.1.1.

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.virgilio.it/infinity77/
-------------- next part --------------
import wx
import wx.grid

class GridFrame(wx.Frame): =


    def __init__(self, *args, **kwds):
        =

        wx.Frame.__init__(self, *args, **kwds)

        self.panel =3D wx.Panel(self)
        self.grid  =3D wx.grid.Grid(self.panel)
        self.button1 =3D wx.Button(self.panel, -1, "Button 1")
        self.button2 =3D wx.Button(self.panel, -1, "Button 2")

        self.SetProperties()
        self.DoLayout()


    def SetProperties(self):

        editor =3D wx.grid.GridCellAutoWrapStringEditor()
        renderer =3D wx.grid.GridCellAutoWrapStringRenderer()
        mlattr =3D wx.grid.GridCellAttr()
        mlattr.SetEditor(editor)
        mlattr.SetRenderer(renderer)    =


        self.grid.CreateGrid(2,1)
        self.grid.SetCellValue(0, 0, """line one here
        now on line2, which should wrap, and effectively does;
        The enter key is behaving very strangely
        no matter if Ctrl is down or not.
        """)
        self.grid.SetColAttr(0, mlattr)
        self.grid.SetRowSize(0, 96)
        self.grid.SetColSize(0, 200)


    def DoLayout(self):

        mainsizer =3D wx.BoxSizer(wx.HORIZONTAL)
        rightsizer =3D wx.BoxSizer(wx.VERTICAL)

        rightsizer.Add(self.button1, 0, wx.ALL, 10)
        rightsizer.Add(self.button2, 0, wx.ALL, 10)

        mainsizer.Add(self.grid, 1, wx.EXPAND)
        mainsizer.Add(rightsizer, 0, wx.EXPAND)

        self.panel.SetSizer(mainsizer)
        mainsizer.Layout()
        =


app =3D wx.PySimpleApp()        =

frame =3D GridFrame(None, wx.ID_ANY, "Multi-Line Cell in a grid")
frame.Show(True)
app.MainLoop()



More information about the wxpython-users mailing list