[wxPython-users] Re: TextCtrl wrap length?
Robin Dunn
robin at alldunn.com
Mon May 14 18:45:44 PDT 2007
Bob Robison wrote:
> On Fri, 11 May 2007 14:32:27 -0700
> Robin Dunn <robin at alldunn.com> wrote:
>
>> Bob Robison wrote:
>>> I have a multi-line TextCtrl that is in a re-sizable window. As the
>>> window is re-sized, the text is appropriately re-wrapped. Is there
>>> anyway to determine how many characters wide the widget is at any
>>> point?
>> That depends on what text is on the line and the font being used.
>> Glyphs in proportional fonts can have (and usually do have) uneven
>> widths so a line with a lot of i's or .'s in it is going to hold a
>> lot more characters than one with a lot of W's. If you use a
>> monospaced font then you can get a close estimation by dividing the
>> width of the control by the character width for the font, but there
>> will still be some extra space used by the control for internal
>> margins, maybe the scrollbar, etc.
>>
> But it sounds like there is no way to get at anything inside the
> control that is keeping track of where the wraps are happening? I will
> be using monospaced font, and a limited number of characters. Can you
> recommend the calls to get at the width of the control (GetSize?) and
> for the characters are you recommending something like GetTextExtent?
If you're using a monspaced font then GetCharWidth will work, and you
won't have to measure the extent of everything.
>
> I also want to be able (under user control) to set a particular width
> (i.e. 37 chars, 23 chars, or whatever) and have the display show only
> that many in each row. I assume I just do the same calculations and
> then set the size with SetSize?
More or less. Expect some extra width will be needed for border size,
scrollbar if present (you can use wx.SystemSettings to get the metric
for scrollbar width) and also perhaps a few pixels for an internal
margin if the TextCtrl uses one.
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!
More information about the wxpython-users
mailing list