Oct 22 2008

TreeView and the frustration

Category: gtk,pygtk,pythonerm @ 3:47 pm

Anyone that’s ever used treeview, might understand my frustration.

I really don’t understand the reasoning behind forcing people to use cellrenders.

There are so many other ways to handle this, if I had the knowledge, this is how I’d do it.

Cells would be widgets,

class myWidget(gtk.Label):
def __init__(self,text=None):
gtk.Label.__init__(self,text)

def set_value(self,text):
self.set_text(text)

You’d create subclasses, and use them, but noooooo we’re stuck using cellrenders that have no easy way to add a widget to.  You’re stuck looking up gtk.style to “draw” things.

I don’t know but it just seems like a lot of extra steps that aren’t needed to render cells, there’s a lot of reasearch that goes into using a treeview, when subclasses could have been used.

Your main treeview would still use a liststore, but when it was time to update all it’d have to do is call obj.set_value(foo) while it was looping.  I really have no clue how all this stuff works, I just know how I’d do it if I were setting up the language.

With gtk you use pack_start() pack_end() and add() to add widgets to various other widgets like a vbox, hbox, notebooks etc.

pack_start is used for treeviews, but it has to be a subclass of a cellrenderer, and thus makes it extreamealy difficult to add things.  There are a few cellrenders for a comobox, entry, images, etc.  However what happens when you want to implement a custom widget … it’s damm near impossible without a month to a week of reasearch.

The reason being if you wanted to set up a complicated widget you could ….


class MyComplexWidget(gtk.EventBox):
def __init__(self):
gtk.EventBox.__init__(self)
vbox = gtk.VBox()
self.value = 0
self.pack_start(vbox)
self.label = gtk.Label(str(self.value))
self.connect('scroll-event',self.scroll)

def set_value(self,value):
self.value = value

def scroll(self,*args):
self.value = self.value + 1
self.label = gtk.Label(str(self.value))
self.emit('scroll-event',*args)

treeviewCol.pack_start(myComplexWidget)

Maybe it’s just me … maybe I’m an idiot, maybe the cellrenderer is exactly this, the problem is I’ve seen nill for simply adding a pre-existing widget on the web.  You have to draw *everything*

Enough of complaining, maybe someone out there will know what I’m talking about, and an easy way to set it up, or you’ll totally agree with what I’m saying.

Tags: , ,

Leave a Reply

You must be logged in to post a comment. Login now.