multiline text cell with wrap and enter in wx.grid?

David A. Barrett barrettd at asgard.com
Mon Feb 26 12:16:15 PST 2007


-------------- next part --------------
#!/usr/bin/env python
#
# wxpython: multiline text cell with wrap and enter in wx.grid?
#
# I would like to have a multiline text cell in a grid that
# behaves in a manner similar to a multi-line text control.
# In particular, that wraps lines to fit the cell
# and that inserts an explict line break when the return key is pressed.
#
# I've searched high and low for a way, but havn't found one published.
# Any hep would be greatly appreciated.
#
# Dave Barrett; barrettd at asgard.com  26Feb2007
#
import sys, wx, wx.grid

class MlGridFrame(wx.Frame): =

  def __init__(self, *args, **kwds):
    wx.Frame.__init__(self, *args, **kwds)
    self.grid  =3D wx.grid.Grid(self, wx.ID_ANY, size=3D(1,1))
    self.editor =3D wx.grid.GridCellAutoWrapStringEditor()
    mlattr =3D wx.grid.GridCellAttr()
    mlattr.SetEditor(self.editor)
    self.grid.CreateGrid(2,1)
    self.grid.SetCellValue(0, 0, """line one here
now on line2, which should wrap, but doesn't until selected;
Also doesn't allow the enter key =

to create a new line break.
""")
    self.grid.SetColAttr(0, mlattr)
    self.grid.SetRowSize(0, 96)
    self.grid.SetColSize(0, 200)

class App(wx.App):
  def __init__(self, redirect=3DFalse, filename=3DNone):
    wx.App.__init__(self, redirect, filename)

  def OnInit(self):
    self.frame =3D MlGridFrame(None, wx.ID_ANY, 'Multi-Line Cell in a grid')
    self.frame.Show(True)
    return 1

app =3D App(False)
app.MainLoop()


More information about the wxpython-users mailing list