[pygtk] disappearing ListStore

Viktor Ivanov v.shrike at gmail.com
Thu Apr 10 06:02:33 WST 2008


I ran into some strange behavior that I believe couldnt be right.

I start with a few items in a ListStore and a TreeView showing them.
I pack the view in a frame and pack that in my main vbox.
Display everything.
Two buttons - one removes the frame from the vbox and the other attempts to
look at the model associated with the view. The model seems to disappear
after removing the frame containing the view from the vbox. There is no
reason for this to happen. The view still exists and is accessible; dont
know why the model went away. Here's my test code for this issue:


-- import gtk, gobject

class Test(object):
    def __init__ (self):
        w =3D gtk.Window ()
        w.connect ("delete_event", gtk.main_quit)

        vbox =3D gtk.VBox ()
        w.add (vbox)

        model =3D gtk.ListStore (gobject.TYPE_STRING)
        model.insert (0, ('bar',))
        model.insert (0, ('baz',))

        self.model =3D model

        view =3D gtk.TreeView (model)
        column =3D gtk.TreeViewColumn ()
        view.append_column (column)
        cell =3D gtk.CellRendererText ()
        column.pack_start (cell, True)
        column.add_attribute (cell, 'text', 0)

        frame =3D gtk.Frame ('foo!')
        frame.add (view)
        vbox.add (frame)

        remove_btn =3D gtk.Button ('Remove')
        remove_btn.connect ('clicked', self.remove)
        vbox.pack_end (remove_btn)

        test_btn =3D gtk.Button ('Test')
        test_btn.connect ('clicked', self.test)
        vbox.pack_end (test_btn)

        self.view =3D view
        self.vbox =3D vbox
        self.w =3D w

    def main (self):
        self.w.show_all ()
        gtk.main ()

    def remove (self, *args):
            child1 =3D self.vbox.get_children () [0]
            self.vbox.remove (child1)

            print 'REMOVING'
            print self.view.get_model ()
            print 'END REMOVING'

    def test (self, *args):
        print "TESTING"
        print self.view.get_model ()
        print "END TESTING"

t =3D Test ()
t.main ()

Viktor R. Ivanov <v.shrike at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.daa.com.au/pipermail/pygtk/attachments/20080409/496c4012/at=
tachment.htm


More information about the pygtk mailing list