Can someone please explain why it is not possible to select the first child
row in the attached program, although there is no problem selecting the
other child rows.
-- 
Jeffrey Barish
# This test selects particular rows identified by looking at their row.path.
# The select_path statement does not work after testing row.path for equality
# with (8, 0).

import gtk

class SelectRowsTestApp(object):
    def __init__(self):
        self.window = gtk.Window()
        self.window.set_size_request(200, 500)
        self.window.connect("destroy", gtk.main_quit)

        treestore = gtk.TreeStore(str)
        for i in range(9):
            treeiter = treestore.append(None, ["Row %d" % i])
        treestore.append(treeiter, ["Subrow (8, 0)"])
        treestore.append(treeiter, ["Subrow (8, 1)"])
        treestore.append(treeiter, ["Subrow (8, 2)"])
        treestore.append(None, ["Row 9"])

        treeview = gtk.TreeView(treestore)
        cell = gtk.CellRendererText()
        col = gtk.TreeViewColumn('Text', cell, text=0)
        treeview.append_column(col)
        treesel = treeview.get_selection()
        treesel.set_mode(gtk.SELECTION_MULTIPLE)

        self.window.add(treeview)
        self.window.show_all()

        def select(rows):
            for row in rows:
                if row[0] in ['Subrow (8, 0)', 'Subrow (8, 1)', 'Subrow (8, 2)']:
                    if row.path == (8, 0):
                        print "selecting (8, 0)"
                        # I get the message above, so I know that I enter this
                        # clause, but no select_path statement is effective.
                        treesel.select_path((8, 0))
                        #treesel.select_path((8, 1))
                    # But selection works fine after a test for any other row.
                    if row.path == (8, 1):
                        print "selecting (8, 1)"
                        # Selecting a path works fine here, even (8, 0).
                        #treesel.select_path((8, 0))
                        treesel.select_path((8, 1))
                    if row.path == (8, 2):
                        print "selecting (8, 2)"
                        treesel.select_path((8, 2))
                    treeview.expand_row(row.parent.path, False)
                select(row.iterchildren())
        select(treestore)

    def run(self):
        self.window.show_all()
        gtk.main()

app = SelectRowsTestApp()
app.run()
_______________________________________________
pygtk mailing list   [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to