TkCommandNames = ['tkwait'.freeze].freeze
TkVar_CB_TBL = {} TkVar_ID_TBL = {}
def ::callback
# File tk/lib/tk/variable.rb, line 55 def TkVariable.callback(id, name1, name2, op) #name1,name2,op = tk_split_list(args) #name1,name2,op = tk_split_simplelist(args) if cb_obj = TkVar_CB_TBL[id] #_get_eval_string(TkVar_CB_TBL[name1].trace_callback(name2,op)) begin _get_eval_string(cb_obj.trace_callback(name2, op)) rescue SystemExit exit(0) rescue Interrupt exit!(1) rescue Exception => e begin msg = _toUTF8(e.class.inspect) + ': ' + _toUTF8(e.message) + "\n" + "\n---< backtrace of Ruby side >-----\n" + _toUTF8(e.backtrace.join("\n")) + "\n---< backtrace of Tk side >-------" if TkCore::WITH_ENCODING msg.force_encoding('utf-8') else msg.instance_variable_set(:@encoding, 'utf-8') end rescue Exception msg = e.class.inspect + ': ' + e.message + "\n" + "\n---< backtrace of Ruby side >-----\n" + e.backtrace.join("\n") + "\n---< backtrace of Tk side >-------" end fail(e, msg) end =begin begin raise 'check backtrace' rescue # ignore backtrace before 'callback' pos = -($!.backtrace.size) end begin _get_eval_string(TkVar_CB_TBL[name1].trace_callback(name2,op)) rescue trace = $!.backtrace raise $!, "\n#{trace[0]}: #{$!.message} (#{$!.class})\n" + "\tfrom #{trace[1..pos].join("\n\tfrom ")}" end =end else '' end end
# File tk/lib/tk/variable.rb, line 282 def initialize(val="", type=nil) # @id = Tk_VARIABLE_ID.join('') begin Tk_VARIABLE_ID.mutex.synchronize{ @id = Tk_VARIABLE_ID.join(TkCore::INTERP._ip_id_) Tk_VARIABLE_ID[1].succ! } end until INTERP._invoke_without_enc('info', 'globals', @id).empty? TkVar_ID_TBL.mutex.synchronize{ TkVar_ID_TBL[@id] = self } @var = @id @elem = nil @def_default = false @default_val = nil @trace_var = nil @trace_elem = nil @trace_opts = nil @type = nil var = self @element_type = Hash.new{|k,v| var.default_value_type } self.default_value_type = type # teach Tk-ip that @id is global var INTERP._invoke_without_enc('global', @id) #INTERP._invoke('global', @id) # create and init if val.kind_of?(Hash) # assoc-array variable self[''] = 0 self.clear end self.value = val =begin if val == [] # INTERP._eval(format('global %s; set %s(0) 0; unset %s(0)', # @id, @id, @id)) elsif val.kind_of?(Array) a = [] # val.each_with_index{|e,i| a.push(i); a.push(array2tk_list(e))} # s = '"' + a.join(" ").gsub(/[\[\]$"]/, '\\\\\&') + '"' val.each_with_index{|e,i| a.push(i); a.push(e)} #s = '"' + array2tk_list(a).gsub(/[\[\]$"]/, '\\\\\&') + '"' s = '"' + array2tk_list(a).gsub(/[\[\]$"\\]/, '\\\\\&') + '"' INTERP._eval(format('global %s; array set %s %s', @id, @id, s)) elsif val.kind_of?(Hash) #s = '"' + val.to_a.collect{|e| array2tk_list(e)}.join(" ")\ # .gsub(/[\[\]$"]/, '\\\\\&') + '"' s = '"' + val.to_a.collect{|e| array2tk_list(e)}.join(" ")\ .gsub(/[\[\]$"\\]/, '\\\\\&') + '"' INTERP._eval(format('global %s; array set %s %s', @id, @id, s)) else #s = '"' + _get_eval_string(val).gsub(/[\[\]$"]/, '\\\\\&') + '"' s = '"' + _get_eval_string(val).gsub(/[\[\]$"\\]/, '\\\\\&') + '"' INTERP._eval(format('global %s; set %s %s', @id, @id, s)) end =end =begin if val.kind_of?(Hash) #s = '"' + val.to_a.collect{|e| array2tk_list(e)}.join(" ")\ # .gsub(/[\[\]$"]/, '\\\\\&') + '"' s = '"' + val.to_a.collect{|e| array2tk_list(e)}.join(" ")\ .gsub(/[\[\]$"\\]/, '\\\\\&') + '"' INTERP._eval(Kernel.format('global %s; array set %s %s', @id, @id, s)) else #s = '"' + _get_eval_string(val).gsub(/[\[\]$"]/, '\\\\\&') + '"' s = '"' + _get_eval_string(val).gsub(/[\[\]$"\\]/, '\\\\\&') + '"' INTERP._eval(Kernel.format('global %s; set %s %s', @id, @id, s)) end =end end
# File tk/lib/tk/variable.rb, line 1229 def %(other) num_or_str(self._value) % other #begin # number(self._value) % other #rescue # self._value % other #end end
# File tk/lib/tk/variable.rb, line 1183 def &(other) if other.kind_of?(Array) self.to_a & other.to_a else self.to_i & other.to_i end end
# File tk/lib/tk/variable.rb, line 1218 def *(other) num_or_str(self._value) * other #begin # number(self._value) * other #rescue # self._value * other #end end
# File tk/lib/tk/variable.rb, line 1237 def **(other) number(self._value) ** other end
# File tk/lib/tk/variable.rb, line 1197 def +(other) case other when Array self.to_a + other when String self._value + other else begin number(self._value) + other rescue self._value + other.to_s end end end
# File tk/lib/tk/variable.rb, line 1211 def -(other) if other.kind_of?(Array) self.to_a - other else number(self._value) - other end end
# File tk/lib/tk/variable.rb, line 1226 def /(other) number(self._value) / other end
# File tk/lib/tk/variable.rb, line 1283 def <=>(other) if other.kind_of?(TkVariable) begin val = other.numeric other = val rescue other = other._value end elsif other.kind_of?(Numeric) begin return self.numeric <=> other rescue return self._value <=> other.to_s end elsif other.kind_of?(Array) return self.list <=> other else return self._value <=> other end end
# File tk/lib/tk/variable.rb, line 1244 def ==(other) case other when TkVariable #self.equal?(other) self._value == other._value when String self.to_s == other when Symbol self.to_sym == other when Integer self.to_i == other when Float self.to_f == other when Array self.to_a == other when Hash # false if self is not an assoc array self._value == other else # false self._value == _get_eval_string(other) end end
# File tk/lib/tk/variable.rb, line 1268 def ===(other) if other.kind_of?(TkVariable) self.id == other.id else super end end
# File tk/lib/tk/variable.rb, line 1240 def =~(other) self._value =~ other end
# File tk/lib/tk/variable.rb, line 688 def [](*idxs) _to_default_element_type(idxs, _element_value(*idxs)) end
# File tk/lib/tk/variable.rb, line 532 def []=(*args) val = args.pop type = default_element_value_type(args) val = val._value if !type && type != :variable && val.kind_of?(TkVariable) index = args.collect{|idx| _get_eval_string(idx, true)}.join(',') _fromUTF8(INTERP._set_global_var2(@id, index, _get_eval_string(val, true))) #_fromUTF8(INTERP._set_global_var2(@id, _toUTF8(_get_eval_string(index)), # _toUTF8(_get_eval_string(val)))) #_fromUTF8(INTERP._set_global_var2(@id, _get_eval_string(index, true), # _get_eval_string(val, true))) end
# File tk/lib/tk/variable.rb, line 777 def bool TkComm.bool(_value) =begin # see Tcl_GetBoolean man-page case _value.downcase when '0', 'false', 'no', 'off' false else true end =end end
# File tk/lib/tk/variable.rb, line 789 def bool_element(*idxs) TkComm.bool(_element_value(*idxs)) end
# File tk/lib/tk/variable.rb, line 445 def clear if (is_scalar?) fail RuntimeError, 'cannot clear a scalar variable' end keys.each{|k| unset(k)} self end
# File tk/lib/tk/variable.rb, line 1159 def coerce(other) case other when TkVariable [other._value, self._value] when String [other, self.to_s] when Symbol [other, self.to_sym] when Numeric [other, self.numeric] when Array [other, self.to_a] else [other, self._value] end end
# File tk/lib/tk/variable.rb, line 148 def default_element_value_type(idxs) if idxs.kind_of?(Array) index = idxs.collect{|idx| _get_eval_string(idx, true)}.join(',') else index = _get_eval_string(idxs, true) end @element_type[index] end
# File tk/lib/tk/variable.rb, line 133 def default_proc(cmd = Proc.new) @def_default = :proc @default_val = cmd self end
#default_value is available only when the variable is an assoc array.
# File tk/lib/tk/variable.rb, line 117 def default_value(val=nil, &b) if b @def_default = :proc @default_val = proc(&b) else @def_default = :val @default_val = val end self end
# File tk/lib/tk/variable.rb, line 145 def default_value_type @type end
# File tk/lib/tk/variable.rb, line 1106 def element_lappend(idxs, *elems) if idxs.kind_of?(Array) idxs = idxs.collect{|idx| _get_eval_string(idx, true)}.join(',') end tk_call('lappend', "#{@id}(#{idxs})", *elems) self end
# File tk/lib/tk/variable.rb, line 1138 def element_lget_f(elem_idxs, idx) number(element_lget(elem_idxs, idx)).to_f end
# File tk/lib/tk/variable.rb, line 1131 def element_lget_i(elem_idxs, idx) number(element_lget(elem_idxs, idx)).to_i end
# File tk/lib/tk/variable.rb, line 1118 def element_lindex(elem_idxs, idx) if elem_idxs.kind_of?(Array) val = _element_value(*elem_idxs) else val = _element_value(elem_idxs) end tk_call('lindex', val, idx) end
# File tk/lib/tk/variable.rb, line 1146 def element_lset(elem_idxs, idx, val) if elem_idxs.kind_of?(Array) idxs = elem_idxs.collect{|i| _get_eval_string(i, true)}.join(',') end tk_call('lset', "#{@id}(#{idxs})", idx, val) self end
# File tk/lib/tk/variable.rb, line 953 def element_to_f(*idxs) number(_element_value(*idxs)).to_f end
# File tk/lib/tk/variable.rb, line 946 def element_to_i(*idxs) number(_element_value(*idxs)).to_i end
# File tk/lib/tk/variable.rb, line 963 def element_to_s(*idxs) _element_value(*idxs) end
# File tk/lib/tk/variable.rb, line 999 def element_to_sym(*idxs) _element_value(*idxs).intern end
# File tk/lib/tk/variable.rb, line 390 def eventloop_tkwait wait(false, true) end
# File tk/lib/tk/variable.rb, line 381 def eventloop_wait(check_root = false) wait(false, check_root) end
# File tk/lib/tk/variable.rb, line 417 def exist?(*elems) INTERP._invoke_without_enc('global', @id) if elems.empty? TkComm.bool(tk_call('info', 'exist', @id)) else # array index = elems.collect{|idx| _get_eval_string(idx, true)}.join(',') TkComm.bool(tk_call('info', 'exist', "#{@id}")) && TkComm.bool(tk_call('info', 'exist', "#{@id}(#{index})")) end end
# File tk/lib/tk/variable.rb, line 1154 def inspect #Kernel.format "#<TkVariable: %s>", @id '#<TkVariable: ' + @id + '>' end
# File tk/lib/tk/variable.rb, line 406 def is_hash? #ITNERP._eval("global #{@id}; array exist #{@id}") == '1' INTERP._invoke_without_enc('global', @id) # INTERP._invoke_without_enc('array', 'exist', @id) == '1' TkComm.bool(INTERP._invoke_without_enc('array', 'exist', @id)) end
# File tk/lib/tk/variable.rb, line 413 def is_scalar? ! is_hash? end
# File tk/lib/tk/variable.rb, line 429 def keys if (is_scalar?) fail RuntimeError, 'cannot get keys from a scalar variable' end #tk_split_simplelist(INTERP._eval("global #{@id}; array get #{@id}")) INTERP._invoke_without_enc('global', @id) #tk_split_simplelist(INTERP._fromUTF8(INTERP._invoke_without_enc('array', 'names', @id))) tk_split_simplelist(INTERP._invoke_without_enc('array', 'names', @id), false, true) end
# File tk/lib/tk/variable.rb, line 1102 def lappend(*elems) tk_call('lappend', @id, *elems) self end
# File tk/lib/tk/variable.rb, line 1135 def lget_f(idx) number(lget(idx)).to_f end
# File tk/lib/tk/variable.rb, line 1128 def lget_i(idx) number(lget(idx)).to_i end
# File tk/lib/tk/variable.rb, line 1114 def lindex(idx) tk_call('lindex', self._value, idx) end
# File tk/lib/tk/variable.rb, line 1029 def list #tk_split_list(value) tk_split_simplelist(_value) end
# File tk/lib/tk/variable.rb, line 1035 def list_element(*idxs) tk_split_simplelist(_element_value(*idxs)) end
# File tk/lib/tk/variable.rb, line 1142 def lset(idx, val) tk_call('lset', @id, idx, val) self end
# File tk/lib/tk/variable.rb, line 1279 def nonzero? !(numeric.zero?) end
# File tk/lib/tk/variable.rb, line 732 def numeric number(_value) end
# File tk/lib/tk/variable.rb, line 735 def numeric_element(*idxs) number(_element_value(*idxs)) end
# File tk/lib/tk/variable.rb, line 1040 def numlist list.collect!{|val| number(val)} end
# File tk/lib/tk/variable.rb, line 1043 def numlist_element(*idxs) list_element(*idxs).collect!{|val| number(val)} end
# File tk/lib/tk/variable.rb, line 901 def procedure TkComm.procedure(self._value) end
# File tk/lib/tk/variable.rb, line 904 def procedure_element(*idxs) TkComm.procedure(_element_value(*idxs)) end
# File tk/lib/tk/variable.rb, line 401 def ref(*idxs) # "#{@id}(#{idxs.collect{|idx| _get_eval_string(idx)}.join(',')})" TkVarAccess.new("#{@id}(#{idxs.collect{|idx| _get_eval_string(idx)}.join(',')})") end
# File tk/lib/tk/variable.rb, line 792 def set_bool(val) if ! val self.value = '0' else case val.to_s.downcase when 'false', '0', 'no', 'off' self.value = '0' else self.value = '1' end end self end
# File tk/lib/tk/variable.rb, line 806 def set_bool_element(idxs, val) if ! val val = '0' else case val.to_s.downcase when 'false', '0', 'no', 'off' val = '0' else val = '1' end end if idxs.kind_of?(Array) self[*idxs]=val else self[idxs]=val end self end
# File tk/lib/tk/variable.rb, line 830 def set_bool_element_type(idxs, val) self.set_default_element_value_type(idxs, :bool) self.set_bool_element(idxs, val) end
# File tk/lib/tk/variable.rb, line 824 def set_bool_type(val) @type = :bool self.bool=(val) self end
# File tk/lib/tk/variable.rb, line 226 def set_default_element_value_type(idxs, type) _set_default_value_type_core(type, idxs) self end
# File tk/lib/tk/variable.rb, line 127 def set_default_value(val) @def_default = :val @default_val = val self end
# File tk/lib/tk/variable.rb, line 220 def set_default_value_type(type) _set_default_value_type_core(type, nil) self end
# File tk/lib/tk/variable.rb, line 705 def set_element_value(idxs, val) if idxs.kind_of?(Array) self[*idxs]=val else self[idxs]=val end self end
# File tk/lib/tk/variable.rb, line 722 def set_element_value_type(idxs, val) self.set_default_element_value_type(idxs, val.class) if idxs.kind_of?(Array) self[*idxs]=val else self[idxs]=val end self end
# File tk/lib/tk/variable.rb, line 1047 def set_list(val) case val when Array self.value=(val) when TkVariable self.value=(val.list) else raise ArgumentError, "Array is expected" end self end
# File tk/lib/tk/variable.rb, line 1063 def set_list_element(idxs, val) case val when Array val when TkVariable val = val.list else raise ArgumentError, "Array is expected" end if idxs.kind_of?(Array) self[*idxs]=val else self[idxs]=val end self end
# File tk/lib/tk/variable.rb, line 1087 def set_list_element_type(idxs, val) self.set_default_element_value_type(idxs, :list) self.set_list_element(idxs, val) end
# File tk/lib/tk/variable.rb, line 1081 def set_list_type(val) @type = :list self.list=(val) self end
# File tk/lib/tk/variable.rb, line 738 def set_numeric(val) case val when Numeric self.value=(val) when TkVariable self.value=(val.numeric) else raise ArgumentError, "Numeric is expected" end self end
# File tk/lib/tk/variable.rb, line 750 def set_numeric_element(idxs, val) case val when Numeric val when TkVariable val = val.numeric else raise ArgumentError, "Numeric is expected" end if idxs.kind_of?(Array) self[*idxs]=val else self[idxs]=val end self end
# File tk/lib/tk/variable.rb, line 772 def set_numeric_element_type(idxs, val) self.set_default_element_value_type(idxs, :numeric) self.set_numeric_element(idxs, val) end
# File tk/lib/tk/variable.rb, line 766 def set_numeric_type(val) @type = :numeric self.numeric=(val) self end
# File tk/lib/tk/variable.rb, line 1097 def set_numlist_element_type(idxs, val) self.set_default_element_value_type(idxs, :numlist) self.set_numlist_element(idxs, val) end
# File tk/lib/tk/variable.rb, line 1091 def set_numlist_type(val) @type = :numlist self.numlist=(val) self end
# File tk/lib/tk/variable.rb, line 907 def set_procedure(cmd) self.value = cmd self end
# File tk/lib/tk/variable.rb, line 912 def set_procedure_element(idxs, cmd) cmd = cmd._value if cmd.kind_of?(TkVariable) if idxs.kind_of?(Array) self[*idxs]=cmd else self[idxs]=cmd end self end
# File tk/lib/tk/variable.rb, line 927 def set_procedure_element_type(idxs, cmd) self.set_default_element_value_type(idxs, :procedure) self.set_proceure_element(idxs, cmd) end
# File tk/lib/tk/variable.rb, line 921 def set_procedure_type(cmd) @type = :procedure self.procedure=(cmd) self end
# File tk/lib/tk/variable.rb, line 969 def set_string(val) val = val._value if val.kind_of?(TkVariable) self.value=val self end
# File tk/lib/tk/variable.rb, line 975 def set_string_element(idxs, val) val = val._value if val.kind_of?(TkVariable) if idxs.kind_of?(Array) self[*idxs]=val else self[idxs]=val end self end
# File tk/lib/tk/variable.rb, line 990 def set_string_element_type(idxs, val) self.set_default_element_value_type(idxs, :string) self.set_string_element(idxs, val) end
# File tk/lib/tk/variable.rb, line 984 def set_string_type(val) @type = :string self.string=(val) self end
# File tk/lib/tk/variable.rb, line 1003 def set_symbol(val) val = val._value if val.kind_of?(TkVariable) self.value=val self end
# File tk/lib/tk/variable.rb, line 1009 def set_symbol_element(idxs, val) val = val._value if val.kind_of?(TkVariable) if idxs.kind_of?(Array) self[*idxs]=val else self[idxs]=val end self end
# File tk/lib/tk/variable.rb, line 1024 def set_symbol_element_type(idxs, val) self.set_default_element_value_type(idxs, :symbol) self.set_symbol_element(idxs, val) end
# File tk/lib/tk/variable.rb, line 1018 def set_symbol_type(val) @type = :symbol self.value=(val) self end
# File tk/lib/tk/variable.rb, line 692 def set_value(val) self.value = val self end
# File tk/lib/tk/variable.rb, line 714 def set_value_type(val) self.default_value_type = val.class self.value = val self end
# File tk/lib/tk/variable.rb, line 842 def set_variable(var) var = var.id if var.kind_of?(TkVariable) self.value = var self end
# File tk/lib/tk/variable.rb, line 848 def set_variable_element(idxs, var) var = var.id if var.kind_of?(TkVariable) if idxs.kind_of?(Array) self[*idxs]=var else self[idxs]=var end self end
# File tk/lib/tk/variable.rb, line 864 def set_variable_element_type(idxs, var) self.set_default_element_value_type(idxs, :variable) self.set_variable_element(idxs, var) end
# File tk/lib/tk/variable.rb, line 857 def set_variable_type(var) @type = :variable var = var.id if var.kind_of?(TkVariable) self.value = var self end
# File tk/lib/tk/variable.rb, line 875 def set_window(win) win = win._value if win.kind_of?(TkVariable) self.value = win self end
# File tk/lib/tk/variable.rb, line 881 def set_window_element(idxs, win) win = win._value if win.kind_of?(TkVariable) if idxs.kind_of?(Array) self[*idxs]=win else self[idxs]=win end self end
# File tk/lib/tk/variable.rb, line 896 def set_window_element_type(idxs, win) self.set_default_element_value_type(idxs, :window) self.set_window_element(idxs, win) end
# File tk/lib/tk/variable.rb, line 890 def set_window_type(win) @type = :window self.window=(win) self end
# File tk/lib/tk/variable.rb, line 440 def size INTERP._invoke_without_enc('global', @id) TkComm.number(INTERP._invoke_without_enc('array', 'size', @id)) end
# File tk/lib/tk/variable.rb, line 966 def string_element(*idxs) _element_value(*idxs) end
# File tk/lib/tk/variable.rb, line 393 def thread_tkwait wait(true, true) end
# File tk/lib/tk/variable.rb, line 384 def thread_wait(check_root = false) wait(true, check_root) end
# File tk/lib/tk/variable.rb, line 387 def tkwait(on_thread = true) wait(on_thread, true) end
# File tk/lib/tk/variable.rb, line 950 def to_f number(_value).to_f end
# File tk/lib/tk/variable.rb, line 697 def to_hash hash = {} self.keys.each{|k| hash[k] = self[k] } hash end
# File tk/lib/tk/variable.rb, line 942 def to_i number(_value).to_i end
# File tk/lib/tk/variable.rb, line 932 def to_proc cmd = self.procedure if cmd.respond_to?(:call) cmd else # cmd is a String cmd.to_sym.to_proc end end
# File tk/lib/tk/variable.rb, line 957 def to_s #string(value).to_s _value end
# File tk/lib/tk/variable.rb, line 995 def to_sym _value.intern end
# File tk/lib/tk/variable.rb, line 1377 def trace(opts, cmd = Proc.new) opts = _check_trace_opt(opts) (@trace_var ||= []).unshift([opts,cmd]) if @trace_opts == nil TkVar_CB_TBL[@id] = self @trace_opts = opts.dup if USE_OLD_TRACE_OPTION_STYLE Tk.tk_call_without_enc('trace', 'variable', @id, @trace_opts, 'rb_var ' << @id) else Tk.tk_call_without_enc('trace', 'add', 'variable', @id, @trace_opts, 'rb_var ' << @id) end else newopts = @trace_opts.dup if USE_OLD_TRACE_OPTION_STYLE opts.each_byte{|c| newopts.concat(c.chr) unless newopts.index(c.chr)} if newopts != @trace_opts Tk.tk_call_without_enc('trace', 'vdelete', @id, @trace_opts, 'rb_var ' << @id) @trace_opts.replace(newopts) Tk.tk_call_without_enc('trace', 'variable', @id, @trace_opts, 'rb_var ' << @id) end else newopts |= opts unless (newopts - @trace_opts).empty? Tk.tk_call_without_enc('trace', 'remove', 'variable', @id, @trace_opts, 'rb_var ' << @id) @trace_opts.replace(newopts) Tk.tk_call_without_enc('trace', 'add', 'variable', @id, @trace_opts, 'rb_var ' << @id) end end end self end
# File tk/lib/tk/variable.rb, line 1308 def trace_callback(elem, op) if @trace_var.kind_of? Array @trace_var.each{|m,e| e.call(self,elem,op) if m.index(op)} end if elem.kind_of?(String) && elem != '' if @trace_elem.kind_of?(Hash) && @trace_elem[elem].kind_of?(Array) @trace_elem[elem].each{|m,e| e.call(self,elem,op) if m.index(op)} end end end
# File tk/lib/tk/variable.rb, line 1417 def trace_element(elem, opts, cmd = Proc.new) if @elem fail(RuntimeError, "invalid for a TkVariable which denotes an element of Tcl's array") end opts = _check_trace_opt(opts) ((@trace_elem ||= {})[elem] ||= []).unshift([opts,cmd]) if @trace_opts == nil TkVar_CB_TBL[@id] = self @trace_opts = opts.dup if USE_OLD_TRACE_OPTION_STYLE Tk.tk_call_without_enc('trace', 'add', 'variable', @id, @trace_opts, 'rb_var ' << @id) else Tk.tk_call_without_enc('trace', 'variable', @id, @trace_opts, 'rb_var ' << @id) end else newopts = @trace_opts.dup if USE_OLD_TRACE_OPTION_STYLE opts.each_byte{|c| newopts.concat(c.chr) unless newopts.index(c.chr)} if newopts != @trace_opts Tk.tk_call_without_enc('trace', 'vdelete', @id, @trace_opts, 'rb_var ' << @id) @trace_opts.replace(newopts) Tk.tk_call_without_enc('trace', 'variable', @id, @trace_opts, 'rb_var ' << @id) end else newopts |= opts unless (newopts - @trace_opts).empty? Tk.tk_call_without_enc('trace', 'remove', 'variable', @id, @trace_opts, 'rb_var ' << @id) @trace_opts.replace(newopts) Tk.tk_call_without_enc('trace', 'add', 'variable', @id, @trace_opts, 'rb_var ' << @id) end end end self end
# File tk/lib/tk/variable.rb, line 1463 def trace_info return [] unless @trace_var @trace_var.dup end
# File tk/lib/tk/variable.rb, line 1469 def trace_info_for_element(elem) if @elem fail(RuntimeError, "invalid for a TkVariable which denotes an element of Tcl's array") end return [] unless @trace_elem return [] unless @trace_elem[elem] @trace_elem[elem].dup end
# File tk/lib/tk/variable.rb, line 1480 def trace_remove(opts,cmd) return self unless @trace_var.kind_of? Array opts = _check_trace_opt(opts) idx = -1 if USE_OLD_TRACE_OPTION_STYLE newopts = '' @trace_var.each_with_index{|e, i| if idx < 0 && e[1] == cmd diff = false ['a', 'r', 'w', 'u'].each{|c| break if (diff = e[0].index(c) ^ opts.index(c)) } unless diff #find idx = i next end end e[0].each_byte{|c| newopts.concat(c.chr) unless newopts.index(c.chr)} } else newopts = [] @trace_var.each_with_index{|e, i| if idx < 0 && e[1] == cmd && e[0].size == opts.size && (e[0] - opts).empty? # find idx = i next end newopts |= e[0] } end if idx >= 0 @trace_var.delete_at(idx) else return self end (@trace_elem ||= {}).each{|elem| @trace_elem[elem].each{|e| if USE_OLD_TRACE_OPTION_STYLE e[0].each_byte{|c| newopts.concat(c.chr) unless newopts.index(c.chr)} else newopts |= e[0] end } } if USE_OLD_TRACE_OPTION_STYLE diff = false @trace_opts.each_byte{|c| break if (diff = ! newopts.index(c))} if diff Tk.tk_call_without_enc('trace', 'vdelete', @id, @trace_opts, 'rb_var ' << @id) @trace_opts.replace(newopts) unless @trace_opts.empty? Tk.tk_call_without_enc('trace', 'variable', @id, @trace_opts, 'rb_var ' << @id) end end else unless (@trace_opts - newopts).empty? Tk.tk_call_without_enc('trace', 'remove', 'variable', @id, @trace_opts, 'rb_var ' << @id) @trace_opts.replace(newopts) unless @trace_opts.empty? Tk.tk_call_without_enc('trace', 'add', 'variable', @id, @trace_opts, 'rb_var ' << @id) end end end self end
# File tk/lib/tk/variable.rb, line 1560 def trace_remove_for_element(elem,opts,cmd) if @elem fail(RuntimeError, "invalid for a TkVariable which denotes an element of Tcl's array") end return self unless @trace_elem.kind_of? Hash return self unless @trace_elem[elem].kind_of? Array opts = _check_trace_opt(opts) idx = -1 if USE_OLD_TRACE_OPTION_STYLE @trace_elem[elem].each_with_index{|e, i| if idx < 0 && e[1] == cmd diff = false ['a', 'r', 'w', 'u'].each{|c| break if (diff = e[0].index(c) ^ opts.index(c)) } unless diff #find idx = i next end end } else @trace_elem[elem].each_with_index{|e, i| if idx < 0 && e[1] == cmd && e[0].size == opts.size && (e[0] - opts).empty? # find idx = i next end } end if idx >= 0 @trace_elem[elem].delete_at(idx) else return self end if USE_OLD_TRACE_OPTION_STYLE newopts = '' @trace_var.each{|e| e[0].each_byte{|c| newopts.concat(c.chr) unless newopts.index(c.chr)} } @trace_elem.each{|elem| @trace_elem[elem].each{|e| e[0].each_byte{|c| newopts.concat(c.chr) unless newopts.index(c.chr)} } } else newopts = [] @trace_var.each{|e| newopts |= e[0] } @trace_elem.each{|elem| @trace_elem[elem].each{|e| e[0].each_byte{|c| newopts.concat(c.chr) unless newopts.index(c.chr)} } } end if USE_OLD_TRACE_OPTION_STYLE diff = false @trace_opts.each_byte{|c| break if (diff = ! newopts.index(c))} if diff Tk.tk_call_without_enc('trace', 'vdelete', @id, @trace_opts, 'rb_var ' << @id) @trace_opts.replace(newopts) unless @trace_opts.empty? Tk.tk_call_without_enc('trace', 'variable', @id, @trace_opts, 'rb_var ' << @id) end end else unless (@trace_opts - newopts).empty? Tk.tk_call_without_enc('trace', 'remove', 'variable', @id, @trace_opts, 'rb_var ' << @id) @trace_opts.replace(newopts) unless @trace_opts.empty? Tk.tk_call_without_enc('trace', 'add', 'variable', @id, @trace_opts, 'rb_var ' << @id) end end end self end
# File tk/lib/tk/variable.rb, line 139 def undef_default @default_val = nil @def_default = false self end
# File tk/lib/tk/variable.rb, line 544 def unset(*elems) if elems.empty? INTERP._unset_global_var(@id) else index = elems.collect{|idx| _get_eval_string(idx, true)}.join(',') INTERP._unset_global_var2(@id, index) end end
# File tk/lib/tk/variable.rb, line 453 def update(hash) if (is_scalar?) fail RuntimeError, 'cannot update a scalar variable' end hash.each{|k,v| self[k] = v} self end
# File tk/lib/tk/variable.rb, line 684 def value _to_default_type(_value) end
# File tk/lib/tk/variable.rb, line 482 def value=(val) val = val._value if !@type && @type != :variable && val.kind_of?(TkVariable) if val.kind_of?(Hash) self.clear val.each{|k, v| #INTERP._set_global_var2(@id, _toUTF8(_get_eval_string(k)), # _toUTF8(_get_eval_string(v))) INTERP._set_global_var2(@id, _get_eval_string(k, true), _get_eval_string(v, true)) } self.value # elsif val.kind_of?(Array) =begin INTERP._set_global_var(@id, '') val.each{|v| #INTERP._set_variable(@id, _toUTF8(_get_eval_string(v)), INTERP._set_variable(@id, _get_eval_string(v, true), TclTkLib::VarAccessFlag::GLOBAL_ONLY | TclTkLib::VarAccessFlag::LEAVE_ERR_MSG | TclTkLib::VarAccessFlag::APPEND_VALUE | TclTkLib::VarAccessFlag::LIST_ELEMENT) } self.value =end # _fromUTF8(INTERP._set_global_var(@id, array2tk_list(val, true))) else #_fromUTF8(INTERP._set_global_var(@id, _toUTF8(_get_eval_string(val)))) _fromUTF8(INTERP._set_global_var(@id, _get_eval_string(val, true))) end end
# File tk/lib/tk/variable.rb, line 835 def variable # keeps a Tcl's variable name TkVarAccess.new(self._value) end
# File tk/lib/tk/variable.rb, line 839 def variable_element(*idxs) TkVarAccess.new(_element_value(*idxs)) end
# File tk/lib/tk/variable.rb, line 362 def wait(on_thread = false, check_root = false) if $SAFE >= 4 fail SecurityError, "can't wait variable at $SAFE >= 4" end on_thread &= (Thread.list.size != 1) if on_thread if check_root INTERP._thread_tkwait('variable', @id) else INTERP._thread_vwait(@id) end else if check_root INTERP._invoke_without_enc('tkwait', 'variable', @id) else INTERP._invoke_without_enc('vwait', @id) end end end
# File tk/lib/tk/variable.rb, line 869 def window TkComm.window(self._value) end
# File tk/lib/tk/variable.rb, line 513 def _element_value(*idxs) index = idxs.collect{|idx| _get_eval_string(idx, true)}.join(',') begin _fromUTF8(INTERP._get_global_var2(@id, index)) rescue => e case @def_default when :proc @default_val.call(self, *idxs) when :val @default_val else fail e end end #_fromUTF8(INTERP._get_global_var2(@id, index)) #_fromUTF8(INTERP._get_global_var2(@id, _toUTF8(_get_eval_string(index)))) #_fromUTF8(INTERP._get_global_var2(@id, _get_eval_string(index, true))) end
use Tcl function version of set tkvariable
# File tk/lib/tk/variable.rb, line 470 def _value #if INTERP._eval("global #{@id}; array exist #{@id}") == '1' INTERP._invoke_without_enc('global', @id) # if INTERP._invoke('array', 'exist', @id) == '1' if TkComm.bool(INTERP._invoke('array', 'exist', @id)) #Hash[*tk_split_simplelist(INTERP._eval("global #{@id}; array get #{@id}"))] Hash[*tk_split_simplelist(INTERP._invoke('array', 'get', @id))] else _fromUTF8(INTERP._get_global_var(@id)) end end