Re: GTK3 ruby comboboxtext: remove text items

Kouhei Sutou <[email protected]>
Newsgroups gmane.comp.lang.ruby.general
Message-ID <[email protected]>
Hi,

In <[email protected]>
  "GTK3 ruby comboboxtext: remove text items" on Sat, 27 Oct 2018 20:45:33 +0200,
  ulli bei Unity <[email protected]> wrote:

> I am using GTK3 ruby 2.5. My problem I want do delete the list.
> 
> I already checked: remove_all, and combobox.model.clear
> 
> but nothing works.

The following works for me:

----
#!/usr/bin/env ruby

require "gtk3"

if str = Gtk.check_version(3, 10, 7)
  puts "This sample requires GTK+ 3.10.7 or later"
  puts str
  exit
end

window = Gtk::Window.new("Gtk::ComboBox sample")
window.signal_connect("destroy") {Gtk.main_quit}

#
# Text only
#
combo1 = Gtk::ComboBoxText.new
["foo", "bar", "fuga", "hoge"].each do |val|
  combo1.append_text(val)
end
combo1.active = 1

combo1.signal_connect("changed") do
  # p "combo1: #{combo1.active}, #{combo1.active_iter[0]}"
  if combo1.model.iter_first
    combo1.active = 1
  end
end

combo1.model.clear

# Show main window
vbox = Gtk::Box.new(:vertical)
vbox.add(combo1)
window.add(vbox).show_all

Gtk.main
----


Thanks,
--
kou

Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.