GTK3-Class Extensions not possible


(ulli bei Unity) #1

Hello,

for some reasons I extend ruby GTK3 class with some functions. This works

very well with ruby-gtk3 2.2.5-4 build1. With ruby-gtk 3.2.4-1 I get always the following error:

comboboxtext_mod.rb:8: warning: previous definition of ComboBoxText was here
Traceback (most recent call last):
comboboxtext_mod.rb:31:in `<main>': undefined method `set_names' for #<Gtk::ComboBoxText:0x5628eabeb0e0 ptr=0x5628eb0102c0> (NoMethodError)
Did you mean? set_name

Cheers

#!/usr/bin/env ruby

require "gtk3"
require "pry"

class Gtk::ComboBoxText

 def set\_names aL
     aL\.each\{|x| self\.append\_text x\}
 end

end

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() #(:entry => true)
@combo1.set_names ["foo", "bar", "fuga", "hoge"]
@combo1.active = 1

@combo1.signal_connect("changed") do

@combo1 = Gtk::ComboBoxText.new
@combo1.set_names ["moon", "mars"]
@combo1.active = 0
@combo1.remove_all
end

button = Gtk::Button.new(:label => "close")
button.signal_connect("clicked") do
@combo1.remove_all
#Gtk.main_quit
end

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

Gtk.main


(Kouhei Sutou) #2

Hi,

In <da1768cc-8ec5-6503-b4fa-3bd23d2c2d2c@unitybox.de>
  "GTK3-Class Extensions not possible" on Fri, 16 Nov 2018 19:48:43 +0100,

for some reasons I extend ruby GTK3 class with some functions. This
works very well with ruby-gtk3 2.2.5-4 build1. With
ruby-gtk 3.2.4-1 I get always the following error:

comboboxtext_mod.rb:8: warning: previous definition of ComboBoxText
was here
Traceback (most recent call last):
comboboxtext_mod.rb:31:in `<main>': undefined method `set_names' for
#<Gtk::ComboBoxText:0x5628eabeb0e0 ptr=0x5628eb0102c0> (NoMethodError)
Did you mean? set_name

gtk3 gem generates bindings at run-time. And it's occurred
when you touch methods or classes under the Gtk namespace
for the first time.

Your script works with the modification:

Gtk::ComboBoxText # Add this line or touch other methods or
                  # classes such as Gtk.check_version
                  # (Gtk::Version.or_later? is better than
                  # Gtk.check_version.)
class Gtk::ComboBoxText
  def set_names aL
    aL.each{|x| self.append_text x}
  end
end

Thanks,

···

ulli bei Unity <upahermann@unitybox.de> wrote:
--
kou