Simplifying gtk.TreeView?
One of these days I was working on a new graphical interface for a new application in python, when I noticed something familiar. Every time I need to add a gtk.TreeView widget to one of my programs, I end up re-writing the same code, over and over again and again… so I thought:
“Why not create my own kit/widget and stop rehashing code?”
Since I had a pretty uneventfull Saturday, I ended up creating GenericList, my own abstraction of a generic grk.TreeView.
Now, every time I need to add a list to one of my programs, all I have to do is instantiate this class, “feeding” it only the layout of the columns I need. Or, subclass it:
The code for the subclass is all here (above)… Inside my code I instantiate it and then I can add, remove, etc records/rows simply calling the generic methods add(), remove(), etc, etc, as shown below:
from billlistview import BillListView as ListView
self.list = ListView()
pixbuf = gtk.gdk.pixbuf_new_from_file(‘coin.jpg’)
list = [[pixbuf, 'Verizon', '$ 49,00', '04/27/2007'],
[pixbuf, 'T-Mobile', '$ 55,99', '04/15/2007'],
[pixbuf, 'Cable', '$ 111,99', '04/15/2007']]
self.list.addList(list)
Obiously, I could not finish this post without a screenshot of the exemplo above in execution.
I still want to add a few more methods before adding it to BillReminder.
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.












April 12th, 2007 at 2:16 am
Stupid question: why not just pass a list [ ("title", gtk.CellRendererText()), ("name", gtk.CellRendererText()) ], which automatically gives you indexes, rather than a dictionary where you have to explicitly specify indexes of 0, 1, 2, etc?
April 12th, 2007 at 3:56 am
Hi there,
This is a very nice window theme you are using. May you post or send me details about it?
Thanks in advance,
Jan
April 12th, 2007 at 7:59 am
yay for clever classes! this is something i am coming up against in my java course at uni and am trying to get myself wrapped around it and seeing your examples has helped me out a bunch, thanks!
April 12th, 2007 at 11:46 am
The icons in the last screenshot lack transparency
April 12th, 2007 at 4:50 pm
So will this go into PyGTK?
April 13th, 2007 at 2:26 pm
Sup OG
Just checking on your site. Shoot me an email when you have a chance.
Adam
April 14th, 2007 at 2:29 pm
Hey Stuart, no need for an apology. The reason why I decided to implement the dictionary was so that the layout could be configured in the derived class… so to be a bit more clear, im my opinion, for the developer how to set it up. Obviously you could document the API, stating what you sugested… Do you see any advantages of one way over the other? I’m sending you an email to make sure you’ll read this.
Cheers,
Og
April 14th, 2007 at 2:31 pm
Hey Jan,
The theme is the default one used by Foresight Linux. I know you can get our wallpaper from art.gnome.org but am not sure about the theme itself. Would you like me to get it for you?
Cheers,
Og
April 14th, 2007 at 2:34 pm
Hey Nathan, how is it going buddy? How is your trip to Australia shaping up? Ping me next time you’re online so we can catch up.
Cheers,
Og
April 14th, 2007 at 2:35 pm
Hey Erik,
I just picked up the first icon I found in my folders…
Cheers,
Og
April 14th, 2007 at 2:42 pm
Hey Reinout,
Absolutely! By the way, thanks for your translations for BillReminder. I will make the official announcement for the next release soon! By the way, nice blog!
Cheers,
Og
June 11th, 2007 at 1:41 pm
where can i download this api?
June 11th, 2007 at 2:00 pm
@Flávio, I’ll publish it very soon… promise!
Cheers,
Og