I have a long column of checkboxes in a panel with a sizer where the
associated text for each checkbox is of variable length. I would like
the checkbox text to wrap within the panel. This is possible with
Tkinter using WrapLength.
How would I accomplish the same thing using wxPython?
As far as I know none of the native checkboxes don't support wrapping their labels... One hack would be to use a checkbox with no label next to a wx.StaticText, but that would probably not look/act correctly for showing the focus or dealing with mouse clicks. Or you could make a generic checkbox widget that uses the wx.RendererNative to draw the various states of the checkbox in a native way, and also draws the text itself wrapping as needed or desired.
···
On 12/8/09 7:33 AM, Reckoner wrote:
Hi,
I have a long column of checkboxes in a panel with a sizer where the
associated text for each checkbox is of variable length. I would like
the checkbox text to wrap within the panel. This is possible with
Tkinter using WrapLength.
How would I accomplish the same thing using wxPython?
I have a long column of checkboxes in a panel with a sizer where the
associated text for each checkbox is of variable length. I would like
the checkbox text to wrap within the panel. This is possible with
Tkinter using WrapLength.
How would I accomplish the same thing using wxPython?
As far as I know none of the native checkboxes don't support wrapping
their labels... One hack would be to use a checkbox with no label next
to a wx.StaticText, but that would probably not look/act correctly for
showing the focus or dealing with mouse clicks. Or you could make a
generic checkbox widget that uses the wx.RendererNative to draw the
various states of the checkbox in a native way, and also draws the text
itself wrapping as needed or desired.
Or you may hack my little CustomCheckBox on the Wiki:
I looked at the CustomCheckBox per your direction, and it seems that
you can change the text height in the label for the checkbox, but I'm
not sure how you would get the line wrap that way, say, by inserting
the newline '\n' character into the string.
Any more hints?
Thanks in advance
···
On Dec 9, 1:54 pm, Andrea Gavana <andrea.gav...@gmail.com> wrote:
2009/12/9 Robin Dunn:
> On 12/8/09 7:33 AM,Reckonerwrote:
>> Hi,
>> I have a long column of checkboxes in a panel with a sizer where the
>> associated text for each checkbox is of variable length. I would like
>> the checkbox text to wrap within the panel. This is possible with
>> Tkinter using WrapLength.
>> How would I accomplish the same thing using wxPython?
> As far as I know none of the native checkboxes don't support wrapping
> their labels... One hack would be to use a checkbox with no label next
> to a wx.StaticText, but that would probably not look/act correctly for
> showing the focus or dealing with mouse clicks. Or you could make a
> generic checkbox widget that uses the wx.RendererNative to draw the
> various states of the checkbox in a native way, and also draws the text
> itself wrapping as needed or desired.
Or you may hack my little CustomCheckBox on the Wiki:
On Dec 10, 2:51 pm, Reckoner <recko...@gmail.com> wrote:
thanks for your reply.
I looked at the CustomCheckBox per your direction, and it seems that
you can change the text height in the label for the checkbox, but I'm
not sure how you would get the line wrap that way, say, by inserting
the newline '\n' character into the string.
I looked at the CustomCheckBox per your direction, and it seems that
you can change the text height in the label for the checkbox, but I'm
not sure how you would get the line wrap that way, say, by inserting
the newline '\n' character into the string.
I'm not sure if that will work in this case or not.
It will, although the textwrap module is best suited for this task.
Basically, what you should do is set up a wx.EVT_SIZE handler like
this (highly untested):
Then, in the DoGetBestSize you need to use GetMultiLineTextExtent
instead of GetTextExtent (and everywhere else too). And, in the
OnPaint method, you should either use dc.DrawLabel or multiple calls
to dc.DrawText (in a number equal to the number of lines).
thanks for your reply. wordwrap would certainly insert the
appropriate newline characters, but the main issue is getting the
newly updated string to fit into the height for the checkbox so that
it appears wrapped.
thanks again.
···
On Dec 10, 1:06 pm, Mike Driscoll <kyoso...@gmail.com> wrote:
Hi,
On Dec 10, 2:51 pm,Reckoner<recko...@gmail.com> wrote:
> thanks for your reply.
> I looked at the CustomCheckBox per your direction, and it seems that
> you can change the text height in the label for the checkbox, but I'm
> not sure how you would get the line wrap that way, say, by inserting
> the newline '\n' character into the string.