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


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

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


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

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

#to_evalObject

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



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

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