Skip to content Skip to sidebar Skip to footer

How To Make Column Editable For Particular Child In Pygtk

In below picture you can see the 3 parent child window. actually I made one code which will show all child according to parent. that is showing correctly but i want username &

Solution 1:

The answer here is similar to the answer to your previous question: you need to extend your tree store with an additional column that specifies the attribute you care about — in this case, editability of username/password cells for a particular row, and connect that store column with the tree view columns that display and edit the username and password.

The provided code simply sets the editable property to true, which means the property is editable everywhere.

There are tutorials that explain the GTK tree view in some detail. Here is a version of the code from the question, modified to match your requirements as I understood them.

#!/usr/bin/env pythonimport pygtk
pygtk.require('2.0')
import gtk, gobject
import os
import cairo, gio, pango, pangocairo, atk

classBasicTreeViewExample:

    # close the window and quitdefdelete_event(self, widget, event, data=None):
        gtk.main_quit()
        returnFalsedefcol1_toggled_cb( self, cell, path, model ):
        model[path][1] = not model[path][1]

    defon_cell_edited(self, cell, path_string, new_text, model):
        print"hi"#cell.set_property('editable', False)iter = model.get_iter_from_string(new_text)
        path = model.get_path(iter)[0]
        column = cell.get_data("username")

    def__init__(self):
        # Create a new window
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)

        self.window.set_title("Basic TreeView Example")

        self.window.set_size_request(400, 400)

        self.window.connect("delete_event", self.delete_event)
        self.treestore = gtk.TreeStore(gobject.TYPE_STRING, gobject.TYPE_BOOLEAN,gobject.TYPE_BOOLEAN, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_BOOLEAN)
        for parent inrange(2):
            piter = self.treestore.append(None, ['Computer %i' % parent, False,False, '', '', False])
            pit = self.treestore.append(piter, ['Drive', False,False, '', '', False])
            pith = self.treestore.append(piter, ['Database', False,False, 'user', 'psw', True])
            for child inrange(2):
                self.treestore.append(pit, ['child', True,True, '', '', False])
            for child inrange(2):
                self.treestore.append(pith, ['child', True,True, '', '', False])
        self.treeview = gtk.TreeView(self.treestore)

        self.cell = gtk.CellRendererText()
        self.tvcolumn = gtk.TreeViewColumn("Computer Name", self.cell, text=0)
        self.cell.set_property( 'editable', False )

        self.cell0 = gtk.CellRendererToggle()
        self.tvcolumn0 = gtk.TreeViewColumn("Select Drive", self.cell0 , active=1, visible=2)
        self.cell0.set_property('activatable', True)
        self.cell0.connect( 'toggled', self.col1_toggled_cb, self.treestore )

        self.cell1 = gtk.CellRendererText()
        self.tvcolumn1 = gtk.TreeViewColumn("username", self.cell1, text=3, visible=5, editable=5)
        self.cell1.connect("editing-started", self.on_cell_edited, self.treestore)

        self.cell2 = gtk.CellRendererText()
        self.tvcolumn2 = gtk.TreeViewColumn("password", self.cell2, text=4, visible=5, editable=5)
        self.treeview.append_column(self.tvcolumn)
        self.treeview.append_column(self.tvcolumn0)
        self.treeview.append_column(self.tvcolumn1)
        self.treeview.append_column(self.tvcolumn2)
        self.treeview.set_reorderable(True)
        self.window.add(self.treeview)
        self.window.show_all()

defmain():
    gtk.main()

if __name__ == "__main__":
    tvexample = BasicTreeViewExample()
    main()

Post a Comment for "How To Make Column Editable For Particular Child In Pygtk"