Note that there are some explanatory texts on larger screens.

plurals
  1. POAuto wrap and newlines in wxPython grid
    primarykey
    data
    text
    <p>I want to implement a grid with the cells that have the following behaviour:</p> <ol> <li><p>cell text should be wrapped if it doesn't fit to the cell</p></li> <li><p>newlines (\n) in the cell text should be processed as well</p></li> </ol> <p>i.e. the same behaviour as in table editors like MS Excel, OO Calc, etc. when you enable the 'wrap words' option for cells.</p> <p>I'm trying to do this as follows:</p> <pre><code>import wx import wx.grid class MyGrid(wx.grid.Grid): def __init__(self, parent = None, style = wx.WANTS_CHARS): wx.grid.Grid.__init__(self, parent, -1, style = style) self.CreateGrid(10, 10) self.editor = wx.grid.GridCellAutoWrapStringEditor() self.SetDefaultEditor(self.editor) self.SetDefaultRenderer(wx.grid.GridCellAutoWrapStringRenderer()) self.SetCellValue(0, 0, "Line1\nLine2\nLine3") self.SetRowSize(0, 100) class MyFrame(wx.Frame): def __init__(self, parent = None, title = "Multiline"): wx.Frame.__init__(self, parent, -1, title) self.Bind(wx.EVT_CHAR_HOOK, self.on_frame_char_hook) panel = wx.Panel(self) vbox = wx.BoxSizer(wx.VERTICAL) panel.SetSizer(vbox) grid = MyGrid(panel) vbox.Add(grid, 1, wx.EXPAND | wx.ALL, 5) self.grid = grid btn_exit = wx.Button(panel, -1, "Exit") vbox.Add(btn_exit, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 10) #Proceed CTRL+ENTER as newline in the cell editor def on_frame_char_hook(self, event): if event.CmdDown() and event.GetKeyCode() == wx.WXK_RETURN: if self.grid.editor.IsCreated(): self.grid.editor.StartingKey(event) else: event.Skip else: event.Skip() if __name__ == "__main__": app = wx.PySimpleApp() f = MyFrame() f.Center() f.Show() app.MainLoop() </code></pre> <p>But this code doesn't work as expected - newlines processed correctly in the cell editor, but ignored in the cell renderer. If I remove the <code>self.SetDefaultRenderer(wx.grid.GridCellAutoWrapStringRenderer())</code> then newlines processed correcly both in the editor and renderer, but obviously auto wrapping in the renderer doesn't work.</p> <p>Does anybody know how to solve this?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload