Maintenance of Ruby 2.0.0 ended on February 24, 2016. Read more

In Files

  • tk/lib/tk/optionobj.rb

Class/Module Index [+]

Quicksearch

Tk::OptionObj

Public Class Methods

new(hash = nil) click to toggle source
 
               # File tk/lib/tk/optionobj.rb, line 16
def initialize(hash = nil)
  super()
  @observ = []
  update_without_notify(_symbolkey2str(hash)) if hash
end
            

Public Instance Methods

+(hash) click to toggle source
 
               # File tk/lib/tk/optionobj.rb, line 162
def +(hash)
  unless hash.kind_of?(Hash)
    fail ArgumentError, "expect a Hash"
  end
  new_obj = self.dup
  new_obj.update_without_notify(_symbolkey2str(hash))
  new_obj
end
            
[](key) click to toggle source
 
               # File tk/lib/tk/optionobj.rb, line 186
def [](key)
  super(key.to_s)
end
            
Also aliased as: cget
[]=(key, val) click to toggle source
 
               # File tk/lib/tk/optionobj.rb, line 196
def []=(key, val)
  store(key,val)
end
            
apply(target = nil) click to toggle source
Alias for: notify
assign(*wins) click to toggle source
 
               # File tk/lib/tk/optionobj.rb, line 58
def assign(*wins)
  # win :=
  #   widget             #==> call widget.configure(hash)
  #   [widget]           #==> call widget.configure(hash)
  #   [widget, nil, {src=>target, ... }]
  #                      #==> call widget.configure(hash)
  #                               with converting hash-key
  #   [widget, method]   #==> call widget.method(hash)
  #   [widget, method, {src=>target, ... }]
  #                      #==> call widget.method(hash)
  #                               with converting hash-key
  #   [widget [receiver, method, arg, ... ]]
  #                      #==> call receiver.method(arg, ... , hash)
  #   [widget [receiver, method, arg, ... ], {src=>target, ... }]
  #                      #==> call receiver.method(arg, ... , hash)
  #                               with onverting hash-key
  #
  # src := option_name_on_optobj
  #
  # target :=
  #   nil                #==> not use the src
  #   option_name_on_target_widget
  #   [ option_name_on_target_widget, ... ]
  #                      #==> set all of them
  #
  wins.each{|win|
    _remove_win(win)
    @observ << win
    notify(win)
  }
  self
end
            
cget(key) click to toggle source
Alias for: []
configure(key, value=nil) click to toggle source
 
               # File tk/lib/tk/optionobj.rb, line 178
def configure(key, value=nil)
  if key.kind_of?(Hash)
    update(key)
  else
    store(key,value)
  end
end
            
notify(target = nil) click to toggle source
 
               # File tk/lib/tk/optionobj.rb, line 98
def notify(target = nil)
  if target
    targets = [target]
  elsif @observ.empty?
    return self
  else
    targets = @observ.dup
  end

  return self if empty?

  org_hash = _symbolkey2str(self)

  targets.each{|win|
    widget = receiver = win
    hash = org_hash
    begin
      if win.kind_of?(Array)
        widget, method, conv_tbl = win
        receiver = widget

        if conv_tbl
          hash = {}
          org_hash.each{|key, val|
            key = conv_tbl[key] if conv_tbl.key?(key)
            next unless key
            if key.kind_of?(Array)
              key.each{|k| hash[k] = val}
            else
              hash[key] = val
            end
          }
        end

        if method.kind_of?(Array)
          receiver, method, *args = method
          receiver.__send__(method, *(args << hash))
        elsif method
          widget.__send__(method, hash)
        else
          widget.configure(hash)
        end

      else
        widget.configure(self)
      end
    rescue => e
      if ( ( widget.kind_of?(TkObject) \
            && widget.respond_to?('exist?') \
            && ! receiver.exist? ) \
        || ( receiver.kind_of?(TkObject) \
            && receiver.respond_to?('exist?') \
            && ! receiver.exist? ) )
        @observ.delete(win)
      else
        fail e
      end
    end
  }

  self
end
            
Also aliased as: apply
observ_info() click to toggle source
 
               # File tk/lib/tk/optionobj.rb, line 22
def observ_info
  @observ.dup
end
            
observs() click to toggle source
 
               # File tk/lib/tk/optionobj.rb, line 26
def observs
  @observ.collect{|win|
    if win.kind_of?(Array)
      win[0]
    else
      win
    end
  }
end
            
replace(hash) click to toggle source
 
               # File tk/lib/tk/optionobj.rb, line 200
def replace(hash)
  super(_symbolkey2str(hash))
  notify
end
            
store(key, val) click to toggle source
 
               # File tk/lib/tk/optionobj.rb, line 191
def store(key, val)
  key = key.to_s
  super(key, val)
  notify
end
            
unassign(*wins) click to toggle source
 
               # File tk/lib/tk/optionobj.rb, line 91
def unassign(*wins)
  wins.each{|win|
    _remove_win(win)
  }
  self
end
            
update(hash) click to toggle source
 
               # File tk/lib/tk/optionobj.rb, line 173
def update(hash)
  update_without_notify(_symbolkey2str(hash))
  notify
end
            
Also aliased as: update_without_notify
update_without_notify(hash) click to toggle source
Alias for: update