Class: Iup::Timer
- Inherits:
-
Object
- Object
- Iup::Timer
- Extended by:
- AttributeBuilders
- Includes:
- CallbackSetter
- Defined in:
- lib/wrapped/timer.rb
Overview
The timer is used to trigger a callback function at regular intervals without interrupting the application's main event loop. It can be used to safely update the user interface.
For example, the following creates a timer which counts down from 10, updating a label's title. When the count reaches 0, the application will close.
count = 10
timer = Iup::Timer.new do |t|
t.time = 1000
t.action_cb = ->{
if count.zero?
Iup::CLOSE
else
count -= 1
label.title = "Time remaining: #{count}"
Iup::DEFAULT
end
}
end
Instance Attribute Summary collapse
-
#handle ⇒ Object
readonly
Unique reference to widget.
Instance Method Summary collapse
-
#action_cb=(callback) ⇒ Object
--.
-
#destroy ⇒ Object
must be called when Timer is finished with.
-
#initialize {|_self| ... } ⇒ Timer
constructor
A new instance of Timer.
-
#run ⇒ Object
:attr: run Values 'yes' / 'no' to start or stop the timer.
-
#time ⇒ Object
:attr: time The time interval before the action_cb is called, in milliseconds.
-
#wid ⇒ Object
:attr_reader: wid The native serial number of the timer: -1 if not running.
Methods included from AttributeBuilders
define_attribute, define_id_attribute, define_id_reader, define_id_writer, define_property_attribute, define_property_reader, define_property_writer, define_reader, define_writer
Methods included from CallbackSetter
Constructor Details
Instance Attribute Details
#handle ⇒ Object (readonly)
Unique reference to widget.
31 32 33 |
# File 'lib/wrapped/timer.rb', line 31 def handle @handle end |
Instance Method Details
#action_cb=(callback) ⇒ Object
--
71 72 73 74 75 76 77 78 79 |
# File 'lib/wrapped/timer.rb', line 71 def action_cb= callback unless callback.arity.zero? raise ArgumentError, 'action_cb must take 0 arguments' end cb = Proc.new do |ih| callback.call end define_callback(cb, 'ACTION_CB', :plain) end |
#destroy ⇒ Object
must be called when Timer is finished with
41 42 43 |
# File 'lib/wrapped/timer.rb', line 41 def destroy IupLib.IupDestroy @handle end |
#run ⇒ Object
:attr: run Values 'yes' / 'no' to start or stop the timer.
55 |
# File 'lib/wrapped/timer.rb', line 55 define_attribute :run |
#time ⇒ Object
:attr: time The time interval before the action_cb is called, in milliseconds.
50 |
# File 'lib/wrapped/timer.rb', line 50 define_attribute :time |
#wid ⇒ Object
:attr_reader: wid The native serial number of the timer: -1 if not running.
60 |
# File 'lib/wrapped/timer.rb', line 60 define_reader :wid |