class TclTkWidget - tk-0.2.0 Documentation

# class TclTkWidget

class TclTkWidget: tcl/tk widget

### Public Class Methods

new(*args) click to toggle source

initialize(*args):

    *args: parameters

Calls superclass method TclTkObject.new

    # File lib/tcltk.rb, line 261
      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
          return res
        else
          fail("first parameter is not TclTkInterpreter")
        end
      end