FXRuby without the subclassing

is there a way to use FXRuby without subclassing from an FXObject? every
example i’ve looked at has something like:

MyAppClass < FXMainWindow

is this neccessary?

FYI - as a proof of concept i’m making GUtopIa plugable so you can tack
on any GUI toolkit you like. i decide to start with Fox using FXRuby,
even though GTK+ might have beean easier, but obviosuly, i’ve run into
the above problem. specifically i can’t seem to get targeted messages to
work.

thanks,

~transami

Tom Sawyer wrote:

is there a way to use FXRuby without subclassing from an FXObject? every
example i’ve looked at has something like:

MyAppClass < FXMainWindow

is this neccessary?

I’m not sure I understand the question. FXRuby is a class library just
like any other Ruby class library. If you just want to use the built-in
classes you can do so, e.g.

 # Create a button
 myButton = FXButton.new(...)

but if you need a customized version of some widget, you might also
choose to subclass it, e.g.

 class MySpecialButton < FXButton
   def initialize(p, buttonText, buttonIcon)
     # Initialize base class first
     super(p, buttonText, buttonIcon)
   end
 end

By convention, most FOX (and FXRuby) applications create an
application-specific subclass of FXMainWindow, and this is what you’ll
see in a majority of the FXRuby example programs. But it’s certainly not
necessary to subclass FXMainWindow, especially for simple little GUIs;
see, for example, the “hello.rb” and “hello2.rb” example programs, which
don’t do any subclassing.

FYI - as a proof of concept i’m making GUtopIa plugable so you can tack
on any GUI toolkit you like. i decide to start with Fox using FXRuby,
even though GTK+ might have been easier, but obviosuly, i’ve run into
the above problem. specifically i can’t seem to get targeted messages to
work.

I don’t know what you mean by “I can’t seem to get targeted messages to
work”. For most FOX widgets you can connect the widget’s command message
(SEL_COMMAND) directly to a Ruby code block, e.g.

 myButton = FXButton.new(parent, "Click Me!")
 myButton.connect(SEL_COMMAND) { puts "Call me Ishmael" }

Hope this helps,

Lyle

thanks, that worked! this not at all how the examples i’ve seen do it,
but this is much better, much more intuitive. thanks Ishmael! :wink:

strange though:

class RadioBox_Fox < RadioBox
attr_reader :engine_widget
def initialize(engine, attributes={})
super
@engine_widget = FXGroupBox.new(@engine.false_parent, ‘’,
LAYOUT_SIDE_TOP|FRAME_GROOVE|LAYOUT_FILL_X, 0, 0, 0, 0)
items.each do |item|
fxrb = FXRadioButton.new(@engine_widget, item, nil, 0,
JUSTIFY_LEFT|JUSTIFY_TOP|ICON_BEFORE_TEXT|LAYOUT_SIDE_TOP)
fxrb.connect(SEL_COMMAND) {
if fxrb.getCheck
@value = fxrb.to_s
self.value=fxrb.to_s # why do i have to use self here?
event_change # i don’t here!
end
}
end
end
end # RadioBox

why do i need to use self to get to the class’ (actually the instance of
the class’) #value= method?

also notice i had to set @value explicity. that’s b/c #value= is
dynamically defined with class_eval { define_method(…) } in which i
haven’t yet figured out to use #super so it is in the context of the
class and not the object the class_eval is called from.

thanks again,

~transami

···

On Wed, 2002-07-24 at 17:48, Lyle Johnson wrote:

 myButton = FXButton.new(parent, "Click Me!")
 myButton.connect(SEL_COMMAND) { puts "Call me Ishmael" }

Lyle,

this helped out wonderfully as i posted before, but now i’m stuck on
needing to temporarily suspending the “connection”. do you know of a way
to do this?

very thankful,

~transami

···

On Wed, 2002-07-24 at 17:48, Lyle Johnson wrote:

 myButton = FXButton.new(parent, "Click Me!")
 myButton.connect(SEL_COMMAND) { puts "Call me Ishmael" }

Hi –

···

On Thu, 25 Jul 2002, Tom Sawyer wrote:

        @value = fxrb.to_s
        self.value=fxrb.to_s  # why do i have to use self here?

If you don’t specify the receiver in “self.value = …”, Ruby will
interpret "value = " as meaning that value is a local variable, rather
than a method. That’s how Ruby disambiguates such expressions – so
if you want it to be a method call, you have to disambiguate it in the
other direction by specifying “self”.

David


David Alan Black
home: dblack@candle.superlink.net
work: blackdav@shu.edu
Web: http://pirate.shu.edu/~blackdav

Tom Sawyer wrote:

this helped out wonderfully as i posted before, but now i’m stuck on
needing to temporarily suspending the “connection”. do you know of a way
to do this?

If you just want to suspend the connection (implying that you’re going
to “unsuspend” it later) I think I’d just use some kind of state
variable to indicate whether the action is suspended or not, e.g.

 myButton.connect(SEL_COMMAND) do
   unless suspended?
     do-whatever-it-is-that-I-do
   end
 end

Now if you just want to break the link altogether, you can set the
button’s message target to nil:

 myButton.target = nil

Hope this helps,

Lyle

thanks david, that makes sense, but i’m confused in that i don’t have to
put the self on #event_change. in fact when i do it bombs. something to
do with the = perhaps?

···

On Wed, 2002-07-24 at 19:23, David Alan Black wrote:

Hi –

On Thu, 25 Jul 2002, Tom Sawyer wrote:

        @value = fxrb.to_s
        self.value=fxrb.to_s  # why do i have to use self here?

If you don’t specify the receiver in “self.value = …”, Ruby will
interpret "value = " as meaning that value is a local variable, rather
than a method. That’s how Ruby disambiguates such expressions – so
if you want it to be a method call, you have to disambiguate it in the
other direction by specifying “self”.


~transami

Hi –

Hi –

        @value = fxrb.to_s
        self.value=fxrb.to_s  # why do i have to use self here?

If you don’t specify the receiver in “self.value = …”, Ruby will
interpret "value = " as meaning that value is a local variable, rather
than a method. That’s how Ruby disambiguates such expressions – so
if you want it to be a method call, you have to disambiguate it in the
other direction by specifying “self”.

thanks david, that makes sense, but i’m confused in that i don’t have to
put the self on #event_change. in fact when i do it bombs. something to
do with the = perhaps?

(Whoops, I quoted the line above the = line instead of the one below :slight_smile:

Yes, the ‘=’ is the determinant. In the case of the bare
"event_change", there’s no indication to Ruby that this is anything
but a method call.

Lots of method calls will fail if you stick “self.” on front of them,
so on its own that isn’t an indication of a problem :slight_smile:

David

···

On Thu, 25 Jul 2002, Tom Sawyer wrote:

On Wed, 2002-07-24 at 19:23, David Alan Black wrote:

On Thu, 25 Jul 2002, Tom Sawyer wrote:


David Alan Black
home: dblack@candle.superlink.net
work: blackdav@shu.edu
Web: http://pirate.shu.edu/~blackdav