Discussion:
GTK3 ruby comboboxtext: remove text items
ulli bei Unity
2018-10-27 18:45:33 UTC
Permalink
Hello,

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.

How can I delete the Textlist.


Cheers



#!/usr/bin/env ruby


require "gtk3"
require "pry"

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]}"
    combo1.active = 1
end



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

Gtk.main



Unsubscribe: <mailto:ruby-talk-***@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/rub
Kouhei Sutou
2018-10-28 00:20:15 UTC
Permalink
Hi,

In <5d4b5cbc-7eaa-92e3-7a16-***@unitybox.de>
"GTK3 ruby comboboxtext: remove text items" on Sat, 27 Oct 2018 20:45:33 +0200,
Post by ulli bei Unity
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:ruby-talk-***@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

Loading...