Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 11-30-2006, 09:24 AM   #1
Senior Member
Registered: Dec 2003
Posts: 3,161
Blog Entries: 4

Rep: Reputation: 136Reputation: 136
Thumbs down gtk.ListStore - python - retrieving the list values?

I'm using a simple gtk.ListStore to store values for a combo box in my python/glade application

However, I'm shocked to see that there's no way to "retrieve" the contents of the ListStore programmatically. I've combed the documentation for ways to retrieve this data, but there is none. Even searching the web has left me clueless (there is a similar thread on a mailing list archive without any replies).

The reason I need to "retrieve" the combo box items is because I am allowing the user to add and remove items dynamically (i.e. the data is not fixed). So in the end, I need to get the list of items stored in the gtk.ListStore (which holds the data for the combo-box).

Why did I chose GTK?

Maybe I'll switch to pyqt. That might make it easier.

Or have I missed something too obvious? I even tried holding a separate list variable to hold the contents of the list and coordinate it with the ListStore, but unfortunate, when an item is removed from the combo box, I have no way to find out the text of the item removed, because I get only a gtk.TreeIter object.

Last edited by vharishankar; 11-30-2006 at 09:27 AM.
Old 11-30-2006, 10:02 PM   #2
Senior Member
Registered: Dec 2003
Posts: 3,161
Blog Entries: 4

Original Poster
Rep: Reputation: 136Reputation: 136
Ok I figured this out. Here's the bit of code:
# list_categories is the ListStore
# cats is the list to hold the retrieved items

cats = list ()
item = list_categories.get_iter_first ()

while ( item != None ):
	cats.append (list_categories.get_value (item, 0))
	item = list_categories.iter_next(item)

Last edited by vharishankar; 11-30-2006 at 10:04 PM.
Old 11-30-2006, 10:12 PM   #3
Senior Member
Registered: Jul 2005
Distribution: Slackware
Posts: 2,014

Rep: Reputation: 115Reputation: 115
Hey, I was about to point you to the C GTK doc on TreeIter and comment that TreeIter is the one and only iterator for Lists and Trees. Seems you figured it out yourself
Old 11-30-2006, 10:15 PM   #4
Senior Member
Registered: Dec 2003
Posts: 3,161
Blog Entries: 4

Original Poster
Rep: Reputation: 136Reputation: 136
I was looking at the documentation for ListStore. Seems it implements TreeModel. I didn't pay attention to TreeModel at first.


data, gtk, python, retrieving

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting GTK to work with python crazyjimbo Programming 4 11-27-2006 01:14 PM
Removing a colon and all characters before it, in a python list tangle Programming 4 09-12-2006 10:48 PM
LXer: How to use GTK+ in C and a C# Python comparison LXer Syndicated Linux News 0 01-12-2006 01:31 PM
WineX, python-gnome, and python-gtk DrD Fedora 0 08-03-2004 01:11 PM
python; retrieving dictionary of ley=value pairs passed into method TheLinuxDuck Programming 5 08-21-2003 12:56 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:20 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration