def body(self, frame): """ Creates the dialog body. Returns the widget that should have initial focus. """ title = Label( text = "Choose Font" ) frame.add( title ) # Font family list ---------------------------------------------------- family = ListBox() family.setMultipleSelect( False ) family.setStyleName( "color", "#ffffff" ) for family_name in families(master): family.addItem( item = family_name ) # Font size spinner --------------------------------------------------- size = TextBox() frame.add( size ) # Example text -------------------------------------------------------- example = TextArea() example.addText( "This is example text.\n" ) example.addText( "If you like this text, it can be your font." ) def on_select( event ): idx = familt.getSelectedIndex() example.setStyleName( "font", family.getValue(idx) ) example.setStyleName( "em", size.getText() ) family.addChangeListener( on_select ) return size # Given initial focus.
class Lists(Sink): def __init__(self): Sink.__init__(self) self.sStrings=[["foo0", "bar0", "baz0", "toto0", "tintin0"], ["foo1", "bar1", "baz1", "toto1", "tintin1"], ["foo2", "bar2", "baz2", "toto2", "tintin2"], ["foo3", "bar3", "baz3", "toto3", "tintin3"], ["foo4", "bar4", "baz4", "toto4", "tintin4"]] self.combo=ListBox() self.list=ListBox() self.echo=Label() self.combo.setVisibleItemCount(1) self.combo.addChangeListener(self) self.list.setVisibleItemCount(10) self.list.setMultipleSelect(True) for i in range(len(self.sStrings)): self.combo.addItem("List %d" % i) self.combo.setSelectedIndex(0) self.fillList(0) self.list.addChangeListener(self) horz = HorizontalPanel() horz.setVerticalAlignment(HasAlignment.ALIGN_TOP) horz.setSpacing(8) horz.add(self.combo) horz.add(self.list) panel = VerticalPanel() panel.setHorizontalAlignment(HasAlignment.ALIGN_LEFT) panel.add(horz) panel.add(self.echo) self.initWidget(panel) self.echoSelection() def onChange(self, sender): print "onChange", sender, self.list, self.combo if sender is self.combo: print "fill list" self.fillList(self.combo.getSelectedIndex()) elif sender is self.list: print "echo " self.echoSelection() else: print "oops" def onShow(self): pass def fillList(self, idx): self.list.clear() strings = self.sStrings[idx] for i in range(len(strings)): self.list.addItem(strings[i]) self.echoSelection() def echoSelection(self): msg = "Selected items: " print msg, self.list.getItemCount() for i in range(self.list.getItemCount()): if self.list.isItemSelected(i): msg += "%d" % i + self.list.getItemText(i) + " " self.echo.setText(msg)