I'm trying to create a full screen window in which statictextctrl with quite long label are layed out in a table, with vertical scrollbar when there are a lot of them. What I need to do is wrap the label accordingly to the width that is available to each statictextctrl (based on the number of textctrl per row and the hpad). Unfortunately, when there is a very long word, I can't make it work, the word is not wraped, even if I set explicitely the textctrl style to wx.TE_BESTWRAP
(which is default anyway, but I thought it was worth trying). Any idea how to achieve this?
import wx
import wx.lib.scrolledpanel as scrolled
class MyPanel(scrolled.ScrolledPanel):
def __init__(self, parent):
scrolled.ScrolledPanel.__init__(self, parent, -1)
## Configuring the panel
self.SetAutoLayout(1)
self.SetupScrolling()
self.SetScrollRate(1,40)
# needs to be called after main window's laytou, so its size is actually
# known and can be used to compute textctrl's width
def Build(self):
labelPerRow=7
hgap = 40
vgap = 20
label_width=int(self.GetClientSize()[0]/labelPerRow)-hgap
print("label width", label_width)
grid_sizer = wx.FlexGridSizer(labelPerRow, vgap, hgap)
self.SetSizer(grid_sizer)
i=0
for label in range(200) :
label = "very long title withaverybigwordthatdoesntfitonasinglelinesoitsquitehardtomanagewordwrap"+str(i)
title = wx.StaticText(self,
label=label,
style=wx.ALIGN_CENTRE_HORIZONTAL |
wx.TE_BESTWRAP)
title.Wrap(int(label_width))
grid_sizer.AddMany([(title)])
i = i+1
self.Layout()
class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, title="Test", style=wx.NO_BORDER)
self.Maximize(True)
frameSizer = wx.BoxSizer()
p = MyPanel(self)
frameSizer.Add(p, 1, wx.EXPAND)
self.SetSizer(frameSizer)
self.Layout()
p.Build()
app = wx.App(0)
frame = MyFrame()
frame.Show()
app.MainLoop()