module Tk::Event::Handler

Public Instance Methods

invoke(id, event) click to toggle source
# File lib/ffi-tk/event/handler.rb, line 13
def invoke(id, event)
  return unless found = @store.at(id)
  found.call(event)
end
register(tag, sequence, &block) click to toggle source
# File lib/ffi-tk/event/handler.rb, line 29
def register(tag, sequence, &block)
  id = register_block(block)
  if sequence.to_s == '%'
    Tk.interp.eval(
      @callback % [tag, '%%'.to_tcl, id, '%%'.to_tcl]
    )
  else
    Tk.interp.eval(
      @callback % [tag, sequence.to_tcl, id, sequence.to_tcl]
    )
  end
  @bound[[tag, sequence]] = block
  id
end
register_block(block) click to toggle source
# File lib/ffi-tk/event/handler.rb, line 18
def register_block(block)
  id = nil

  @mutex.synchronize do
    @store << block
    id = @store.size - 1
  end

  id
end
register_custom(block) { |id| ... } click to toggle source
# File lib/ffi-tk/event/handler.rb, line 44
def register_custom(block)
  id = register_block(block)
  yield id
  id
end
unregister(tag, sequence) click to toggle source
# File lib/ffi-tk/event/handler.rb, line 50
def unregister(tag, sequence)
  key = [tag, sequence]

  if block = @bound[key]
    Tk.execute(:bind, tag, sequence, nil)
    id = @store.index(block)
    @store[id] = nil
    @bound.delete(key)
  end
end