Class | TclTkInterpreter
In: | tcltklib/lib/tcltk.rb
Parent: | Object

class TclTkInterpreter: tcl/tk interpreter

### Methods

_tcltkip commands method_missing new rootwidget

### Public Class methods

new()

initialize():

[Source]

    # File tcltklib/lib/tcltk.rb, line 88
      def initialize()
        # generate interpreter object
        @ip = TclTkIp.new()

        # add ruby_fmt command to tcl interpreter
        # ruby_fmt command format arguments by `format' and call `ruby' command
        # (notice ruby command receives only one argument)
        if $DEBUG
          @ip._eval("proc ruby_fmt {fmt args} { puts \"ruby_fmt: $fmt $args\" ; set cmd [list ruby [format $fmt $args]] ; uplevel $cmd }")
        else
          @ip._eval("proc ruby_fmt {fmt args} { set cmd [list ruby [format $fmt $args]] ; uplevel $cmd }")
        end

        # @ip._get_eval_string(*args): generate string to evaluate in tcl interpreter
        #   *args: script which is going to be evaluated under tcl/tk
        def @ip._get_eval_string(*args)
          argstr = ""
          args.each{|arg|
            argstr += " " if argstr != ""
            # call to_eval if it is defined
            if (arg.respond_to?(:to_eval))
              argstr += arg.to_eval()
            else
              # call to_s unless defined
              argstr += arg.to_s()
            end
          }
          return argstr
        end

        # @ip._eval_args(*args): evaluate string under tcl/tk interpreter
        #     returns result string.
        #   *args: script which is going to be evaluated under tcl/tk
        def @ip._eval_args(*args)
          # calculate the string to eval in the interpreter
          argstr = _get_eval_string(*args)

          # evaluate under the interpreter
          print("_eval: \"", argstr, "\"") if $DEBUG
          res = _eval(argstr)
          if $DEBUG
            print(" -> \"", res, "\"\n")
          elsif  _return_value() != 0
            print(res, "\n")
          end
          fail(%Q/can't eval "#{argstr}"/) if _return_value() != 0 #'
          return res
        end

        # generate tcl/tk command object and register in the hash
        @commands = {}
        # for all commands registered in tcl/tk interpreter:
        @ip._eval("info command").split(/ /).each{|comname|
          if comname =~ /^[.]/
            # if command is a widget (path), generate TclTkWidget,
            # and register it in the hash
            @commands[comname] = TclTkWidget.new(@ip, comname)
          else
            # otherwise, generate TclTkCommand
            @commands[comname] = TclTkCommand.new(@ip, comname)
          end
        }
      end

### Public Instance methods

_tcltkip()

_tcltkip(): returns @ip(TclTkIp)

[Source]

    # File tcltklib/lib/tcltk.rb, line 163
      def _tcltkip()
        return @ip
      end

commands()

commands(): returns hash of the tcl/tk commands

[Source]

    # File tcltklib/lib/tcltk.rb, line 153
      def   commandscommandscommands()
        return @commands
      end

method_missing(id, *args)

method_missing(id, *args): execute undefined method as tcl/tk command

      id: method symbol
      *args: method arguments

[Source]

    # File tcltklib/lib/tcltk.rb, line 170
      def method_missing(id, *args)
        # if command named by id registered, then execute it
        if @commands.key?(id.id2name)
          return @commands[id.id2name].e(*args)
        else
          # otherwise, exception
          super
        end
      end

rootwidget()

rootwidget(): returns root widget(TclTkWidget)

[Source]

    # File tcltklib/lib/tcltk.rb, line 158
      def rootwidget()
        return @commands["."]
      end

[Validate]