How add Gtk button with other widgets?

Hi guys :slight_smile:

I created a simple Gtknetbook with combo box inside, now i try to add
two buttons on the right down side like that “Quit” “Ok” but i got the
following error:

bricolage1.rb: line 32
Gtk-WARNING **:Attempting to add a widget with type GtkButton to a
GtkWindow, but as a GtkBin subclass a GtkWindow can only contain one
widget at a time; it already contains a widget of type GtkNotebook

Here is my code:

require ‘gtk2’

window = Gtk::Window.new(Gtk::Window::TOPLEVEL)
window.set_title “Test”
window.border_width = 100
window.set_default_size 300, 300

nb = Gtk::Notebook.new
label1 = Gtk::Label.new(“Start”)
b = Gtk::Button.new(Gtk::Stock::OK)
b = Gtk::Button.new(Gtk::Stock::CANCEL)

combo1 = Gtk::ComboBox.new
[“Scan”, “toto”, “hoge”, “lucas”].each do |val|
combo1.append_text(val)
end
combo1.active = 1

combo1.signal_connect(“changed”) do
p “combo1: #{combo1.active}, #{combo1.active_iter[0]}”
end

nb.append_page(combo1, label1)
window.add(nb)
window.add(b)
window.show_all
Gtk.main

How i can add my buttons ?

Thanks :slight_smile:

I don’t know Ruiby but it appear like shoes no ?

I try your code using Ruiby and it work lika a charm ,

But don’t understand why i have en error with:

syntax error, unexpected $end, expecting ‘}’

when i try to add a third page with other combobox.I do the same you
post here and the } is in my code too.

Florent Daguerre wrote in post #1169424:

Hi guys :slight_smile:

b = Gtk::Button.new(Gtk::Stock::OK)
b = Gtk::Button.new(Gtk::Stock::CANCEL)

b1 and b2 ?..

window.add(nb)
window.add(b)
window.show_all

hbox=Box.new()
hbox.add(nb)
hbox.add(b1)
hbox.add(b2)
window.add(hbox)
window.show_all

or

require ‘Ruiby’

Ruiby.app width: 300, height: 300, title: “Test” do
notebook {
page(“Essai”) do
stack do
combo({“scan”=>1,“toto”=>2,“hoge”=>3,“Licas”=>3},1)
flowi {
button("#ok") { alert(“ok”)}
button("#cancel") {alert(“cancel”)}
}
end
end
page(“Help”) do
label(“gem install Ruiby”)
end
}
end

Florent Daguerre wrote in post #1169504:

I don’t know Ruiby but it appear like shoes no ?

yes, very close, differences are:

  • widget only, many widget type (for drawing, you must create a drawing
    area)
  • no permanent loop

when i try to add a third page with other combobox.I do the same you
post here and the } is in my code too.

show us the code…

Hi :slight_smile:

My objective is create a notebook with seven tab, for each of those
tables a combobox inside with the same buttons gtk stock Ok and cancel.

When i try to add a third page i got the error i explain above, im sure
it’s because the symbol “}” is not very clear in my head.The code below
is the code you show me.

require ‘Ruiby’

Ruiby.app width: 300, height: 300, title: “Test” do
notebook {
page(“Essai”) do
stack do
combo({“scan”=>1,“toto”=>2,“hoge”=>3,“Licas”=>3},1)
flowi {
button("#ok") { alert(“ok”)}
button("#cancel") {alert(“cancel”)}
}
end
end
page(“Help”) do
label(“gem install Ruiby”)
end
} # is this the end funtion of the gtk netbook ?
end

Now the code im trying to do:
require ‘Ruiby’

Ruiby.app width: 300, height: 300, title: “Test” do
notebook {
page(“Essai”) do
stack do
combo({“scan”=>1,“toto”=>2,“hoge”=>3,“Licas”=>3},1)
flowi {
button("#ok") { alert(“ok”)}
button("#cancel") {alert(“cancel”)}
}
end
end
page(“Test”) do
stack do
combo({“blabla”=>1,“dark”=>2,“etc”=>3,“donuts”=>3},1)
flowi {
button("#ok") { alert(“ok”)}
button("#cancel") {alert(“cancel”)}
}
end
end
page(“Othertest”) do
stack do
combo({“Marje”=>1,“Bart”=>2,“Duff”=>3,“Homer”=>3},1)
flowi {
button("#ok") { alert(“ok”)}
button("#cancel") {alert(“cancel”)}
}
}
end
end

It’s my first app sorry if im little confusing…

Florent Daguerre wrote in post #1169570:

Hi :slight_smile:

My objective is create a notebook with seven tab, for each of those
tables a combobox inside with the same buttons gtk stock Ok and cancel.

Don’t repeat yourself…
you can factoring your components :

Ruiby.app width: 300, height: 300, title: “Test” do
def flo_page(name,hcombo,default)
page(name) do
stack do
c=combo(hcombo,default)
flowi do
button("#ok") {
alert(“ok #{name} #{c.get_selection.join(’/’)}”)}
button("#cancel") {
alert(“cancel”)
}
end
end
end
end
notebook {
flo_page(“one”,{“a” => 1, “b” => 2, “c” => 3},1)
flo_page(“two”,{“aa” => 1, “ab” => 2, “ac” => 3},2)
flo_page(“tree”,{“ba” => 1, “bb” => 2, “bc” => 3},3)
page(“Help”) do
label(“gem install Ruiby”)
end
}
end

When i try to add a third page i got the error i explain above, im sure
it’s because the symbol “}” is not very clear in my head.The code below

page(“Othertest”) do
stack do
combo({“Marje”=>1,“Bart”=>2,“Duff”=>3,“Homer”=>3},1)
flowi {
button("#ok") { alert(“ok”)}
button("#cancel") {alert(“cancel”)}
}
<>
}
end
end

At <>, 2 ‘end’ are missing : end of stack, end of page.
You should use a editor which known ruby syntaxe, this is
very helpful :

  • notepad++
  • (netbeans or eclipse)+ ruby plugin
  • redcar

It’s my first app sorry if im little confusing…

Begining ruby by gui application is perhaps a little hard.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs