Module: TkConfigMethod

Includes:
TkTreatFont, TkUtil
Included in:
Tk::Tcllib::Tkpiechart::ConfigMethod, TkObject
Defined in:
lib/tk.rb

Constant Summary

Constants included from TkUtil

TkUtil::None, TkUtil::RELEASE_DATE

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TkTreatFont

#font_configinfo, #font_configure, #font_copy, #kanjifont_configure, #kanjifont_copy, #latinfont_configure, #latinfont_copy

Methods included from TkUtil

_conv_args, #_conv_args, #_fromUTF8, #_get_eval_enc_str, _get_eval_enc_str, #_get_eval_string, _get_eval_string, #_symbolkey2str, _symbolkey2str, #_toUTF8, #bool, bool, callback, eval_cmd, hash_kv, #hash_kv, install_cmd, num_or_nil, #num_or_nil, #num_or_str, num_or_str, #number, number, string, #string, uninstall_cmd, untrust

Class Method Details

.__IGNORE_UNKNOWN_CONFIGURE_OPTION__Object


3745
3746
3747
# File 'lib/tk.rb', line 3745

def TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
  @mode || false
end

.__set_IGNORE_UNKNOWN_CONFIGURE_OPTION__!(mode) ⇒ Object


3748
3749
3750
3751
# File 'lib/tk.rb', line 3748

def TkConfigMethod.__set_IGNORE_UNKNOWN_CONFIGURE_OPTION__!(mode)
  fail SecurityError, "can't change the mode" if $SAFE>=4
  @mode = (mode)? true: false
end

Instance Method Details

#[](id) ⇒ Object


3876
3877
3878
# File 'lib/tk.rb', line 3876

def [](id)
  cget(id)
end

#[]=(id, val) ⇒ Object


3880
3881
3882
3883
# File 'lib/tk.rb', line 3880

def []=(id, val)
  configure(id, val)
  val
end

#__check_available_configure_options(keys) ⇒ Object


4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
# File 'lib/tk.rb', line 4073

def __check_available_configure_options(keys)
  availables = self.current_configinfo.keys

  # add non-standard keys
  availables |= __font_optkeys.map{|k|
    [k.to_s, "latin#{k}", "ascii#{k}", "kanji#{k}"]
  }.flatten
  availables |= __methodcall_optkeys.keys.map{|k| k.to_s}
  availables |= __keyonly_optkeys.keys.map{|k| k.to_s}

  keys = _symbolkey2str(keys)
  keys.delete_if{|k, v| !(availables.include?(k))}
end

#cget(slot) ⇒ Object


3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
# File 'lib/tk.rb', line 3974

def cget(slot)
  unless TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
    __cget_core(slot)
  else
    begin
      __cget_core(slot)
    rescue => e
      if current_configinfo.has_key?(slot.to_s)
        # error on known option
        fail e
      else
        # unknown option
        nil
      end
    end
  end
end

#cget_strict(slot) ⇒ Object


3991
3992
3993
3994
# File 'lib/tk.rb', line 3991

def cget_strict(slot)
  # never use TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
  __cget_core(slot)
end

#cget_tkstring(option) ⇒ Object


3885
3886
3887
3888
3889
# File 'lib/tk.rb', line 3885

def cget_tkstring(option)
  opt = option.to_s
  fail ArgumentError, "Invalid option `#{option.inspect}'" if opt.length == 0
  tk_call_without_enc(*(__cget_cmd << "-#{opt}"))
end

#config_hash_kv(keys, enc_mode = nil, conf = nil) ⇒ Object


3870
3871
3872
# File 'lib/tk.rb', line 3870

def config_hash_kv(keys, enc_mode = nil, conf = nil)
  hash_kv(__conv_keyonly_opts(keys), enc_mode, conf)
end

#configinfo(slot = nil) ⇒ Object


4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
# File 'lib/tk.rb', line 4884

def configinfo(slot = nil)
  if slot && TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
    begin
      __configinfo_core(slot)
    rescue
      Array.new(__configinfo_struct.values.max).unshift(slot.to_s)
    end
  else
    __configinfo_core(slot)
  end
end

#configure(slot, value = None) ⇒ Object


4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
# File 'lib/tk.rb', line 4087

def configure(slot, value=None)
  unless TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
    __configure_core(slot, value)
  else
    if slot.kind_of?(Hash)
      begin
        __configure_core(slot)
      rescue
        slot = __check_available_configure_options(slot)
        __configure_core(slot) unless slot.empty?
      end
    else
      begin
        __configure_core(slot, value)
      rescue => e
        if current_configinfo.has_key?(slot.to_s)
          # error on known option
          fail e
        else
          # unknown option
          nil
        end
      end
    end
  end
  self
end

#configure_cmd(slot, value) ⇒ Object


4115
4116
4117
# File 'lib/tk.rb', line 4115

def configure_cmd(slot, value)
  configure(slot, install_cmd(value))
end

#current_configinfo(slot = nil) ⇒ Object


4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
# File 'lib/tk.rb', line 4896

def current_configinfo(slot = nil)
  if TkComm::GET_CONFIGINFO_AS_ARRAY
    if slot
      org_slot = slot
      begin
        conf = configinfo(slot)
        if ( ! __configinfo_struct[:alias] \
            || conf.size > __configinfo_struct[:alias] + 1 )
          return {conf[0] => conf[-1]}
        end
        slot = conf[__configinfo_struct[:alias]]
      end while(org_slot != slot)
      fail RuntimeError,
        "there is a configure alias loop about '#{org_slot}'"
    else
      ret = {}
      configinfo().each{|cnf|
        if ( ! __configinfo_struct[:alias] \
            || cnf.size > __configinfo_struct[:alias] + 1 )
          ret[cnf[0]] = cnf[-1]
        end
      }
      ret
    end
  else # ! TkComm::GET_CONFIGINFO_AS_ARRAY
    ret = {}
    configinfo(slot).each{|key, cnf|
      ret[key] = cnf[-1] if cnf.kind_of?(Array)
    }
    ret
  end
end