Class: Wx::App

Inherits:
Object
  • Object
show all
Defined in:
lib/wx/classes/app.rb

Overview

Controller class which creates and manages all windows.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.run(&block) ⇒ Object

Convenience class method to create simple apps. Starts an application main_loop, setting up initial windows etc as specified in the passed block. block



10
11
12
13
14
15
16
17
# File 'lib/wx/classes/app.rb', line 10

def self.run(&block)
  app_klass = Class.new(self)
  app_klass.class_eval do
    define_method(:on_init, &block)
  end
  the_app = app_klass.new
  the_app.main_loop
end

Instance Method Details

#gc_stress(interval = 1) ⇒ Object

For use in development only, of no practical use in production code. This method causes Ruby’s garbage collection to run (roughly) at interval interval (seconds) - the default is 1, i.e. every second. This should help ferret out bugs in memory management more quickly.



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/wx/classes/app.rb', line 39

def gc_stress(interval = 1)
  # Ruby 1.9 provides this built-in version, but doesn't like the 1.8
  # version at all - results in frequent segfaults.
  if RUBY_VERSION >= "1.9.0"
    GC.stress
  else # Ruby 1.8
    t = Wx::Timer.new(self, 9999)
    evt_timer(9999) { Thread.pass }
    Thread.new { loop { sleep interval; GC.start } }
    t.start(100)
  end
end

#is_main_loop_runningObject

This is a class method in Wx, but permit it to be an instance method in wxRuby



21
22
23
# File 'lib/wx/classes/app.rb', line 21

def is_main_loop_running
  Wx::App.is_main_loop_running
end