Class: Nobbie::Wx::ApplicationLauncher

Inherits:
Object
  • Object
show all
Defined in:
lib/nobbie/wx/launcher.rb

Overview

:nodoc:

Constant Summary collapse

AUT_NOT_WX_APP =
"APPLICATION_UNDER_TEST must be an instance of a Wx::App"
AUT_NOT_DEFINED =
"APPLICATION_UNDER_TEST must be set to be an instance of the application you wish to test"

Instance Method Summary collapse

Constructor Details

#initializeApplicationLauncher

Returns a new instance of ApplicationLauncher.



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/nobbie/wx/launcher.rb', line 19

def initialize
  begin
    app = get_application
    unless app.is_a?(Wxruby2::App)
      handle(AUT_NOT_WX_APP)
    end
  rescue NameError => e
    handle(AUT_NOT_DEFINED)
  end
  @app = app
end

Instance Method Details

#get_applicationObject



69
70
71
# File 'lib/nobbie/wx/launcher.rb', line 69

def get_application
  APPLICATION_UNDER_TEST
end

#handle(message) ⇒ Object



65
66
67
# File 'lib/nobbie/wx/launcher.rb', line 65

def handle(message)
  Kernel.raise message
end

#startObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/nobbie/wx/launcher.rb', line 38

def start
  puts "\n>> Starting application: #{@app.class}"
  start = Time.now

  @app_thread = Thread.new {
    @app.extend(ApplicationUnderTest)
    @app.init_timer
    @app.main_loop
  }

  @app_thread.priority = -1

  sleep 1
  finish = Time.now
  puts "\n>> Took #{finish-start} seconds to start application"
  Thread.pass
end

#stopObject



56
57
58
59
60
61
62
63
# File 'lib/nobbie/wx/launcher.rb', line 56

def stop
  puts "\n>> Stopping application: #{@app.class}\n"

  #todo: tbis would seem a polite way to exit .. but causes Bus/Segmentation Errors on OSX.
  #@app.top_window.destroy
  #@app.exit_main_loop
  #@app = nil
end

#with_applicationObject



31
32
33
34
35
36
# File 'lib/nobbie/wx/launcher.rb', line 31

def with_application
  start
  result = yield
  stop
  result
end