When using wx.MODERN in fonts for wx.StaticText on Mac (Python 2.6, wxPython 2.8.9.1, OS 10.5.6), the text is not wrapped properly. It appears to be fixing the width of the text widget regardless of how I call the Wrap() method, and thus wrapping lines above a certain length whether I want it to or not. This behavior is not observed when using wx.SWISS. Is there any way to get around this without explicitly providing a size for the widget? (It’s working the way it should on Linux, by the way.)
Here is the sample app:
···
import wx
txt1 = “”"This is a test of monospace text formatting. Newlines will be translated
but wrapping will not be applied.
“”"
txt2 = “”"This is a test of regular text formatting. No newlines here, so this line should \
just keep going forever and expanding the frame as necessary unless Wrap() is applied. Blah blah \
blah blah blah blah blah blah blah blah. . ."""
class MyFrame (wx.Frame) :
def init (self) :
wx.Frame.init(self, None, -1, “Test frame”, size=(720,400))
panel = wx.Panel(self, -1)
szr = wx.BoxSizer(wx.VERTICAL)
panel.SetSizer(szr)
unwrapped
txt1_widget = wx.StaticText(panel, -1, txt1)
txt1_widget.SetFont(wx.Font(12, wx.MODERN, wx.NORMAL, wx.NORMAL))
txt2_widget = wx.StaticText(panel, -1, txt2)
txt2_widget.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.NORMAL))
szr.Add(txt1_widget, 0, wx.ALL, 5)
szr.Add(txt2_widget, 0, wx.ALL, 5)
now with Wrap()
txt3_widget = wx.StaticText(panel, -1, txt1)
txt3_widget.SetFont(wx.Font(12, wx.MODERN, wx.NORMAL, wx.NORMAL))
txt3_widget.Wrap(680)
txt4_widget = wx.StaticText(panel, -1, txt2)
txt4_widget.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.NORMAL))
txt4_widget.Wrap(680)
szr.Add(txt3_widget, 0, wx.ALL, 5)
szr.Add(txt4_widget, 0, wx.ALL, 5)
szr.Fit(panel)
self.Fit()
a = wx.App(0)
f = MyFrame()
f.Show()
a.MainLoop()
And here is the output:
http://cci.lbl.gov/~nat/img/wrapping.png
thanks,
Nat