LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

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

Rep: Reputation: 121Reputation: 121
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 08:27 AM.
 
Old 11-30-2006, 09:02 PM   #2
vharishankar
Senior Member
 
Registered: Dec 2003
Posts: 3,142
Blog Entries: 4

Original Poster
Rep: Reputation: 121Reputation: 121
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)

Last edited by vharishankar; 11-30-2006 at 09:04 PM.
 
Old 11-30-2006, 09:12 PM   #3
tuxdev
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, 09:15 PM   #4
vharishankar
Senior Member
 
Registered: Dec 2003
Posts: 3,142
Blog Entries: 4

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


Reply

Tags
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 12:14 PM
Removing a colon and all characters before it, in a python list tangle Programming 4 09-12-2006 09:48 PM
LXer: How to use GTK+ in C and a C# Python comparison LXer Syndicated Linux News 0 01-12-2006 12:31 PM
WineX, python-gnome, and python-gtk DrD Fedora 0 08-03-2004 12:11 PM
python; retrieving dictionary of ley=value pairs passed into method TheLinuxDuck Programming 5 08-21-2003 11:56 AM


All times are GMT -5. The time now is 07:48 PM.

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