2 # vim: ts=4:sw=4:tw=78:nowrap
8 "Buy groceries": "Go to Asda after work",
9 "Do some programming": "Remember to update your software",
10 "Power up systems": "Turn on the client but leave the server",
11 "Watch some tv": "Remember to catch ER"
17 Display = DisplayModel()
19 self.mdl = Store.get_model()
20 self.view = Display.make_view( self.mdl )
28 """ The GUI class is the controller for our application """
30 # setup the main window
31 self.root = gtk.Window(type=gtk.WINDOW_TOPLEVEL)
32 self.root.set_title("CellRenderer Example")
33 self.root.connect("destroy", self.destroy_cb)
36 self.root.add(myTree.get_tree())
41 def destroy_cb(self, *kw):
42 """ Destroy callback to shutdown the app """
46 """ run is called to set off the GTK mainloop """
51 """ The model class holds the information we want to display """
53 """ Sets up and populates our gtk.TreeStore """
54 self.tree_store = gtk.TreeStore( gobject.TYPE_STRING,
55 gobject.TYPE_BOOLEAN )
56 # places the global people data into the list
57 # we form a simple tree.
58 for item in tasks.keys():
59 parent = self.tree_store.append( None, (item, None) )
60 self.tree_store.append( parent, (tasks[item],None) )
63 """ Returns the model """
65 return self.tree_store
70 """ Displays the Info_Model model in a view """
71 def make_view( self, model ):
72 """ Form a view for the Tree Model """
73 self.view = gtk.TreeView( model )
74 # setup the text cell renderer and allows these
76 self.renderer = gtk.CellRendererText()
77 self.renderer.set_property( 'editable', True )
78 self.renderer.connect( 'edited', self.col0_edited_cb, model )
80 # The toggle cellrenderer is setup and we allow it to be
81 # changed (toggled) by the user.
82 self.renderer1 = gtk.CellRendererToggle()
83 self.renderer1.set_property('activatable', True)
84 self.renderer1.connect( 'toggled', self.col1_toggled_cb, model )
86 # Connect column0 of the display with column 0 in our list model
87 # The renderer will then display whatever is in column 0 of
89 self.column0 = gtk.TreeViewColumn("Name", self.renderer, text=0)
91 # The columns active state is attached to the second column
92 # in the model. So when the model says True then the button
93 # will show as active e.g on.
94 self.column1 = gtk.TreeViewColumn("Complete", self.renderer1 )
95 self.column1.add_attribute( self.renderer1, "active", 1)
96 self.view.append_column( self.column0 )
97 self.view.append_column( self.column1 )
99 def col0_edited_cb( self, cell, path, new_text, model ):
101 Called when a text cell is edited. It puts the new text
102 in the model so that it is displayed properly.
104 print "Change '%s' to '%s'" % (model[path][0], new_text)
105 model[path][0] = new_text
107 def col1_toggled_cb( self, cell, path, model ):
109 Sets the toggled state on the toggle button to true or false.
111 model[path][1] = not model[path][1]
112 print "Toggle '%s' to: %s" % (model[path][0], model[path][1],)
115 if __name__ == '__main__':
116 myGUI = GUI_Controller()