In Files

  • tk/lib/tk/optiondb.rb

Class/Module Index [+]

Quicksearch

TkOption

Public Class Methods

add(pat, value, pri=None) click to toggle source
 
               # File tk/lib/tk/optiondb.rb, line 24
def add(pat, value, pri=None)
  # if $SAFE >= 4
  #   fail SecurityError, "can't call 'TkOptionDB.add' at $SAFE >= 4"
  # end
  tk_call('option', 'add', pat, value, pri)
end
            
clear() click to toggle source
 
               # File tk/lib/tk/optiondb.rb, line 30
def clear
  # if $SAFE >= 4
  #   fail SecurityError, "can't call 'TkOptionDB.crear' at $SAFE >= 4"
  # end
  tk_call_without_enc('option', 'clear')
end
            
eval_under_random_base(parent = nil, &b) click to toggle source
 
               # File tk/lib/tk/optiondb.rb, line 359
def eval_under_random_base(parent = nil, &b)
  new_klass = __create_new_class(__get_random_basename(),
                                 [], 4, false, parent)
  ret = new_klass.class_eval(&b) if block_given?
  __remove_methods_of_proc_class(new_klass)
  new_klass.freeze
  ret
end
            
get(win, name, klass) click to toggle source
 
               # File tk/lib/tk/optiondb.rb, line 36
def get(win, name, klass)
  tk_call('option', 'get', win ,name, klass)
end
            
new_proc_class(klass, func, safe = 4, add = false, parent = nil, &b) click to toggle source

define new proc class : If you want to modify the new class or create a new subclass, you must do such operation in the block parameter. Because the created class is flozen after evaluating the block.

 
               # File tk/lib/tk/optiondb.rb, line 350
def new_proc_class(klass, func, safe = 4, add = false, parent = nil, &b)
  new_klass = __create_new_class(klass, func, safe, add, parent)
  new_klass.class_eval(&b) if block_given?
  __remove_methods_of_proc_class(new_klass)
  new_klass.freeze
  new_klass
end
            
new_proc_class_random(klass, func, safe = 4, add = false, &b) click to toggle source
 
               # File tk/lib/tk/optiondb.rb, line 369
def new_proc_class_random(klass, func, safe = 4, add = false, &b)
  eval_under_random_base(){
    TkOptionDB.new_proc_class(klass, func, safe, add, self, &b)
  }
end
            
read_entries(file, f_enc=nil) click to toggle source
 
               # File tk/lib/tk/optiondb.rb, line 45
def read_entries(file, f_enc=nil)
  if TkCore::INTERP.safe?
    fail SecurityError,
      "can't call 'TkOptionDB.read_entries' on a safe interpreter"
  end

  i_enc = ((Tk.encoding)? Tk.encoding : Tk.encoding_system)

  unless f_enc
    f_enc = i_enc
  end

  ent = []
  cline = ''
  open(file, 'r') {|f|
    while line = f.gets
      #cline += line.chomp!
      cline.concat(line.chomp!)
      case cline
      when /\\$/    # continue
        cline.chop!
        next
      when /^\s*(!|#)/     # coment
        cline = ''
        next
      when /^([^:]+):(.*)$/
        pat = $1.strip
        val = $2.lstrip
        p "ResourceDB: #{[pat, val].inspect}" if $DEBUG
        pat = TkCore::INTERP._toUTF8(pat, f_enc)
        pat = TkCore::INTERP._fromUTF8(pat, i_enc)
        val = TkCore::INTERP._toUTF8(val, f_enc)
        val = TkCore::INTERP._fromUTF8(val, i_enc)
        ent << [pat, val]
        cline = ''
      else          # unknown --> ignore
        cline = ''
        next
      end
    end
  }
  ent
end
            
read_file(file, pri=None) click to toggle source
Alias for: readfile
read_with_encoding(file, f_enc=nil, pri=None) click to toggle source
 
               # File tk/lib/tk/optiondb.rb, line 90
  def read_with_encoding(file, f_enc=nil, pri=None)
    # try to read the file as an OptionDB file
    read_entries(file, f_enc).each{|pat, val|
      add(pat, val, pri)
    }

=begin
    i_enc = Tk.encoding()

    unless f_enc
      f_enc = i_enc
    end

    cline = ''
    open(file, 'r') {|f|
      while line = f.gets
        cline += line.chomp!
        case cline
        when /\\$/    # continue
          cline.chop!
          next
        when /^\s*!/     # coment
          cline = ''
          next
        when /^([^:]+):\s(.*)$/
          pat = $1
          val = $2
          p "ResourceDB: #{[pat, val].inspect}" if $DEBUG
          pat = TkCore::INTERP._toUTF8(pat, f_enc)
          pat = TkCore::INTERP._fromUTF8(pat, i_enc)
          val = TkCore::INTERP._toUTF8(val, f_enc)
          val = TkCore::INTERP._fromUTF8(val, i_enc)
          add(pat, val, pri)
          cline = ''
        else          # unknown --> ignore
          cline = ''
          next
        end
      end
    }
=end
  end
            
readfile(file, pri=None) click to toggle source
 
               # File tk/lib/tk/optiondb.rb, line 39
def readfile(file, pri=None)
  tk_call('option', 'readfile', file, pri)
end
            
Also aliased as: read_file

Public Instance Methods

mutex() click to toggle source
 
               # File tk/lib/tk/optiondb.rb, line 13
def mutex; @mutex; end