Module: TkConfigMethod

Includes:
TkTreatFont, TkUtil
Included in:
Tk::Tcllib::Tkpiechart::ConfigMethod, TkObject
Defined in:
ext/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_str, #num_or_str, number, #number, string, #string, uninstall_cmd

Class Method Details

.__IGNORE_UNKNOWN_CONFIGURE_OPTION__Object



3564
3565
3566
# File 'ext/lib/tk.rb', line 3564

def TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
  @mode || false
end

.__set_IGNORE_UNKNOWN_CONFIGURE_OPTION__!(mode) ⇒ Object



3567
3568
3569
3570
# File 'ext/lib/tk.rb', line 3567

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



3695
3696
3697
# File 'ext/lib/tk.rb', line 3695

def [](id)
  cget(id)
end

#[]=(id, val) ⇒ Object



3699
3700
3701
3702
# File 'ext/lib/tk.rb', line 3699

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

#__check_available_configure_options(keys) ⇒ Object



3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
# File 'ext/lib/tk.rb', line 3886

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



3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
# File 'ext/lib/tk.rb', line 3787

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



3804
3805
3806
3807
# File 'ext/lib/tk.rb', line 3804

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

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



3689
3690
3691
# File 'ext/lib/tk.rb', line 3689

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

#configinfo(slot = nil) ⇒ Object



4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
# File 'ext/lib/tk.rb', line 4696

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



3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
# File 'ext/lib/tk.rb', line 3900

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



3928
3929
3930
# File 'ext/lib/tk.rb', line 3928

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

#current_configinfo(slot = nil) ⇒ Object



4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
# File 'ext/lib/tk.rb', line 4708

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{|conf|
        if ( ! __configinfo_struct[:alias] \
            || conf.size > __configinfo_struct[:alias] + 1 )
          ret[conf[0]] = conf[-1]
        end
      }
      ret
    end
  else # ! TkComm::GET_CONFIGINFO_AS_ARRAY
    ret = {}
    configinfo(slot).each{|key, conf| 
      ret[key] = conf[-1] if conf.kind_of?(Array)
    }
    ret
  end
end