Re: [Fxruby-users] Message Identifiers, Types, etc again.
Status: Inactive
Brought to you by:
lyle
|
From: Lyle J. <jl...@cf...> - 2003-06-13 18:04:25
|
Hugh Sasse Staff Elec Eng wrote:
>> The ID_OPEN_FIRST message identifier tells the shutter to open its first
>> item, so let's make that the message identifier (or selector):
>>
>> openFirstButton.setSelector(FXShutter::ID_OPEN_FIRST)
>>
>> So now, when the user clicks this button, it will send a (SEL_COMMAND,
>> ID_OPEN_FIRST) message to the shutter.
>
> So this is sending the ID_OPEN_FIRST selector in the data part of
> the (sender, message, data) triple?
No. The part of the (sender, message, data) triple is a number that
incorporates both the message type and identifier. In a previous e-mail,
Sander referred to two methods you can use to extract the type and
identifier from the "message" value:
def someMessage(sender, sel, data)
messageType = Fox.SELTYPE(sel)
messageId = Fox.SELID(sel)
...
end
In most cases you actually don't need to do this, but the information's
there if you want it. I say that you don't need to do this because,
generally speaking, you know why you ended up in that message handler in
the first place and there's no need to check the message type or
identifier to confirm it. For example, consider this code:
aButton = FXButton.new(...)
aButton.connect(SEL_COMMAND, method(:onCommand))
...
def onCommand(sender, sel, data)
#
# Here, I can check the type of the message using
# Fox.SELTYPE(sel), but I already know what the
# answer's going to be. I got here because I "connected"
# the button's SEL_COMMAND message to this handler method.
#
end
> (Incidentally, I don't see setSelector in the http://www.fxruby.org/doc/api/ but that's BTW.)
Yeah, this isn't spelled out clearly in the README part of the API docs,
but it should be. For all of the getter and setter methods (including
FXWindow#getSelector and FXWindow#setSelector) there are aliases that
instead make them look like regular Ruby attr_reader and attr_writer
methods. So if you look at the documentation for FXWindow:
http://www.fxruby.org/doc/api/classes/Fox/FXWindow.html
and check its list of "Attributes", you'll see an entry for "selector",
which has [RW] accessors. So to set the selector for a window, you can use:
aWidget.setSelector(xxx)
or the more Ruby-esque:
aWidget.selector = xxx
which I thought was more compact.
Hope this helps,
Lyle
|