Forum: Ruby-Gnome 2 How to get ComboBox strings ?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Vladimir F. (Guest)
on 2007-03-13 18:57
(Received via mailing list)
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...
Peter J. (Guest)
on 2007-03-13 19:11
(Received via mailing list)
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...
Curtis S. (Guest)
on 2007-03-13 19:15
(Received via mailing list)
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...
> _______________________________________________
> ruby-gnome2-devel-en mailing list
> removed_email_address@domain.invalid
> https://lists.sourceforge.net/lists/listinfo/ruby-...
>
>


-------------------------------------------------------------------------
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...
Dobai-Pataky Bálint (Guest)
on 2007-03-13 21:56
(Received via mailing list)
-------------------------------------------------------------------------
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...
Peter J. (Guest)
on 2007-03-13 21:59
(Received via mailing list)
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...
Curtis S. (Guest)
on 2007-03-13 22:06
(Received via mailing list)
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%... has been
deprecated in favor of Gtk::ComboBox
<http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%...

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-...
> removed_email_address@domain.invalid
> https://lists.sourceforge.net/lists/listinfo/ruby-...
>


-------------------------------------------------------------------------
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...
Vladimir F. (Guest)
on 2007-03-15 01:54
(Received via mailing list)
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 :( (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!
:)

 V.

I FEEL HAPPY :)

-------------------------------------------------------------------------
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...
This topic is locked and can not be replied to.