Method: Fox::FXApp#addChore

Defined in:
lib/fox16/chore.rb

#addChore(*args, &block) ⇒ Object

Add a idle processing message to be sent to a target object when the system becomes idle, i.e. when there are no more events to be processed. There are several forms for #addChore; the original form (from FOX) takes two arguments, a target object and a message identifier:

app.addChore(tgt, sel)

If a chore with the same target and message already exists, it will be rescheduled.

A second form takes a Method instance as its single argument:

app.addChore(mthd)

For this form, the method should have the standard argument list for a FOX message handler. That is, the method should take three arguments, for the message sender (an FXObject), the message selector, and the message data (if any).

The last form takes a block:

app.addChore() do |sender, sel, data|
    ... handle the chore ...
end

All of these return a reference to an opaque FXChore instance that can be passed to #removeChore if it is necessary to remove the chore before it fires.

For the last two forms, you can pass in the optional :repeat parameter to cause the chore to be re-registered after it fires, e.g.

chore = app.addChore(:repeat => true) do |sender, sel, data|
    ... handle the chore ...
    ... re-add the chore ...
end


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/fox16/chore.rb', line 46

def addChore(*args, &block)
  params = {}
  params = args.pop if args.last.is_a? Hash
  tgt, sel = nil, 0
  if args.length > 0
    if args[0].respond_to? :call
      tgt = params[:target] || FXPseudoTarget.new
      tgt.pconnect(SEL_CHORE, args[0], params)
    else
      tgt, sel = args[0], args[1]
    end
  else
    tgt = params[:target] || FXPseudoTarget.new
    tgt.pconnect(SEL_CHORE, block, params)
  end
  addChoreOrig(tgt, sel)
  params[:target] = tgt
  params[:selector] = sel
  params
end