LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   gtk.ListStore - python - retrieving the list values? (https://www.linuxquestions.org/questions/programming-9/gtk-liststore-python-retrieving-the-list-values-506215/)

vharishankar 11-30-2006 08:24 AM

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? :p

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

vharishankar 11-30-2006 09:02 PM

Ok I figured this out. Here's the bit of code:
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)


tuxdev 11-30-2006 09:12 PM

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 :)

vharishankar 11-30-2006 09:15 PM

I was looking at the documentation for ListStore. Seems it implements TreeModel. I didn't pay attention to TreeModel at first. ;)


All times are GMT -5. The time now is 10:32 AM.