wxRichTextCtrl and sizers in a Notebook

Hi Andrea,

Never mind. Garbage in and garbage out. The 40 as a width is obviously wrong. So I think the workaround will work well for me.

Thanks for the tip!

Chris

···

----- Original Message ----
From: Christopher Kampmeier <ckamps@yahoo.com>
To: wxpython-users@lists.wxwidgets.org
Sent: Monday, April 6, 2009 6:35:42 PM
Subject: Re: [wxpython-users] wxRichTextCtrl and sizers in a Notebook

Hi Andrea,

I tried the following suggested workaround, but I am seeing very large textHeight field values. In the following example, the textHeight returned is much larger than the actual multi-line text.

After I added some code to count the number of lines in the word wrapped text, I saw that the text was split into 4 lines even though the original text should fit on one line.

Original string: a short line of text...

Wordwrapped result:
a
sho
rt
line
of
text
...

width: 40
textWidth: 42
textHeight: 68
lineHeight: 17
lines: 4

So it looks like my wordwrapped result is invalid. The width passed to wordwrap was 40.

Here's an excerpt from the code:

        self.desc_value = "a short line of text..."
        print self.desc_value

        lines = self.desc_value.count('\n')
        dc = wx.ClientDC(self.overview)
        width = self.GetSize().GetWidth()
        new_text = wordwrap(self.desc_value, width, dc)
        print new_text

        textWidth, textHeight, lineHeight = dc.GetMultiLineTextExtent(new_text)
        lines = new_text.count('\n')
        print "width: ", width, "textWidth: ", textWidth, " textHeight: ", textHeight, " lineHeight: ", lineHeight, " lines: ", lines+1

        self.desc.SetValue(self.desc_value)
        self.overview_sizer.SetItemMinSize(self.desc, -1, textHeight)

Thanks,
Chris

(untested):

# In the __init__ method
wx.CallAfter(self.SetRichTextSize)

def SetRichTextSize(self):

    from wx.lib.wordwrap import wordwrap

    dc = wx.ClientDC(self.desc)
    width = self.GetClientSize().width
    new_text = wordwrap(YOUR_TEXT, width, dc)

    textWidth, textHeight, dummy = dc.GetMultiLineTextExtent(new_text)

    richtextSizer = self.desc.GetContainingSizer()
    richtextSizer.SetItemMinSize((-1, textHeight))
    self.Layout()

Or something along these lines. Not perfect, not clean, but it may work :smiley:

HTH.

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/
_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users