I ended up defining this as shown below:

class LabelValue(HorizontalPanel):


    def __init__(self, label, value, label_style = 'label', value_style = 
'value', own_style = None):
        HorizontalPanel.__init__(self, HorizontalAlignment = HasAlignment.
ALIGN_LEFT, VerticalAlignment = HasAlignment.ALIGN_MIDDLE)
        label = MyHTML(label, label_style)
        self.value = MyHTML(value, value_style)
        self.add(label)
        self.add(self.value)
        if own_style: self.setStyleName(own_style)


    def update(self, value):
        self.value.setText(value)


The idea being that I want a different style for the label and for the 
value, and that I want to change the value now and then.
For the time being it is serving my purposes, but this is my first 
"personal widget", so please let me know if I am doing something terribly 
stupid.

Thanks,
Daniel

On Tuesday, June 19, 2012 2:29:01 PM UTC+2, Jim Washington wrote:
>
> On Mon, 2012-06-18 at 14:44 -0700, Daniel Gonzalez wrote: 
> > Hi, 
> > 
> > 
> > I am trying to define my first simple widget, but I am not 
> > suceeding.What I am trying to define is a widget for a Label/Value 
> > pair. Label and Value must have configurable style names, so that text 
> > size, color, etc can be defined independently in the CSS. And they 
> > must be horizontally next to each other, with label placed before 
> > value. 
> > 
> > 
> > I have tried several implementation without success. It is not clear 
> > for me from which base class I should derive my widget. Directly from 
> > Widget? My first idea was to use two different DIVs, one for label and 
> > one for value, but I do not know how to add two DOM elements to a 
> > widget. 
>
> The base widget for a custom widget is usually ComplexPanel. It has the 
> methods and infrastructure for managing (adding and removing) child DOM 
> elements. You still have to use DOM methods, but despite the name, it 
> removes some of the complexities. Grep through the ui folder for 
> examples of how ComplexPanel is used. 
>
> - Jim Washington 
>
>
>
>
>
>

Reply via email to