treeview / pygtk problem

A

Andre Lerche

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
 
T

Tim Gerla

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
(e-mail address removed)
 
A

Andre Lerche

Hi Tim,

Tim Gerla said:
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
(e-mail address removed)

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

Thanks,

Andre
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top