Class: TclTkCallback

Inherits:
TclTkObject show all
Defined in:
lib/tcltk.rb

Overview

class TclTkCallback: tcl/tk callbacks

Instance Method Summary collapse

Methods inherited from TclTkObject

#to_s

Constructor Details

#initialize(interp, pr, arg = nil) ⇒ TclTkCallback

initialize(interp, pr, arg):

interp: interpreter(TclTkInterpreter)
pr: callback procedure(Proc)
arg: string to pass as block parameters of pr
    bind command of tcl/tk uses % replacement for parameters
    pr can receive replaced data using block parameter
    its format is specified by arg string
    You should not specify arg for the command like
    scrollbar with -command option, which receives parameters
    without specifying any replacement


316
317
318
319
320
321
322
323
324
325
326
# File 'lib/tcltk.rb', line 316

def initialize(interp, pr, arg = nil)
  # auto-generate tcl/tk representation (variable name)
  exp = TclTk._newname("c_")
  # initialize TclTkObject
  super(interp._tcltkip(), exp)
  # save parameters
  @pr = pr
  @arg = arg
  # register in the module
  TclTk._addcallback(self)
end

Instance Method Details

#_call(arg) ⇒ Object

_call(arg): invoke callback

arg: callback parameter


342
343
344
# File 'lib/tcltk.rb', line 342

def _call(arg)
  @pr.call(arg)
end

#to_evalObject

to_eval(): retuens string representation for @ip._eval_args



329
330
331
332
333
334
335
336
337
338
# File 'lib/tcltk.rb', line 329

def to_eval()
  if @arg
    # bind replaces %s before calling ruby_fmt, so %%s is used
    s = %Q/{ruby_fmt {TclTk._callcallback("#{to_s()}", "%%s")} #{@arg}}/
  else
    s = %Q/{ruby_fmt {TclTk._callcallback("#{to_s()}", "%s")}}/
  end

  return s
end