Example #1
0
class PersonEditor(SlaveView):

    def create_ui(self):
        self.pane = gtk.HPaned()
        self.widget.add(self.pane)
        self.listing = PersonList()
        self.detail = PersonForm()
        self.pane.pack1(self.listing.widget)
        self.pane.pack2(self.detail.widget)

    def on_listing__item_activated(self, listing, item):
        self.detail.model = item

    def on_listing__item_changed(self, listing, item, attr, value):
        if item is self.detail.model:
            # cause an ui update
            self.detail.model = item

    def on_detail__model_updated(self, detail, attribute, value):
        self.listing.objects.update(detail.model)

    def append_item(self, item):
        self.listing.append_item(item)

if __name__ == '__main__':
    editor = PersonEditor()
    editor.append_item(Person('Ali', 'Afshar', '*****@*****.**'))
    editor.append_item(Person('Hilda', 'Afshar', '*****@*****.**'))
    run_in_window(editor)
Example #2
0
    def model_set(self):
        if self.model:
            self.firstname_entry.set_text(self.model.name)
            self.lastname_entry.set_text(self.model.surname)
            self.email_entry.set_text(self.model.email)
        else:
            self.reset()

    def on_firstname_entry__changed(self, entry):
        if self.model:
            self.model.name = entry.get_text()
            self.emit('model-updated', 'name', self.model.name)

    def on_lastname_entry__changed(self, entry):
        if self.model:
            self.model.surname = entry.get_text()
            self.emit('model-updated', 'surname', self.model.surname)

    def on_email_entry__changed(self, entry):
        if self.model:
            self.model.email = entry.get_text()
            self.emit('model-updated', 'email', self.model.email)


if __name__=='__main__':
    person = Person('hans', 'man', '*****@*****.**')
    view = PersonForm()
    view.set_model(person)
    run_in_window(view)