Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > treeview / pygtk problem

Reply
Thread Tools

treeview / pygtk problem

 
 
Andre Lerche
Guest
Posts: n/a
 
      07-10-2003
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
 
Reply With Quote
 
 
 
 
Tim Gerla
Guest
Posts: n/a
 
      07-10-2003
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
http://www.velocityreviews.com/forums/(E-Mail Removed)


 
Reply With Quote
 
 
 
 
Andre Lerche
Guest
Posts: n/a
 
      07-11-2003
Hi Tim,

Tim Gerla <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> 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
> (E-Mail Removed)


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

Thanks,

Andre
 
Reply With Quote
 
David M. Cook
Guest
Posts: n/a
 
      07-11-2003
In article <(E-Mail Removed)> , 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
>> (E-Mail Removed)

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


Hardly; this API is quite obscure.

Dave Cook
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[pygtk] problem with TreeView + ListStore Guillermo Heizenreder Python 1 09-04-2007 02:30 PM
change keybindings for pygtk treeview Fabian Braennstroem Python 0 10-27-2006 12:21 PM
PyGTK TreeView segmentation fault on expand_all() Chris Johnson Python 0 08-07-2006 01:52 PM
pygtk, gtk.treeview and virtuallist ? manatlan Python 0 04-25-2005 08:55 PM
[PyGTK] forbid focus of TreeView columns Franck Pommereau Python 0 02-21-2005 10:02 AM



Advertisments