[wxPython] labelled text entry widget

Has anybody ever written a nice "labelled text entry" class?
I mean, the situation of having a text enty widget associated with a
static text label is quite common, yet we always need to go through the
cumbersome process of doing something like:

sizer= wxBoxSizer( wxVERTICAL )
label = wxStaticText( parent, -1, _("my label"), ... )
label.SetFont( ... )
sizer.AddWindow( label, ...)
entry = wxTextCtrl( parent,... )
sizer.AddWindow( entry, ... )
[...]
supersizer.AddSizer( sizer, 1, wxALIGN_CENTRE|wxALL, 5 )

Ridiculous amount of work for something we need every day again and again.

would be nicer just to do a

lt = wxLabelTextCtrl(...., label="my label", orientation = wxVERTICAL)
supersizer.AddWindow(ltextctrl ...)

If nobody has done it yet, I would do it.

Horst

Has anybody ever written a nice "labelled text entry" class?
I mean, the situation of having a text enty widget associated with a
static text label is quite common, yet we always need to go through the
cumbersome process of doing something like:

[cumbersome process snipped]

Agreed!

If nobody has done it yet, I would do it.

Thank's Horst. Great!

Of course, the advantage of defining the separately is that you can
get the alignment just the way you like it... You might want the
label above the text entry like this:

Spam
[________]

or before, like this:

Spam [________]

If you want several entry fields, you probably want them aligned,
not just the labels. (Proper viewing of text below required non
proportional font).

E.g. you don't want:
Name [__________]
Adress [_______________]
Phone [_________]

But rather:
Name [__________]
Adress [_______________]
Phone [_________]

Or maybe:
   Name [__________]
Adress [_______________]
  Phone [_________]

I haven't played around enough with layout to know
how difficult this is to solve so that it works
right with sizers etc.

My first thought was that one would need to have
some kind of anchor on the beginning of the entry
field to align by, but then I realized that it
might be ok just to specify a big enough width
for the label. Then it shouldn't be so bad.

I've have some clients who would probably give
comments such as wanting the label to be 0.7 mm
closer to the entry field... :frowning:

Then you have the issue of vertical alignment. My
experience is that you might have to fiddle a bit
with these things. It usually works best with
wxALIGN_CENTER_VERTICAL in my wxPython experience,
but NOT if you have a multi line entry field I guess...
But if you can make something that works well with
only single lines, it's a good start.

I guess it would be a good thing if this combo
widget would somehow encapsulate all the functionality
in the normal two-controls-and-sizer solution so
that there are good defaults, but if I want some
variation on exact label location etc, I can make
a subclass of your control and use that through out
my design. I'd love to be able to change *all* my labels
to be left aligned, bold, in a different font, or two
pixels closer to the entry control by making a change
in just one place in the code.

···

At 22:23 2002-02-12 +1100, Horst wrote:

--
Magnus Lyckå, Thinkware AB
Älvans väg 99, SE-907 50 UMEÅ
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/ mailto:magnus@thinkware.se

Of course, the advantage of defining the separately is that you can
get the alignment just the way you like it... You might want the
label above the text entry like this:

this is what I intended to achieve by the orientation=... parameter

If you want several entry fields, you probably want them aligned,
not just the labels. (Proper viewing of text below required non
proportional font).

I would do tis through a "labelsize = " parameter; if not -1, the label
would be sized to an absolute size otherwise dynamically sized.

I've have some clients who would probably give
comments such as wanting the label to be 0.7 mm
closer to the entry field... :frowning:

One could also add a placeholder ("empty space") object between label and
text control, either absolutely size or dynamically sizeable

Then you have the issue of vertical alignment. My
experience is that you might have to fiddle a bit
with these things. It usually works best with
wxALIGN_CENTER_VERTICAL in my wxPython experience,
but NOT if you have a multi line entry field I guess...
But if you can make something that works well with
only single lines, it's a good start.

I wuld use default parameters with the most common values, and then you
override these default values as needed

I guess it would be a good thing if this combo
widget would somehow encapsulate all the functionality
in the normal two-controls-and-sizer solution so
that there are good defaults, but if I want some
variation on exact label location etc, I can make
a subclass of your control and use that through out
my design. I'd love to be able to change *all* my labels
to be left aligned, bold, in a different font, or two
pixels closer to the entry control by making a change
in just one place in the code.

Right. A "styling" class with static members would probably do the trick
One could pass the styling object as parameter, and the widget would
simply query the style on redraw. That way, yu could dynamically change
style properties "groupwise" without much sweat

Horst

···

On Tuesday 12 February 2002 23:05, Magnus Lyckå wrote: