Example #1
0
    def readInput(self):
        ok = False
        if self.type == str:
            ok, value = enterText(control=self.widget, validator=self.validator)
        elif self.type in (int, Seconds,):
            ok, value = enterNumeric(control=self.widget, validator=self.validator, current=self.store.get(self.key))
        elif self.type == NegativeSeconds:
            ok, value = enterNumeric(control=self.widget, validator=self.validator, current= str(int(self.store.get(self.key)) * -1))
            if value != '0':
                value = '-' + value
        elif self.type == bool and toolkit.isRadioButton(self.widget):
            ok, value = True, ['False', 'True'][self.widget.isSelected()]
        else:
            log.warn('readinput() not activated for type %s and widget %s with id %s' % (self.type, type(self.widget), self.widget.getId()))

        if ok:
            self.store.put(self.key, value)
            self.render() # re-render since enterNumeric(...) doesn't handle special cases like Seconds
Example #2
0
 def render(self):
     value = self.store.get(self.key)
     
     if toolkit.isButton(self.widget):
         if self.type == str:
             self.widget.setLabel(label=self.widget.getLabel(), label2=value)
         elif self.type == int:
             self.widget.setLabel(label=self.widget.getLabel(), label2=str(value))
         elif self.type == Seconds:
             self.widget.setLabel(label=self.widget.getLabel(), label2='%s seconds' % value)
         elif self.type == NegativeSeconds:
             self.widget.setLabel(label=self.widget.getLabel(), label2='%s seconds' % str(int(value) * -1))                
         else:
             raise Exception('Dont know how to handle type %s in render()' % self.type)
     elif toolkit.isRadioButton(self.widget):
         if self.type == bool:
             self.widget.setSelected(self.store.get(self.key) in ('True', 'true', '1'))
         else:
             raise Exception('Dont know how to handle type %s in render()' % self.type)
     else:
         raise Exception('Unknown widget in render(): %s with id %s' % (type(self.widget), self.widget.getId()))