treeview / pygtk problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andre Lerche

    treeview / pygtk problem

    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.ScrolledWindo w ()
    renderer = g.CellRendererT ext ()
    col1 = g.TreeViewColum n ("col 1", renderer, text=1)
    col2 = g.TreeViewColum n ("col 2", renderer, text=1)
    model = g.ListStore (gobject.TYPE_S TRING, gobject.TYPE_ST RING)
    view = g.TreeView ()
    view.set_model (model)
    view.set_header s_visible (1)
    view.append_col umn(col1)
    view.append_col umn(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
  • Tim Gerla

    #2
    Re: treeview / pygtk problem

    On Thu, 2003-07-10 at 11:53, Andre Lerche wrote:[color=blue]
    > 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.ScrolledWindo w ()
    > renderer = g.CellRendererT ext ()
    > col1 = g.TreeViewColum n ("col 1", renderer, text=1)
    > col2 = g.TreeViewColum n ("col 2", renderer, text=1)[/color]
    ----^
    That's your problem right there: text= expects a sequence from 0 to n.
    So try:

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

    That should solve your problem!

    -Tim
    tim@gerla.net


    Comment

    • Andre Lerche

      #3
      Re: treeview / pygtk problem

      Hi Tim,

      Tim Gerla <tim@gerla.ne t> wrote in message news:<mailman.1 057867154.11801 .python-list@python.org >...[color=blue]
      > On Thu, 2003-07-10 at 11:53, Andre Lerche wrote:[color=green]
      > > Hi list,[/color][/color]
      [...][color=blue][color=green]
      > > renderer = g.CellRendererT ext ()
      > > col1 = g.TreeViewColum n ("col 1", renderer, text=1)
      > > col2 = g.TreeViewColum n ("col 2", renderer, text=1)[/color]
      > ----^
      > That's your problem right there: text= expects a sequence from 0 to n.
      > So try:
      >
      > col1 = g.TreeViewColum n ("col 1", renderer, text=0)
      > col2 = g.TreeViewColum n ("col 2", renderer, text=1)
      >
      > That should solve your problem!
      >
      > -Tim
      > tim@gerla.net[/color]

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

      Thanks,

      Andre

      Comment

      • David M. Cook

        #4
        Re: treeview / pygtk problem

        In article <eafaf631.03071 10739.fd3aeb3@p osting.google.c om>, Andre Lerche
        wrote:
        [color=blue][color=green]
        >> col1 = g.TreeViewColum n ("col 1", renderer, text=0)
        >> col2 = g.TreeViewColum n ("col 2", renderer, text=1)
        >>
        >> That should solve your problem!
        >>
        >> -Tim
        >> tim@gerla.net[/color]
        >
        > Yes, this has solved my problem, I was really to dumb.[/color]

        Hardly; this API is quite obscure.

        Dave Cook

        Comment

        Working...