import pygtk import gobject pygtk.require('2.0') import gtk from sqlobject import * from sqlobject.col import * from pysqlgtk.models import SqlListModel, SqlListController from pysqlgtk.widgets import DateEntry #Setting up the connection to the database of your choice #See http://www.sqlobject.org for further documentation connection_string = "postgres://markus:rantanplan@localhost:5432/test" connection = connectionForURI(connection_string) sqlhub.processConnection = connection #Defining your tables: tables are classes, rows are instances, cols are attributes. #For every table you define a class that inherits from SQLObject. You can also #set up relations between tables. #See http://www.sqlobject.org for further documentation. class Person(SQLObject): first_name = StringCol() last_name = StringCol() date_of_birth = DateCol() class DemoApp: def __init__(self): window = gtk.Window(gtk.WINDOW_TOPLEVEL) window.connect("destroy", gtk.main_quit, "WM destroy") #With a single line we create a model that can be used with Treeviews, Controllers, etc. model = SqlListModel(Person) #We fill the model with data calling refresh() model.refresh() #Now self.controller = SqlListController(model) vbox = gtk.VBox() entry = gtk.Entry() self.controller.add_widget('first_name', entry) vbox.pack_start(entry, expand = False) entry = gtk.Entry() self.controller.add_widget('last_name', entry) vbox.pack_start(entry, expand = False) entry = DateEntry() self.controller.add_widget('date_of_birth',entry) vbox.pack_start(entry, expand = False) self.controller.reset() hbox = gtk.HBox() button = gtk.Button("<") button.connect("clicked", self.previous) hbox.pack_start(button, expand=False) button = gtk.Button(">") button.connect("clicked", self.next) hbox.pack_start(button, expand=False) vbox.pack_start(hbox) vbox.show_all() window.add(vbox) window.show_all() def previous(self, w): self.controller.previous() def next(self, w): self.controller.next() def main(self): gtk.main() if __name__ == '__main__': demo = DemoApp() demo.main()