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.

A very generic gtk.TreeView base class

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:

Subclassing the generic list

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)

A little test application

Obiously, I could not finish this post without a screenshot of the exemplo above in execution.

A sample demo

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.

AddThis Social Bookmark Button

13 Responses to “Simplifying gtk.TreeView?”

  1. 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?

  2. 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

  3. 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!

  4. The icons in the last screenshot lack transparency

  5. So will this go into PyGTK? :)

  6. Sup OG
    Just checking on your site. Shoot me an email when you have a chance.

    Adam

  7. 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

  8. 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

  9. 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

  10. Hey Erik,

    I just picked up the first icon I found in my folders… ;)

    Cheers,

    Og

  11. 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

  12. where can i download this api?

  13. @Flávio, I’ll publish it very soon… promise! :)

    Cheers,

    Og

Leave a Reply

CAPTCHA Image CAPTCHA Audio
Refresh Image