#!/usr/bin/env python
from gi.repository import Gtk
from gi.repository import GObject


tasks =  { "Live": "Die" } 

class GUI_Controller:
    def __init__(self):
        self.root = Gtk.Window()
        self.root.set_title("Bug #160990")
        self.root.connect("destroy", self.destroy_cb)
        # Get the model and attach it to the view
        self.mdl = Store.get_model()
        self.view = Display.make_view( self.mdl )
        self.root.add(self.view)
        self.root.show_all()
        return
    def destroy_cb(self, *kw):
        """ Destroy callback to shutdown the app """
        Gtk.main_quit()
        return
    def run(self):
        """ run is called to set off the GTK mainloop """
        Gtk.main()
	return	

class InfoModel:
    """ The model class holds the information we want to display """
    def __init__(self):
        """ Sets up and populates our Gtk.TreeStore """
        self.tree_store = Gtk.TreeStore( GObject.TYPE_STRING,
                                         GObject.TYPE_BOOLEAN)

        for item in tasks.keys():
            parent = self.tree_store.append( None, (item, None) )
            self.tree_store.append( parent, (tasks[item], None) )
        return
    def get_model(self):
        """ Returns the model """
        if self.tree_store:
            return self.tree_store 
        else:
            return None

class DisplayModel:
    """ Displays the Info_Model model in a view """
    def make_view( self, model ):
        """ Form a view for the Tree Model """
        self.view = Gtk.TreeView( model )
        self.renderer = Gtk.CellRendererText()
        self.renderer.set_property( 'editable', True )

        self.renderer.connect( 'editing-started', self.editingKey, model)

        self.renderer.connect( 'edited', self.col0_edited_cb, model )

        self.column0 = Gtk.TreeViewColumn("Data", self.renderer, text=0)
		
        self.view.append_column( self.column0 )
        return self.view
    def editingKey(self, cell, editable, path, model):
        print "Crash!"
        return
    def col0_edited_cb( self, cell, path, new_text, model ):
        """
        Called when a text cell is edited.  It puts the new text
        in the model so that it is displayed properly.
        """
        print "Change '%s' to '%s'" % (model[path][0], new_text)
        model[path][0] = new_text
        return

if __name__ == '__main__':
    Store = InfoModel()	
    Display = DisplayModel()
    myGUI = GUI_Controller()
    myGUI.run()

