this is a follow up on how to properly use glade with ruby, if anyone is
interested.
masao mutoh was extremely helpful with this and even threw together a
smaple framework for my app! too kind. so, as an example, i’ll give you
a simplified version of that framework:
require ‘lglade’
class Test
def initialize
@glade = GladeXML.new(“mygui.glade”) { |handler|
p handler # this will actually print all signals
method(handler)
}
end
def on_some_signal_one
p “on_some_signal_one”
end
def on_some_signal_two
p “on_some_signal_two”
end
def on_some_signal_three
p “on_some_signal_three”
end
…
def on_some_signal_to_very_last
p “on_some_signal_to_very_last”
end
end
Test.new
Gtk.main
so this is the “correct” approach: every glade file you have will get
its own class. an important thing to remember is that each and every
signal must be accounted for in your methods, otherwise you’ll get an
error, and sometimes it’s not a very obvious one. that’s was the problem
i was having. don’t leave any out, even if they don’t yet do anything as
you are developing.
the above framework is quite elegent, and makes it easy to slice up your
gui windows into multiple .glade files. you simply define a new class
like the one above for each file, then instantiate the class in your
code. you only need to do GTK.main the one time, from then on all new
glade gui windows will appear as they are created anew. (well, if
they’re not designated as hidden, in wich case you;d need to use the
.show method)
of course you can have multiple windows in a sigle glade file, but i
would not over due this approach because of naming conflicts. since
every widget within a single glade file must have a unique name which
you access in your code with @glade.getWidget(‘widget_name’) it is
easier to seperate your windows into seperate glade files by functional
divisions. also, you will find that the method #getWidgetByLongName is
rather useless as you have to know the entire tree of containment to get
at the desired widget. with gtk, this can be down under quite a depth of
layout mananger widgets, so just stick with the unique names.
okay, that should give anyone interested in using glade a good start.
the docs aren’t so great but they are getting better. i have found that
the best thing to do is simply puts #methods on whatever widget object
your trying to understand, and see all that it does. (i could not get
the included rbbc.rb class browser to fully work, by the way)
if anyone has any other questions about glade let me know and i’ll see
what i can do. hope this is helpful.
~transami
p.s. Thanks Masao!
···
On Fri, 2002-08-09 at 01:36, Tom Sawyer wrote:
hi,
i am trying to load two glade files one after another. is there a
special trick? or is it not possible?
something like the following, although my program has these two GladeXML
instantiations in seperate methods, the first calling the second when
logon is successful.
g1 = GladeXML.new(‘logon.glade’) { |handler_name|
…
}
Gtk::main
g2 = GladeXML.new(‘search.glade’) { |handler_name|
…
}
Gtk::main
i get an error on the second call at g2 = GladeXML …
(eval):13:in ‘doConnect’: undefined method ‘arity’ for nil (NameError)
any help would be much appreciated.
–
~transami
–
~transami