Sha256: 0e2768fcdb85ef07dba0bb93c26c1f31820f6d73116942dc8ae2926d608476f9

Contents?: true

Size: 1.07 KB

Versions: 53

Compression:

Stored size: 1.07 KB

Contents

require 'thread'

module Fox

  class FXApp

    alias initialize_before_thread initialize # :nodoc:

    def initialize(*args, &block)
      initialize_before_thread(*args)
      event_handler_setup
      block.call(self) if block_given?
    end

    def runOnUiThread(&block)
      @event_handler_events << block
      @event_handler_pwr.write 'e'
    end

    private

    def event_handler_setup
      if RUBY_PLATFORM =~ /mingw|mswin/i
        require 'socket'
        gs = TCPServer.open('localhost', 0)
        prd = TCPSocket.open('localhost', gs.addr[1])
        pwr = gs.accept
        gs.close
      else
        prd, pwr = IO.pipe
      end
      self.addInput(prd, Fox::INPUT_READ){ event_handler_pull(prd) }
      @event_handler_pwr = pwr
      @event_handler_events = Queue.new
    end

    def event_handler_pull(prd)
      prd.read(1)
      while !@event_handler_events.empty?
        ev = @event_handler_events.shift
        ev.call
      end
    end

  end # class FXApp

  class FXId
    def runOnUiThread(&block)
      app.runOnUiThread(&block)
    end
  end
end # module Fox

Version data entries

53 entries across 53 versions & 1 rubygems

Version Path
fxruby-1.6.48 lib/fox16/thread.rb
fxruby-1.6.48-x64-mingw32 lib/fox16/thread.rb
fxruby-1.6.48-x64-mingw-ucrt lib/fox16/thread.rb
fxruby-1.6.48-x86-mingw32 lib/fox16/thread.rb
fxruby-1.6.47 lib/fox16/thread.rb
fxruby-1.6.47-x64-mingw-ucrt lib/fox16/thread.rb
fxruby-1.6.47-x64-mingw32 lib/fox16/thread.rb
fxruby-1.6.47-x86-mingw32 lib/fox16/thread.rb
fxruby-1.6.46 lib/fox16/thread.rb
fxruby-1.6.46-x64-mingw32 lib/fox16/thread.rb
fxruby-1.6.46-x64-mingw-ucrt lib/fox16/thread.rb
fxruby-1.6.46-x86-mingw32 lib/fox16/thread.rb
fxruby-1.6.45 lib/fox16/thread.rb
fxruby-1.6.45-x64-mingw32 lib/fox16/thread.rb
fxruby-1.6.45-x64-mingw-ucrt lib/fox16/thread.rb
fxruby-1.6.45-x86-mingw32 lib/fox16/thread.rb
fxruby-1.6.44 lib/fox16/thread.rb
fxruby-1.6.44-x64-mingw32 lib/fox16/thread.rb
fxruby-1.6.44-x86-mingw32 lib/fox16/thread.rb
fxruby-1.6.43 lib/fox16/thread.rb