StaticText with wrap, how to have it autosize?

1,113 views
Skip to first unread message

Gabriel Rossetti

unread,
Nov 19, 2009, 9:08:28 AM11/19/09
to wxpytho...@googlegroups.com
Hello everyone,

I am trying to use toasterboxes and I ran into a problem. I added an ico
and static text with wrap, but it doesn't autosize.
What I mean by autosize is that depending on the text's length, I get a
certain amount of lines (since it wraps). I'd like the toasterbox's size
to adjust (at least it's height ). To add to the problem, the size
depends on the system's font. If I don't change the size, the extra text
gets cut off. Does anyone know how to do this?

Thank you,
Gabriel

Mike Driscoll

unread,
Nov 19, 2009, 11:13:48 AM11/19/09
to wxPython-users
Hi Gabriel,

On Nov 19, 8:08 am, Gabriel Rossetti <gabriel.rosse...@arimaz.com>
wrote:
Did you put the widget in a sizer?

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org

Gabriel Rossetti

unread,
Nov 23, 2009, 3:02:04 AM11/23/09
to wxpytho...@googlegroups.com

Yes, a horizontal box sizer, here's the code :

def createToasterBox(message, logo, parent=None):
from wx.lib.agw import toasterbox
tb = toasterbox.ToasterBox(parent, toasterbox.TB_COMPLEX,
toasterbox.DEFAULT_TB_STYLE, toasterbox.TB_ONTIME)
#tb.SetPopupSize((200, 75))
xSize, ySize = wx.DisplaySize()
tb.SetPopupPosition((xSize-230, ySize-112))
tb.SetPopupPauseTime(7000)
tb.SetPopupScrollSpeed(2)

tbpanel = tb.GetToasterBoxWindow()
panel = wx.Panel(tbpanel, wx.ID_ANY)

sizer = wx.BoxSizer(wx.HORIZONTAL)
stbmp = wx.StaticBitmap(panel, wx.ID_ANY, logo)
sizer.Add(stbmp, border=10, flag=wx.EXPAND|wx.ALL)

message = wx.StaticText(panel, wx.ID_ANY, message)
message.Wrap(150)
sizer.Add(message, border=10, flag=wx.EXPAND|wx.TOP)

sizer.Layout()
panel.SetSizer(sizer)

tb.AddPanel(panel)

tb.Play()


I tried as you can see to also not set the size myself by commenting :
"tb.SetPopupSize((200, 75))", but that doesn't fix the problem.

Cheers,
Gabriel

Mike Driscoll

unread,
Nov 23, 2009, 10:58:33 AM11/23/09
to wxPython-users
Hi,

On Nov 23, 2:02 am, Gabriel Rossetti <gabriel.rosse...@arimaz.com>
You can probably use the wordwrap module:

http://www.wxpython.org/docs/api/wx.lib.wordwrap-module.html

You will also need to do a little math yourself. On resize, figure out
the width (or whatever) and then re-wrap the text.

You could also put the text in a multiline TextCtrl (mess with the
styles to make it borderless and read-only or whatever), which would
do all this for you, although it always shows a vertical scrollbar.
Reply all
Reply to author
Forward
0 new messages