Class: DynVar
Overview
Variable binding for widget : (shower/editor widget) <==> (int/float/string/bool variable) ###########
Class Method Summary collapse
Instance Method Summary collapse
- #destroy ⇒ Object
- #do_notification ⇒ Object
- #get_as_bool ⇒ Object
-
#initialize(v, name = "") ⇒ DynVar
constructor
A new instance of DynVar.
- #name ⇒ Object
- #observ(&blk) ⇒ Object
- #set_as_bool(v) ⇒ Object
- #set_name(name) ⇒ Object
- #set_trace(on) ⇒ Object
- #tr(old, neww) ⇒ Object
- #value ⇒ Object
- #value=(v) ⇒ Object
Constructor Details
#initialize(v, name = "") ⇒ DynVar
Returns a new instance of DynVar.
62 |
# File 'lib/ruiby_gtk/dyn_var.rb', line 62 def initialize(v,name="") @value=v ; @abo={} ; @name=name end |
Class Method Details
.save_stock ⇒ Object
58 59 60 |
# File 'lib/ruiby_gtk/dyn_var.rb', line 58 def save_stock (@ldyn||[]).each { |v| Ruiby.stock_put(v.name, v.value.to_s) if v.name } end |
.stock(name, defv) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ruiby_gtk/dyn_var.rb', line 48 def stock(name,defv) v= Ruiby.stock_get(name,defv) var=DynVar.new(v,name) if ! @ldyn @ldyn=[] at_exit { DynVar.save_stock } end @ldyn << var var end |
Instance Method Details
#destroy ⇒ Object
97 98 99 |
# File 'lib/ruiby_gtk/dyn_var.rb', line 97 def destroy() @abo=[] end |
#do_notification ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/ruiby_gtk/dyn_var.rb', line 66 def do_notification() return if @abo.size==0 abo=@abo.clone return if abo.size==0 there=self gui_invoke_wait { after(100) { abo.each { |a,b| b.call(there.value) } } } end |
#get_as_bool ⇒ Object
83 84 85 86 87 88 89 90 |
# File 'lib/ruiby_gtk/dyn_var.rb', line 83 def get_as_bool() case @value when Numeric then @value!=0 when String then @value && @value.length>0 else !! @value end end |
#name ⇒ Object
64 |
# File 'lib/ruiby_gtk/dyn_var.rb', line 64 def name() @name end |
#observ(&blk) ⇒ Object
65 |
# File 'lib/ruiby_gtk/dyn_var.rb', line 65 def observ(&blk) @abo[caller] = blk ; blk.call(@value) end |
#set_as_bool(v) ⇒ Object
75 76 77 78 79 80 81 82 |
# File 'lib/ruiby_gtk/dyn_var.rb', line 75 def set_as_bool(v) @value=case @value when Numeric then v ? 1 : 0 when String then v ? "1" : "" else !!v end do_notification() end |
#set_name(name) ⇒ Object
63 |
# File 'lib/ruiby_gtk/dyn_var.rb', line 63 def set_name(name) @name=name end |
#set_trace(on) ⇒ Object
91 92 93 |
# File 'lib/ruiby_gtk/dyn_var.rb', line 91 def set_trace(on) @trace=on end |
#tr(old, neww) ⇒ Object
94 95 96 |
# File 'lib/ruiby_gtk/dyn_var.rb', line 94 def tr(old,neww) puts "trace var from #{old} to #{neww}" if @trace end |
#value ⇒ Object
74 |
# File 'lib/ruiby_gtk/dyn_var.rb', line 74 def value() @value end |
#value=(v) ⇒ Object
73 |
# File 'lib/ruiby_gtk/dyn_var.rb', line 73 def value=(v) (tr(@value,v); @value=v ; do_notification()) if @value!=v end |