Hi folks,Has anyone written a "labeled Widget" widget?It seems to a be Very common use to need a wx.TextCtrl, or a wx.Choice, or a ??? with a label to the left or above it.I do this all the time, using a wx.StaticText and the widget, then laying them out with a wx.FlexGridSizer or whatever.However, the layout is kind of a pain, as the label and the widget are treated as different items.Anyway, I'm planing on writing a simple combined widget, but was wondering if anyone else has done this -- Andrea?If not, I'll get started on it. I'll start with something very simple, but I'll post it here, and maybe between all of us we can get something full featured some day.
···
--- On Fri 08/04, Christopher Barker < Chris.Barker@noaa.gov > wrote:
From: Christopher Barker [mailto: Chris.Barker@noaa.gov]
To: wxPython-users@lists.wxwidgets.org
Date: Fri, 04 Aug 2006 14:40:48 -0700
Subject: [wxPython-users] A "labeled widget"?
#------------------------
Here's something I put together a LOOONNNG time ago - not sure I'd do it the same way today, but...
Chris
#_______________________________________________________________________________
### convience class for label + text with label position geometry mgmt
class LabelText( wxPanel ):
def __init__( self, parent, id, txt_id, psize, tstyle = wxTE_PROCESS_ENTER, title = '', defaulttxt= '', label_pos = LP_LEFT ):
wxPanel.__init__( self, parent, id, size = psize, style = wxSIMPLE_BORDER | wxTAB_TRAVERSAL)
# weird problem that cropped up in latest wxPython - crashes
# when wxTE_MULTILINE and wxTE_PROCESS_ENTER are both set
# not so weird now - new? error msg - multiline is ALWAYS process_enter???
if not tstyle & wxTE_MULTILINE: tstyle = tstyle | wxTE_PROCESS_ENTER
# else: tstyle = tstyle | wxHSCROLL
# save reference to label and text field in class instance
self.fTxt = wxTextCtrl( self, txt_id, defaulttxt, style = tstyle )
self.fLab = wxStaticText( self, -1, ' ' + title + ' ' )
self.fTxt.SetFont(wxFont(14, wxROMAN, wxNORMAL, wxNORMAL))
if ( label_pos == LP_LEFT ) or ( label_pos == LP_RIGHT ):
self.box = wxBoxSizer( wxHORIZONTAL )
else:
self.box = wxBoxSizer( wxVERTICAL )
if ( label_pos == LP_LEFT ) or ( label_pos == LP_TOP):
self.box.Add( self.fLab, 0, wxLEFT | wxALIGN_CENTER_VERTICAL )
self.box.Add( self.fTxt, 1, wxEXPAND )
else:
self.box.Add( self.fTxt, 1, wxEXPAND )
self.box.Add( self.fLab, 0, wxLEFT | wxALIGN_CENTER_VERTICAL )
self.set_txt_bg( TxtDefaultBGColor )
self.set_lab_bg( LabelDefaultBGColor )
self.SetAutoLayout( True )
self.SetSizer( self.box )
#_______________________
def get_txt( self ):
return( self.fTxt.GetValue() )
#_______________________
def set_txt( self, txt ):
self.fTxt.SetValue( txt )
#_______________________
def set_lab( self, txt ):
self.fLab.SetValue( txt )
#_______________________
def set_lab_txt( self, labtxt, fldtxt ):
self.set_txt( fldtxt )
self.set_lab( labtxt )
#_______________________
def set_txt_bg( self, bgcolor ):
self.fTxt.SetBackgroundColour( bgcolor )
#_______________________
def set_lab_bg( self, bgcolor ):
self.fLab.SetBackgroundColour( bgcolor )
self.SetBackgroundColour( bgcolor ) # in Windows, have to set the panel color also?
# otherwise the labels show up against diff panel color
_______________________________________________
Join Excite! - http://www.excite.com
The most personalized portal on the Web!