3

I have a GUI created in Glade, and I would like to populate the treeview widget. Here is the relevant part of my code

def __init__(self):
            .....
    self.fill_store()
    self.add_column(self.widget('treeview_preview'))
    self.widget('treeview_preview').set_pixbuf_column(0)

def fill_store(self):
    self.widget('liststore_preview').clear()
    foo = GdkPixbuf.Pixbuf.new_from_file('9.png')
    da = Gtk.Image.new_from_pixbuf(foo)
    self.widget('liststore_preview').append([da])

def add_column(self, treeview):
    renderer = Gtk.CellRendererPixbuf()
    column = Gtk.TreeViewColumn("Preview", renderer, pixbuf = 0)
    column.set_sort_column_id(0)    
    treeview.append_column(column)

Yet, when I try to run the code, I get an error, which informs me that renderer is not defined. The offending line is

column = Gtk.TreeViewColumn("Preview", renderer, pixbuf = 0)

Can someone point out the error? In case it helps, here is the traceback

Traceback (most recent call last):
File "test.py", line 10, in <module>
class test:
File "test.py", line 48, in test
column = Gtk.TreeViewColumn("Preview", r, pixbuf = 0)
NameError: name 'r' is not defined

Thanks,

v923z

gpoo
  • 8,408
  • 3
  • 38
  • 53
v923z
  • 1,237
  • 5
  • 15
  • 25

1 Answers1

1

Are you sure you don't have an typo like this?

>>> something = 1
>>> somthing    # typo, left out 'e'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'somthing' is not defined
Steven Rumbalski
  • 44,786
  • 9
  • 89
  • 119
  • Yes, I am quite sure. It should also be clear from my verbatim posting. But in order to make certain that it is definitely not the case, I re-named renderer as 'r', and tried the code with this modification. It still doesn't work. – v923z Nov 09 '11 at 21:36
  • I wasn't sure your code was pasted verbatim. Could you add the traceback to your question? I'll delete this answer once your question is updated. – Steven Rumbalski Nov 09 '11 at 21:38
  • Sure. I have added that to the OP. – v923z Nov 10 '11 at 07:34
  • @v923z: I'm going to double down and stick to my answer. What you are seeing has nothing to do with gtk/glade/treeview. Python is telling you that it can't make the call to `Gtk.TreeViewColumn` because one of the names you are using as an argument is not defined. Now, I agree that is not what your pasted code shows, but I dispute whether the pasted code is an accurate representation of your real code. – Steven Rumbalski Nov 10 '11 at 18:25
  • I am not sure about what you mean by "an accurate representation of code". I have pasted the code that I use, and since python in an interpreted language, I guess that that must be the code that runs in python. In fact, when I change the name from renderer to r, then python complains that r is undefined. From this the only thing I can conclude is that I am running the code that I posted here. How could it be represented more accurately? – v923z Nov 10 '11 at 19:49
  • Well, there are more lines in your traceback than in your pasted code, so there may be more to see. – Steven Rumbalski Nov 11 '11 at 02:32
  • As it turns out, the indentation was wrong. python does not complain any more about undefined symbols. (Whether the code works is a completely different matter.) Thanks for your time! – v923z Nov 11 '11 at 07:41