def add(self,w,value=None): """Add a widget and associated value to the dropdown box.""" if type(w) == str: w = Label(w,cls=self.cls+".option.label") w.style.align = -1 btn = Button(w,cls=self.cls+".option") btn.connect(CLICK,self._setvalue,w) self.options.tr() self.options.add(btn) if (not self.firstOption): self.firstOption = btn if value != None: w._value = value else: w._value = w if self.value == w._value: self.top_selected.value = w self.values.append(w)
def add(self, w, value=None): """Add a widget, value item to the Select. <pre>Select.add(widget,value=None)</pre> <dl> <dt>widget<dd>Widget or string to represent the item <dt>value<dd>value for this item </dl> <strong>Example</strong> <code> w = Select() w.add("Goat") #adds a Label w.add("Goat","goat") #adds a Label with the value goat w.add(gui.Label("Cuzco"),"goat") #adds a Label with value goat </code> """ if type(w) == str: w = Label(w, cls=self.cls + ".option.label") w.style.align = -1 btn = Button(w, cls=self.cls + ".option") btn.connect(CLICK, self._setvalue, w) self.options.tr() self.options.add(btn) if (not self.firstOption): self.firstOption = btn if value != None: w._value = value else: w._value = w if self.value == w._value: self.top_selected.value = w self.values.append(w)
def __setattr__(self, k, v): mywidget = None if k == 'value': for w in self.values: if w._value == v: mywidget = w _v = self.__dict__.get(k, NOATTR) self.__dict__[k] = v if k == 'value' and _v != NOATTR and _v != v: self.send(CHANGE) self.repaint() if k == 'value': if not mywidget: mywidget = Label(" ", cls=self.cls + ".option.label") self.top_selected.value = mywidget
def __init__(self,value=None,**params): params.setdefault('cls','select') Table.__init__(self,**params) label = Label(" ",cls=self.cls+".option.label") self.top_selected = Button(label, cls=self.cls+".selected") Table.add(self,self.top_selected) #,hexpand=1,vexpand=1)#,0,0) self.top_arrow = Button(Image(self.style.arrow), cls=self.cls+".arrow") Table.add(self,self.top_arrow) #,hexpand=1,vexpand=1) #,1,0) self.options = Table(cls=self.cls+".options") self.options.connect(BLUR,self._close,None) self.options.name = "pulldown-table" self.values = [] self.value = value