treeview / pygtk problem

Discussion in 'Python' started by Andre Lerche, Jul 10, 2003.

  1. Andre Lerche

    Andre Lerche Guest

    Hi list,

    I am quite new to Python and try to learn Python with a small pygtk
    program. I am facing a problem which I am unable to solve for myself.
    I think I have read the documentation and some samples, but however
    I cannot find my mistake, so hopefully someone can help me with a
    short hint. This is a small sample application which demonstrates
    my problem:

    import gtk as g
    import gobject

    window = g.Window ()
    window.connect ('delete_event', g.mainquit)
    scrolledwin = g.ScrolledWindow ()
    renderer = g.CellRendererText ()
    col1 = g.TreeViewColumn ("col 1", renderer, text=1)
    col2 = g.TreeViewColumn ("col 2", renderer, text=1)
    model = g.ListStore (gobject.TYPE_STRING, gobject.TYPE_STRING)
    view = g.TreeView ()
    view.set_model (model)
    view.set_headers_visible (1)
    view.append_column(col1)
    view.append_column(col2)

    scrolledwin.add (view)
    window.add (scrolledwin)
    window.show_all ()

    iter = model.append ()
    # -- Problem -- #
    model.set (iter, 0, "foo", 1, "bar")
    # ------------- #
    g.mainloop ()

    I thought, with the marked model.set... I can set the first row in my
    treeview to col1 = foo and col2 = bar. But, if I execute the script
    the 2 columns are set to bar.

    Where is my mistake? I am using Python 2.2.2 on RedHat 9.

    Thanks,

    Andre
    Andre Lerche, Jul 10, 2003
    #1
    1. Advertising

  2. Andre Lerche

    Tim Gerla Guest

    On Thu, 2003-07-10 at 11:53, Andre Lerche wrote:
    > Hi list,
    >
    > I am quite new to Python and try to learn Python with a small pygtk
    > program. I am facing a problem which I am unable to solve for myself.
    > I think I have read the documentation and some samples, but however
    > I cannot find my mistake, so hopefully someone can help me with a
    > short hint. This is a small sample application which demonstrates
    > my problem:
    >
    > import gtk as g
    > import gobject
    >
    > window = g.Window ()
    > window.connect ('delete_event', g.mainquit)
    > scrolledwin = g.ScrolledWindow ()
    > renderer = g.CellRendererText ()
    > col1 = g.TreeViewColumn ("col 1", renderer, text=1)
    > col2 = g.TreeViewColumn ("col 2", renderer, text=1)

    ----^
    That's your problem right there: text= expects a sequence from 0 to n.
    So try:

    col1 = g.TreeViewColumn ("col 1", renderer, text=0)
    col2 = g.TreeViewColumn ("col 2", renderer, text=1)

    That should solve your problem!

    -Tim
    Tim Gerla, Jul 10, 2003
    #2
    1. Advertising

  3. Andre Lerche

    Andre Lerche Guest

    Hi Tim,

    Tim Gerla <> wrote in message news:<>...
    > On Thu, 2003-07-10 at 11:53, Andre Lerche wrote:
    > > Hi list,

    [...]
    > > renderer = g.CellRendererText ()
    > > col1 = g.TreeViewColumn ("col 1", renderer, text=1)
    > > col2 = g.TreeViewColumn ("col 2", renderer, text=1)

    > ----^
    > That's your problem right there: text= expects a sequence from 0 to n.
    > So try:
    >
    > col1 = g.TreeViewColumn ("col 1", renderer, text=0)
    > col2 = g.TreeViewColumn ("col 2", renderer, text=1)
    >
    > That should solve your problem!
    >
    > -Tim
    >


    Yes, this has solved my problem, I was really to dumb.

    Thanks,

    Andre
    Andre Lerche, Jul 11, 2003
    #3
  4. In article <>, Andre Lerche
    wrote:

    >> col1 = g.TreeViewColumn ("col 1", renderer, text=0)
    >> col2 = g.TreeViewColumn ("col 2", renderer, text=1)
    >>
    >> That should solve your problem!
    >>
    >> -Tim
    >>

    >
    > Yes, this has solved my problem, I was really to dumb.


    Hardly; this API is quite obscure.

    Dave Cook
    David M. Cook, Jul 11, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Franck Pommereau

    [PyGTK] forbid focus of TreeView columns

    Franck Pommereau, Feb 21, 2005, in forum: Python
    Replies:
    0
    Views:
    460
    Franck Pommereau
    Feb 21, 2005
  2. manatlan
    Replies:
    0
    Views:
    421
    manatlan
    Apr 25, 2005
  3. Chris Johnson
    Replies:
    0
    Views:
    300
    Chris Johnson
    Aug 7, 2006
  4. Fabian Braennstroem

    change keybindings for pygtk treeview

    Fabian Braennstroem, Oct 27, 2006, in forum: Python
    Replies:
    0
    Views:
    291
    Fabian Braennstroem
    Oct 27, 2006
  5. Guillermo Heizenreder

    [pygtk] problem with TreeView + ListStore

    Guillermo Heizenreder, Sep 4, 2007, in forum: Python
    Replies:
    1
    Views:
    377
Loading...

Share This Page