This method notes in Ruby the ownership of the timer, from both sides, and sets up an event hook if needed for the window’s destruction.
Source Code
# File wx/classes/timer.rb, line 30 def setup_owner_destruction_hook(new_owner) this_timer = self # Class-wide list of global (unowned) timers @@__unowned_timers__ ||= [] # remove from list of previous owner if defined?(@__owner__) and @__owner__ @__owner__.instance_eval { @__owned_timers__.delete(this_timer) } end # If becoming global unowned timer, add to list of those timers if not new_owner @__owner__ = nil @@__unowned_timers__ << self return end # Otherwise, if previously unowned, remove from global owned @@__unowned_timers__.delete(self) @__owner__ = new_owner # Then add to list of new owner, setting destructor hook if required new_owner.instance_eval do if not defined?(@__owned_timers__) @__owned_timers__ = [] unless self.kind_of?(Wx::App) # Don't set up hook on App evt_window_destroy do | evt | # If it's the owning window being destroyed... if evt.get_event_object == self @__owned_timers__.each { | timer | timer.stop } end evt.skip end end end @__owned_timers__ << this_timer end end
<code/>and<pre/>for code samples.