How to get ComboBox strings?


#1

Hi all!

I have following problem : I’m using gtk2 and I want to write an
application wich, after start loads strings which should be in some
ComboBoxEntry from external file and in the end saves them back to same
file (similar behaviour as URL history in browser).

Problem is that I don’t know how to get list of strings stored in
ComboBox (Gtk::ComboBoxEntry.new(true)). According to reference manual,
there are onle Gtk::ComboBox#append_text, Gtk::ComboBox#insert_text,
Gtk::ComboBox#prepend_text, Gtk::ComboBox#remove_text and
Gtk::ComboBox#active_text methods supported.

So I miss some kind of array-like mechanism for access to strings
stored in
ComboBox list. Could anybody help me please ?

Thanks,

V.


Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net’s Techsay panel and you’ll get the chance to share
your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV


#2

On Tue, Mar 13, 2007 at 05:55:56PM +0100, Vladimir F. wrote:

Gtk::ComboBox#prepend_text, Gtk::ComboBox#remove_text and
Gtk::ComboBox#active_text methods supported.

Unfortunately, there’s no API for that when using Gtk::ComboBox in the
“convenience mode” with just strings. You’ll have to iterate over the
underlying Gtk::TreeModel to get all the strings:

list = []
combo_box.model.each { |model, path, iter| list << model.get_value(iter,
0) }

(Should work in theory, haven’t tested here)

-pete


Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net’s Techsay panel and you’ll get the chance to share
your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV


#3

I haven’t used the text only version, but you can use a ListStore for
the model like so:

@combo_list = Gtk::ListStore.new(String)

[‘one’,‘two’,‘three’].each do |a|
iter = @combo_list.append
iter[0] = a
end

@combo_box = Gtk::ComboBox.new(@combo_list)

Curtis

Vladimir F. wrote:

Gtk::ComboBox#prepend_text, Gtk::ComboBox#remove_text and
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net’s Techsay panel and you’ll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV


ruby-gnome2-devel-en mailing list
removed_email_address@domain.invalid
https://lists.sourceforge.net/lists/listinfo/ruby-gnome2-devel-en


Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net’s Techsay panel and you’ll get the chance to share
your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV


#4

Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net’s Techsay panel and you’ll get the chance to share
your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV


#5

Just beware that Gtk::Combo is deprecated.

From the docs:

“As of GTK+ 2.4, Gtk::Combo
http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3ACombo has been
deprecated in favor of Gtk::ComboBox
http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3AComboBox.”

on this page:
http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3ACombo

Dobai-Pataky Bálint wrote:

@combo_list = Gtk::ListStore.new(String)
Vladimir F. wrote:

there are onle Gtk::ComboBox#append_text, Gtk::ComboBox#insert_text,

https://lists.sourceforge.net/lists/listinfo/ruby-gnome2-devel-en
removed_email_address@domain.invalid
https://lists.sourceforge.net/lists/listinfo/ruby-gnome2-devel-en


Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net’s Techsay panel and you’ll get the chance to share
your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV


#6

Hi all!

I tryied Peter J.'s code and it works perfectly. I also tryied
Curtis
Summers’s code, but I was not able to force the code to work :frowning: (truth
is
that I did not play with it too much, because previuous way worked).
Anyway,
I have at least one way how to do job done! Thank you very much guys!
:slight_smile:

V.

I FEEL HAPPY :slight_smile:


Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net’s Techsay panel and you’ll get the chance to share
your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV


#7

On Tue, Mar 13, 2007 at 09:50:52PM +0200, Dobai-Pataky B??lint wrote:

how about trying the Gtk::Combo, and not the Gtk::ComboBox?
Gtk::Combo is for text only and does not use a model, as far as i
understood.

Gtk::Combo is an old widget, and really not suggested for new code.
Gtk::ComboBox is the way of the future! (:

-pete


Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net’s Techsay panel and you’ll get the chance to share
your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV