class Tk::BLT::Watch - tk-0.1.2 Documentation

# class Tk::BLT::Watch

### Constants

BLT_WATCH_ID
TkCommandNames
WATCH_ID_TBL

### Public Class Methods

names(state = None) click to toggle source

    # File lib/tkextlib/blt/watch.rb, line 28
    def self.names(state = None)
      lst = tk_split_list(tk_call('::blt::watch', 'names', state))
      WATCH_ID_TBL.mutex.synchronize{
        lst.collect{|name|
          WATCH_ID_TBL[name] || name
        }
      }
    end

new(name = nil, keys = {}) click to toggle source

    # File lib/tkextlib/blt/watch.rb, line 52
    def initialize(name = nil, keys = {})
      if name.kind_of?(Hash)
        keys = name
        name = nil
      end

      if name
        @id = name.to_s
      else
        BLT_WATCH_ID.mutex.synchronize{
          @id = BLT_WATCH_ID.join(TkCore::INTERP._ip_id_)
          BLT_WATCH_ID[1].succ!
        }
      end

      @path = @id

      WATCH_ID_TBL.mutex.synchronize{
        WATCH_ID_TBL[@id] = self
      }
      tk_call('::blt::watch', 'create', @id, *hash_kv(keys))
    end

### Public Instance Methods

activate() click to toggle source

    # File lib/tkextlib/blt/watch.rb, line 75
    def activate
      tk_call('::blt::watch', 'activate', @id)
      self
    end

cget(key) click to toggle source

    # File lib/tkextlib/blt/watch.rb, line 158
    def cget(key)
      unless TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
        cget_strict(key)
      else
        begin
          cget_strict(key)
        rescue => e
          if current_configinfo.has_key?(key.to_s)
            # error on known option
            fail e
          else
            # unknown option
            nil
          end
        end
      end
    end

cget_strict(key) click to toggle source

    # File lib/tkextlib/blt/watch.rb, line 150
    def cget_strict(key)
      key = key.to_s
      begin
        info.assoc(key)[1]
      rescue
        fail ArgumentError, "unknown option '#{key}'"
      end
    end

configinfo(slot = nil) click to toggle source

    # File lib/tkextlib/blt/watch.rb, line 133
    def configinfo(slot = nil)
      if slot
        slot = slot.to_s
        v = cget(slot)
        if TkComm::GET_CONFIGINFO_AS_ARRAY
          [slot, v]
        else
          {slot=>v}
        end
      else
        if TkComm::GET_CONFIGINFO_AS_ARRAY
          info
        else
          Hash[*(info.flatten)]
        end
      end
    end

deactivate() click to toggle source

    # File lib/tkextlib/blt/watch.rb, line 79
    def deactivate
      tk_call('::blt::watch', 'deactivate', @id)
      self
    end

delete() click to toggle source

    # File lib/tkextlib/blt/watch.rb, line 83
    def delete
      tk_call('::blt::watch', 'delete', @id)
      self
    end

info() click to toggle source

    # File lib/tkextlib/blt/watch.rb, line 87
    def info
      ret = []
      lst = tk_split_simplelist(tk_call('::blt::watch', 'info', @id))
      until lst.empty?
        k, v, *lst = lst
        k = k[1..-1]
        case k
        when /^(#{__strval_optkeys.join('|')})$/
          # do nothing

        when /^(#{__numval_optkeys.join('|')})$/
          begin
            v = number(v)
          rescue
            v = nil
          end

        when /^(#{__numstrval_optkeys.join('|')})$/
          v = num_or_str(v)

        when /^(#{__boolval_optkeys.join('|')})$/
          begin
            v = bool(v)
          rescue
            v = nil
          end

        when /^(#{__listval_optkeys.join('|')})$/
          v = simplelist(v)

        when /^(#{__numlistval_optkeys.join('|')})$/
          v = list(v)

        else
          if v.index('{')
            v = tk_split_list(v)
          else
            v = tk_tcl2ruby(v)
          end
        end

        ret << [k, v]
      end

      ret
    end

mutex() click to toggle source

    # File lib/tkextlib/blt/watch.rb, line 20
    def mutex; @mutex; end

### Private Instance Methods

__boolval_optkeys() click to toggle source

    # File lib/tkextlib/blt/watch.rb, line 42
    def __boolval_optkeys
      ['active']
    end

__config_cmd() click to toggle source

    # File lib/tkextlib/blt/watch.rb, line 47
    def __config_cmd
      ['::blt::watch', 'configure', self.path]
    end

__numval_optkeys() click to toggle source

    # File lib/tkextlib/blt/watch.rb, line 37
    def __numval_optkeys
      ['maxlevel']
    end