I want to put a block of uneditable text into a window with
scrollbars. I update the text with a SetLabel() on the StaticText
widget. The presense of a newline causes it to act badly, while no
newlines cause it to act as I would expect (but at the price of only
having a single line of text). I've tried lots of things, like Fit(),
SetSize(), more calls to SetupScrolling(), Wrap( -1 ), etc, but
nothing seems to work.
What I see when I run the program below is that the window has a
column of text as such:
A
longe
r line
of
text
doesn
't
work
out
right
if it
has a
newli
ne in
it!
And if I scroll down so that the first line (A) isn't in the window
then the blue color disappears completely.
What am I missing please?
import wx
import wx.lib.scrolledpanel as scrolled
class TestPanel(scrolled.ScrolledPanel):
def __init__(self, parent):
scrolled.ScrolledPanel.__init__(self, parent, -1)
vbox = wx.BoxSizer(wx.VERTICAL)
self.desc = wx.StaticText(self, -1, "initial" )
self.desc.SetForegroundColour("Blue")
vbox.Add(self.desc, 0, wx.ALIGN_LEFT|wx.ALL, 5)
self.SetSizer(vbox)
self.SetAutoLayout(1)
self.SetupScrolling()
app = wx.App(0)
frame = wx.Frame(None, wx.ID_ANY)
fa = TestPanel(frame)
frame.Show()
fa.desc.SetLabel( "A longer line of text doesn't work out right if it
has a newline in it!\n" )
app.MainLoop()
--
-- Schlake
-Chris
> --
> To unsubscribe, send email to wxPython-user...@googlegroups.com
> or visit http://groups.google.com/group/wxPython-users?hl=en
>
> --
> To unsubscribe, send email to wxPython-user...@googlegroups.com
> or visit http://groups.google.com/group/wxPython-users?hl=en
>
--
-- Schlake
But the column of text is wrong. I want lines of text, not a column.
What is the platform and wx version? Whether a static text
automatically wraps or not is undefined and platform dependent. On the
other hand, what is supposed to work everywhere is that it will honor
newlines in the text. Wrap() basically just inserts newlines in the
label's text.
If your intent is that the widget remains the same width as it is when
displaying the "initial" text, then you can do it like the attached
modification to your sample. If you want some other result you'll need
to explain it some more.
As for the color change, not sure what's going on there. More details
are needed.
--
Robin Dunn
Software Craftsman
http://wxPython.org
My intent is that when I update the text the window gets scrollbars as
needed to display it "as is" and obeying the newlines. For the
example I provided I'd expect there to be one long line of text. It
appears that the StaticText widget is sizing itself when initially
created based on it's label, and never resizing. I've tried lots of
things to make it resize, but none seems to work. Most, in fact,
cause it to size itself to (0,0).
All it should need is to call the scrolled panel's SetupScrolling again.
That will recalculate the virtual size of the scrolled window based on
the size that the sizer reports that it needs. However it looks like
the static text has a bug in 2.8 and/or carbon where it is not
recalculating its best size correctly when there are newlines in the
text. The attached works fine for me on a 2.9-cocoa build.
On Fri, Sep 9, 2011 at 8:21 PM, Robin Dunn <ro...@alldunn.com> wrote:
> size correctly when there are newlines in the text. The attached works fine
> for me on a 2.9-cocoa build.
--
-- Schlake
class MyClass(Class.Subclass):
def __init__(self, ...):
Class.Subclass.__init__(...)
I'd worry about MRO issues doing it that way.
Why? Class.Subclass.__init__(..) just might be different then
super(MyClass, self).__init__() in this case.
Personally I don't know enough about putting in a base like that (in a
class definition header like you have).
It was not Class.Subclass, it was module.Class.