Class: TclTkWidget

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

Overview

class TclTkWidget: tcl/tk widget

Direct Known Subclasses

Othello::BoardView

Instance Method Summary collapse

Methods inherited from TclTkCommand

#e

Methods inherited from TclTkObject

#to_s

Constructor Details

#initialize(*args) ⇒ TclTkWidget

initialize(*args):

*args: parameters


260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
# File 'lib/tcltk.rb', line 260

def initialize(*args)
  if args[0].kind_of?(TclTkIp)
    # in case the 1st argument is TclTkIp:

    # Wrap tcl/tk widget by TclTkWidget
    # (used in TclTkInterpreter#initialize())

    # need two arguments
    fail("invalid # of parameter") if args.size != 2

    # ip: interpreter(TclTkIp)
    # exp: tcl/tk representation
    ip, exp = args

    # initialize TclTkObject
    super(ip, exp)
  elsif args[0].kind_of?(TclTkInterpreter)
    # in case 1st parameter is TclTkInterpreter:

    # generate new widget from parent widget

    # interp: interpreter(TclTkInterpreter)
    # parent: parent widget
    # command: widget generating tk command(label 等)
    # *args: argument to the command
    interp, parent, command, *args = args

    # generate widget name
    exp = parent.to_s()
    exp += "." if exp !~ /[.]$/
    exp += TclTk._newname("w_")
    # initialize TclTkObject
    super(interp._tcltkip(), exp)
    # generate widget
    res = @ip._eval_args(command, exp, *args)
#      fail("can't create Widget") if res != exp
    # for tk_optionMenu, it is legal res != exp
  else
    fail("first parameter is not TclTkInterpreter")
  end
end