Ejemplo n.º 1
0
    def __init__(self, field):
        super(FieldBox, self).__init__()
        self.base_field = field
        self.lbl = gtk.Label(field.description)
        self.lbl_error = gtk.Label("")
        self.lbl_error.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse("red"))
        self.lbl_error.modify_font(pango.FontDescription("sans 8"))
        self.lbl.set_alignment(xalign=0.03, yalign=0.0)
        
        self.pack_start(self.lbl, False)
        self.pack_start(self.lbl_error, False)
        if isinstance(field, CharField):
            self.entry = gtk.Entry()
            if field.password :
                self.entry.set_visibility(False)
            self.pack_start(self.entry, False)
            self.type = "char"

            if field.signal:
                self.entry.connect(field.signal, field.callback)
            
            if not field.editable:
                self.entry.set_property("editable", False)

        elif isinstance(field, FloatField):
            self.entry = gtk.Entry()
            self.pack_start(self.entry, False)
            self.type = "float"
            
            if field.signal:
                self.entry.connect(field.signal, field.callback)

        elif isinstance(field, ChoiceField):
            # si es un combo normal
            self.cmb = gtk.combo_box_new_text()
            self.pack_start(self.cmb, False)
            self.choices = field.choices
            for choice in field.choices:
                self.cmb.append_text(choice[1])
            self.type = "combo"

            if field.signal:
                self.cmb.connect(field.signal, field.callback)

        elif isinstance(field, MultipleChoiceField):
            self.type = "multiselect"
            l = []
            self.choices = field.choices
            for choice in field.choices:
                l.append(choice[1])

            self.cmb_multiple = SelectMultiple(l)
            self.cmb_multiple.set_size_request(200, 200)
            self.pack_start(self.cmb_multiple, False)

            if field.signal:
                self.cmb_multiple.connect(field.signal, field.callback)

        elif isinstance(field, BooleanField):
            self.check = gtk.CheckButton()
            self.pack_start(self.check, False)
            
            if field.default:
                self.check.set_active(True)
            
            self.type = "check"
    
            if field.signal:
                self.check.connect(field.signal, field.callback)

        elif isinstance(field, DateField):
            self.cal = CalendarEntry()
            self.pack_start(self.cal, False)
            self.type = "date"

        elif isinstance(field, TimeField):
            self.time = TimePicker()
            self.pack_start(self.time, False)
            self.type = "time"

        elif isinstance(field, DateTimeField):
            self.datetime = DateTimeEntry()
            self.pack_start(self.datetime, False)
            self.type = "datetime"
Ejemplo n.º 2
0
class FieldBox(gtk.VBox):
    def __init__(self, field):
        super(FieldBox, self).__init__()
        self.base_field = field
        self.lbl = gtk.Label(field.description)
        self.lbl_error = gtk.Label("")
        self.lbl_error.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse("red"))
        self.lbl_error.modify_font(pango.FontDescription("sans 8"))
        self.lbl.set_alignment(xalign=0.03, yalign=0.0)
        
        self.pack_start(self.lbl, False)
        self.pack_start(self.lbl_error, False)
        if isinstance(field, CharField):
            self.entry = gtk.Entry()
            if field.password :
                self.entry.set_visibility(False)
            self.pack_start(self.entry, False)
            self.type = "char"

            if field.signal:
                self.entry.connect(field.signal, field.callback)
            
            if not field.editable:
                self.entry.set_property("editable", False)

        elif isinstance(field, FloatField):
            self.entry = gtk.Entry()
            self.pack_start(self.entry, False)
            self.type = "float"
            
            if field.signal:
                self.entry.connect(field.signal, field.callback)

        elif isinstance(field, ChoiceField):
            # si es un combo normal
            self.cmb = gtk.combo_box_new_text()
            self.pack_start(self.cmb, False)
            self.choices = field.choices
            for choice in field.choices:
                self.cmb.append_text(choice[1])
            self.type = "combo"

            if field.signal:
                self.cmb.connect(field.signal, field.callback)

        elif isinstance(field, MultipleChoiceField):
            self.type = "multiselect"
            l = []
            self.choices = field.choices
            for choice in field.choices:
                l.append(choice[1])

            self.cmb_multiple = SelectMultiple(l)
            self.cmb_multiple.set_size_request(200, 200)
            self.pack_start(self.cmb_multiple, False)

            if field.signal:
                self.cmb_multiple.connect(field.signal, field.callback)

        elif isinstance(field, BooleanField):
            self.check = gtk.CheckButton()
            self.pack_start(self.check, False)
            
            if field.default:
                self.check.set_active(True)
            
            self.type = "check"
    
            if field.signal:
                self.check.connect(field.signal, field.callback)

        elif isinstance(field, DateField):
            self.cal = CalendarEntry()
            self.pack_start(self.cal, False)
            self.type = "date"

        elif isinstance(field, TimeField):
            self.time = TimePicker()
            self.pack_start(self.time, False)
            self.type = "time"

        elif isinstance(field, DateTimeField):
            self.datetime = DateTimeEntry()
            self.pack_start(self.datetime, False)
            self.type = "datetime"

    def clear(self):
        if self.type == "char":
            self.entry.set_text("")
        elif self.type == "combo":
            self.cmb.set_active(-1)
        elif self.type == "check":
            self.check.set_active(False)
        elif self.type == "multiselect":
            self.cmb_multiple.unselect_all()
    
    def set_value(self, value):
        if self.type == "char" or self.type == "float":
            self.entry.set_text(str(value))
        elif self.type == "combo":
            for i, choice in enumerate(self.choices):
                if choice[0] == value:
                    self.cmb.set_active(i)
                    break
        elif self.type == "check":
            self.check.set_active(value)
        elif self.type == "multiselect":
            for i in value:
                self.cmb_multiple.select(i)
        elif self.type == "date":
            self.cal.set_date(value)
        elif self.type == "time":
            self.time.set_time(value)
        elif self.type == "datetime":
            self.datetime.set_datetime(value)

    def set_choices(self, choices):
        if self.type == "combo":
            self.choices = choices
            # hack... fix it
            for i in range(1000):
                try:
                    self.cmb.remove_text(i)
                except:
                    break

            for choice in choices:
                self.cmb.append_text(choice[1])
    
    def get_value(self):
        if self.type == "char":
            return self.entry.get_text()
        elif self.type == "char":
            return float(self.entry.get_text())
            
        elif self.type == "combo":
            if self.cmb.get_active() == -1:
                return None
            else:
                return self.choices[self.cmb.get_active()]
        elif self.type == "check":
            return self.check.get_active()
        
        elif self.type == "multiselect":
            return self.cmb_multiple.get_selected()
        elif self.type == "date":
            return self.cal.get_date()
        elif self.type == "time":
            return self.cal.get_time()
        elif self.type == "datetime":
            return self.datetime.get_datetime()