Sha256: 63f3973760b919c37947ddd72f6f3fe399808b2796eb9bb4b6911a500c7905f9
Contents?: true
Size: 1.3 KB
Versions: 3
Compression:
Stored size: 1.3 KB
Contents
module Tk module Event module Handler data = Data::PROPERTIES.transpose[0].join(' ').gsub(/%/, '%%') @callback = %(bind %s %s { ::RubyFFI::event %d %s #{data} }) @store = [] @bound = {} @mutex = Mutex.new module_function def invoke(id, event) return unless found = @store.at(id) found.call(event) end def register_block(block) id = nil @mutex.synchronize{ @store << block id = @store.size - 1 } return id end 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 def register_custom(block) id = register_block(block) yield id id end 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 end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
ffi-tk-2010.08.23 | lib/ffi-tk/event/handler.rb |
ffi-tk-2010.08 | lib/ffi-tk/event/handler.rb |
ffi-tk-2010.06 | lib/ffi-tk/event/handler.rb |