Class: Hornetseye::X11Display

Inherits:
Object
  • Object
show all
Defined in:
lib/hornetseye-xorg/x11display.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.new(name = ENV[ 'DISPLAY' ]) ⇒ Object



26
27
28
29
30
31
# File 'lib/hornetseye-xorg/x11display.rb', line 26

def new( name = ENV[ 'DISPLAY' ] )
  if name.nil? and ENV[ 'DISPLAY' ].nil?
    raise "DISPLAY variable was not set"
  end
  orig_new name
end

.orig_newObject



24
# File 'lib/hornetseye-xorg/x11display.rb', line 24

alias_method :orig_new, :new

.show(*args, &action) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/hornetseye-xorg/x11display.rb', line 33

def show( *args, &action )
  options = args.last.is_a?( Hash ) ? args.pop : {}
  options = { :title => 'Hornetseye', :border => true,
              :output => XImageOutput }.merge options
  unless action
    frame, width, height = *args
    width  ||= frame.width
    height ||= ( width.to_f * frame.height / frame.width ).round
    display = options[ :display ] || new
    output = options[ :output ].new
    output.write frame
    window = X11Window.new display, output, width, height, options
    window.title = options[ :title ]
    begin
      window.show
      display.event_loop
    ensure
      window.close
    end
    frame
  else
    width, height = *args
    display = options[ :display ] || new
    result = action.call display
    width  ||= result.shape[0]
    height ||= ( width.to_f * result.shape[1] / result.shape[0] ).round
    output = options[ :output ].new
    window = X11Window.new display, output, width, height, options
    window.title = options[ :title ]
    begin
      window.show
      t = Time.new.to_f
      while true
        t += 1.0 / options[ :frame_rate ] if options[ :frame_rate ]
        output.write result
        delay = t - Time.new.to_f
        if delay > 0
          display.event_loop delay
        else
          display.process_events
        end
        break unless display.status?
        result = action.call display
      end
    ensure
      window.close
    end
    result
  end
end

Instance Method Details

#event_loop(timeout = INFINITE) ⇒ Object



88
89
90
91
# File 'lib/hornetseye-xorg/x11display.rb', line 88

def event_loop( timeout = INFINITE )
  timeout *= 1000 unless timeout == INFINITE
  orig_event_loop timeout
end

#orig_event_loopObject



86
# File 'lib/hornetseye-xorg/x11display.rb', line 86

alias_method :orig_event_loop, :event_loop