Module: TeekDemo Private
- Defined in:
- lib/teek/demo_support.rb
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Class Attribute Summary collapse
- .app ⇒ Object private
Class Method Summary collapse
- .active? ⇒ Boolean private
-
.after_idle(timeout: 60, &block) ⇒ Object
private
Run block once when event loop is idle.
-
.delay(test: 100, record: 1000) ⇒ Object
private
Get appropriate delay for current mode.
-
.finish ⇒ Object
private
Signal completion and exit cleanly.
-
.on_visible(window: '.', timeout: 60, &block) ⇒ Object
private
Run block once when window becomes visible.
- .recording? ⇒ Boolean private
-
.signal_ready ⇒ Object
private
Signal test harness that sample is ready (without exiting).
-
.signal_recording_ready(window: '.') ⇒ Object
private
Signal recording harness that window is visible and ready to record.
- .testing? ⇒ Boolean private
Class Attribute Details
.app ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
29 30 31 |
# File 'lib/teek/demo_support.rb', line 29 def app @app end |
Class Method Details
.active? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
39 40 41 |
# File 'lib/teek/demo_support.rb', line 39 def active? testing? || recording? end |
.after_idle(timeout: 60, &block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Run block once when event loop is idle. Use when window is already created before binding can be set up.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/teek/demo_support.rb', line 71 def after_idle(timeout: 60, &block) return unless active? raise ArgumentError, "block required" unless block raise "TeekDemo.app not set" unless app @demo_started = false app.after_idle { next if @demo_started @demo_started = true signal_recording_ready if recording? app.after(timeout * 1000) { finish } block.call } end |
.delay(test: 100, record: 1000) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get appropriate delay for current mode
44 45 46 |
# File 'lib/teek/demo_support.rb', line 44 def delay(test: 100, record: 1000) recording? ? record : test end |
.finish ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Signal completion and exit cleanly. Handles TK_READY_PORT (test) and TK_STOP_PORT (record).
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/teek/demo_support.rb', line 132 def finish signal_ready if (port = ENV['TK_STOP_PORT']) Thread.new do begin sock = TCPSocket.new('127.0.0.1', port.to_i) sock.read(1) # Block until harness sends byte or closes sock.close rescue StandardError end app.after(0) { app.destroy('.') } end else app.after(0) { app.destroy('.') } end end |
.on_visible(window: '.', timeout: 60, &block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Run block once when window becomes visible.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/teek/demo_support.rb', line 50 def on_visible(window: '.', timeout: 60, &block) return unless active? raise ArgumentError, "block required" unless block raise "TeekDemo.app not set" unless app @demo_started = false app.bind(window, 'Visibility') do next if @demo_started @demo_started = true signal_recording_ready(window: window) if recording? # Safety timeout app.after(timeout * 1000) { finish } app.after(50) { block.call } end end |
.recording? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
35 36 37 |
# File 'lib/teek/demo_support.rb', line 35 def recording? !!ENV['TK_RECORD'] end |
.signal_ready ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Signal test harness that sample is ready (without exiting)
120 121 122 123 124 125 126 127 128 |
# File 'lib/teek/demo_support.rb', line 120 def signal_ready $stdout.flush if (port = ENV.delete('TK_READY_PORT')) begin TCPSocket.new('127.0.0.1', port.to_i).close rescue StandardError end end end |
.signal_recording_ready(window: '.') ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Signal recording harness that window is visible and ready to record. Polls until geometry is valid, then signals via TCP.
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/teek/demo_support.rb', line 91 def signal_recording_ready(window: '.') return unless (port = ENV['TK_STOP_PORT']) return if @_recording_ready_sent try_signal = proc do app.tcl_eval('update idletasks') width = app.winfo.width(window) height = app.winfo.height(window) if width >= 10 && height >= 10 @_recording_ready_sent = true @_initial_geometry = [width, height] begin sock = TCPSocket.new('127.0.0.1', port.to_i) sock.write("R:#{width}x#{height}") sock.close rescue StandardError => e $stderr.puts "TeekDemo: signal error: #{e.}" end else app.after(10) { try_signal.call } end end try_signal.call end |
.testing? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
31 32 33 |
# File 'lib/teek/demo_support.rb', line 31 def testing? !!ENV['TK_READY_PORT'] end |