module Tk::Cget

Constants

CGET_MAP

Public Instance Methods

cget(option) click to toggle source
# File lib/ffi-tk/command/cget.rb, line 35
def cget(option)
  option = option.to_tcl_option
  Cget.option_to_ruby(option, execute('cget', option))
end
option_hash_to_tcl(hash) click to toggle source
# File lib/ffi-tk/command/cget.rb, line 83
def option_hash_to_tcl(hash)
  result = {}

  hash.each do |key, value|
    case type = CGET_MAP[option = key.to_tcl_option]
    when :command
      command = register_command(key, &value)
      result[option] = command
    else
      result[option] = value
    end
  end

  result
end
option_to_ruby(name, value) click to toggle source
# File lib/ffi-tk/command/cget.rb, line 42
def option_to_ruby(name, value)
  if type = CGET_MAP[name.to_tcl_option]
    type_to_ruby(type, value)
  else
    raise 'Unknown type for %p: %p' % [name, value]
  end
end
type_to_ruby(type, value) click to toggle source
# File lib/ffi-tk/command/cget.rb, line 50
def type_to_ruby(type, value)
  case type
  when :integer
    value.respond_to?(:to_i?) ? value.to_i? : value.to_i
  when :symbol
    value&.to_sym
  when :boolean
    Tk.boolean(value)
  when :color, :string, :font, :bitmap
    value.respond_to?(:to_s?) ? value.to_s? : value
  when :variable
    Variable.new(value.to_s?) if value.respond_to?(:to_s?)
  when :list
    case value
    when Array
      value
    when String
      value.split
    else
      value.to_a
    end
  when :float
    value.to_f
  when :pathname
    Tk.pathname_to_widget(value.to_s)
  when :command
    string = value.to_s
    string unless string.empty?
  else
    raise 'Unknown type: %p: %p' % [type, value]
  end
end