Sha256: bda1701765c618c773400b609f8f093463f913853929c2f0596d26d32fb9beba

Contents?: true

Size: 1.07 KB

Versions: 15

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, &block)
      event_handler_setup
    end

    def runOnUiThread(&block)
      @event_handler_events << block
      @event_handler_pwr.write 'e' if @event_handler_pwr
    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) if prd
      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

15 entries across 15 versions & 1 rubygems

Version Path
fxruby-1.6.32-x86-mingw32 lib/fox16/thread.rb
fxruby-1.6.32-x64-mingw32 lib/fox16/thread.rb
fxruby-1.6.32 lib/fox16/thread.rb
fxruby-1.6.32.pre2-x64-mingw32 lib/fox16/thread.rb
fxruby-1.6.32.pre2-x86-mingw32 lib/fox16/thread.rb
fxruby-1.6.32.pre2 lib/fox16/thread.rb
fxruby-1.6.32.pre1 lib/fox16/thread.rb
fxruby-1.6.32.pre1-x86-mingw32 lib/fox16/thread.rb
fxruby-1.6.32.pre1-x64-mingw32 lib/fox16/thread.rb
fxruby-1.6.31-x64-mingw32 lib/fox16/thread.rb
fxruby-1.6.31-x86-mingw32 lib/fox16/thread.rb
fxruby-1.6.31 lib/fox16/thread.rb
fxruby-1.6.30-x86-mingw32 lib/fox16/thread.rb
fxruby-1.6.30-x64-mingw32 lib/fox16/thread.rb
fxruby-1.6.30 lib/fox16/thread.rb