[fxruby-users] Data Targets and message handlers [was: Default double-click in FXTable?]

Philippe Lang philippe.lang at attiksystem.ch
Wed Oct 11 02:37:44 EDT 2006

fxruby-users-bounces at rubyforge.org wrote:

>> This makes FXDataTarget objects pretty useless under FXRuby...
> Have you looked at FoxTails/Observable? FoxTails subclasses
> some of the Fox/FXRuby classes and defines an initialize
> method that (typically) takes an object and an attribute name
> instead of the usual target arguments. The attribute name is
> used to keep that attr in sync when the widget is used.
> FoxTails uses Fox's #connect mechanism for this functionality
> (typically, using SEL_COMMAND, SEL_FOCUSOUT, etc) rather than
> data targets. This means you can still use connect (with
> other messages) for other purposes. You can also use the
> #when_foo methods to register blocks of code to execute when
> the attr changes or matches a pattern.
> Here's a simple combobox example that lets you select an
> object (in terms of its string representation using #inspect)
> and then changes a label to display the class of the object.
> #!/usr/bin/env ruby
> require 'foxtails'

Thanks Joel, I have to check your library.

Otherwise, Lyle, do you think it would be possible to implement messaging in FXRuby differently, without the FXPseudoTarget? I'm wondering why the content of the FXPseudoTarget class cannot be included directly, at run-time, in the object itself, rather than in in a separate class. This would avoid modifying the target of an object when connecting a handler to it.

  class FXPseudoTarget < FXObject

    include Responder

    @@targets_of_pending_timers = {}
    @@targets_of_pending_chores = {}
    @@targets_of_pending_signals = {}
    @@targets_of_pending_inputs = {}

    # Returns an initialized FXPseudoTarget object.
    def initialize
      @blocks = {}

    # Store an association between a message of type
    # _messageType_ with a callable object or a block.
    def pconnect(messageType, callableObject, block)
      if callableObject.nil?
	@blocks[messageType] = block
	@blocks[messageType] = callableObject
      FXMAPTYPE(messageType, :onHandleMsg)
      case messageType
        when SEL_TIMEOUT
	  @@targets_of_pending_timers[self] = self
        when SEL_CHORE
	  @@targets_of_pending_chores[self] = self
        when SEL_SIGNAL
	  @@targets_of_pending_signals[self] = self
	  @@targets_of_pending_inputs[self] = self

    # Handle a message from _sender_, with selector _sel_ and
    # message data _ptr_.
    def onHandleMsg(sender, sel, ptr)
      messageType = Fox.FXSELTYPE(sel)
      result = @blocks[messageType].call(sender, sel, ptr)
      case messageType
        when SEL_TIMEOUT
        when SEL_CHORE

Philippe Lang
Attik System

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3125 bytes
Desc: not available
Url : http://rubyforge.org/pipermail/fxruby-users/attachments/20061011/dfdd7ae7/attachment.bin 

More information about the fxruby-users mailing list