Class: TkVariable
Constant Summary
collapse
- TkCommandNames =
TkCommandNames = [‘tkwait’.freeze].freeze
['vwait'.freeze].freeze
- TkVar_CB_TBL =
TkVar_CB_TBL = {} TkVar_ID_TBL = {}
TkCore::INTERP.create_table
- TkVar_ID_TBL =
TkCore::INTERP.create_table
- USE_OLD_TRACE_OPTION_STYLE =
(major < 8) || (major == 8 && minor < 4)
- USE_TCLs_SET_VARIABLE_FUNCTIONS =
true
Constants included
from TkCore
TkCore::EventFlag, TkCore::INTERP, TkCore::INTERP_MUTEX, TkCore::INTERP_ROOT_CHECK, TkCore::INTERP_THREAD, TkCore::INTERP_THREAD_STATUS, TkCore::RUN_EVENTLOOP_ON_MAIN_THREAD, TkCore::WIDGET_DESTROY_HOOK, TkCore::WITH_ENCODING, TkCore::WITH_RUBY_VM
Constants included
from TkComm
TkComm::GET_CONFIGINFO_AS_ARRAY, TkComm::GET_CONFIGINFOwoRES_AS_ARRAY, TkComm::TkExtlibAutoloadModule, TkComm::Tk_CMDTBL, TkComm::Tk_IDs, TkComm::Tk_WINDOWS, TkComm::USE_TCLs_LIST_FUNCTIONS, TkComm::WidgetClassNames
Constants included
from TkUtil
TkUtil::None, TkUtil::RELEASE_DATE
Constants included
from Tk
Tk::AUTO_PATH, Tk::Fontchooser, Tk::INTERP, Tk::JAPANIZED_TK, Tk::LIBRARY_PATH, Tk::MAINLOOP, Tk::PACKAGE_PATH, Tk::RELEASE_DATE, Tk::TCL_LIBRARY_PATH, Tk::TCL_MAJOR_VERSION, Tk::TCL_MINOR_VERSION, Tk::TCL_PACKAGE_PATH, Tk::TCL_PATCHLEVEL, Tk::TCL_PRECISION, Tk::TCL_VERSION, Tk::TK_MAJOR_VERSION, Tk::TK_MINOR_VERSION, Tk::TK_PATCHLEVEL, Tk::TK_VERSION, Tk::Tkextlib_RELEASE_DATE, Tk::TreeCtrl_Widget, Tk::X_Scrollable, Tk::Y_Scrollable
Tk::Encoding::BINARY, Tk::Encoding::BINARY_NAME, Tk::Encoding::DEFAULT_EXTERNAL_NAME, Tk::Encoding::DEFAULT_INTERNAL_NAME, Tk::Encoding::ENCODING_TABLE, Tk::Encoding::RubyEncoding, Tk::Encoding::UNKNOWN, Tk::Encoding::UTF8_NAME
Class Method Summary
collapse
Instance Method Summary
collapse
-
#%(other) ⇒ Object
-
#&(other) ⇒ Object
-
#*(other) ⇒ Object
-
#**(other) ⇒ Object
begin number(self._value) % other rescue self._value % other end.
-
#+(other) ⇒ Object
-
#+@ ⇒ Object
-
#-(other) ⇒ Object
-
#-@ ⇒ Object
-
#/(other) ⇒ Object
begin number(self._value) * other rescue self._value * other end.
-
#<=>(other) ⇒ Object
-
#==(other) ⇒ Object
-
#===(other) ⇒ Object
-
#=~(other) ⇒ Object
-
#[](*idxs) ⇒ Object
-
#[]=(*args) ⇒ Object
-
#bool ⇒ Object
-
#bool_element(*idxs) ⇒ Object
# see Tcl_GetBoolean man-page case _value.downcase when ‘0’, ‘false’, ‘no’, ‘off’ false else true end.
-
#clear ⇒ Object
-
#coerce(other) ⇒ Object
-
#default_element_value_type(idxs) ⇒ Object
-
#default_proc(cmd = Proc.new) ⇒ Object
-
#default_value(val = nil, &b) ⇒ Object
default_value is available only when the variable is an assoc array.
-
#default_value_type ⇒ Object
-
#element_lappend(idxs, *elems) ⇒ Object
-
#element_lget_f(elem_idxs, idx) ⇒ Object
-
#element_lget_i(elem_idxs, idx) ⇒ Object
-
#element_lindex(elem_idxs, idx) ⇒ Object
(also: #element_lget)
-
#element_lset(elem_idxs, idx, val) ⇒ Object
-
#element_to_f(*idxs) ⇒ Object
-
#element_to_i(*idxs) ⇒ Object
-
#element_to_s(*idxs) ⇒ Object
-
#element_to_sym(*idxs) ⇒ Object
(also: #symbol_element)
-
#eventloop_tkwait ⇒ Object
-
#eventloop_wait(check_root = false) ⇒ Object
-
#exist?(*elems) ⇒ Boolean
-
#id ⇒ Object
-
#initialize(val = "", type = nil) ⇒ TkVariable
constructor
A new instance of TkVariable.
-
#inspect ⇒ Object
-
#is_hash? ⇒ Boolean
-
#is_scalar? ⇒ Boolean
-
#keys ⇒ Object
-
#lappend(*elems) ⇒ Object
-
#lget_f(idx) ⇒ Object
-
#lget_i(idx) ⇒ Object
-
#lindex(idx) ⇒ Object
(also: #lget)
-
#list ⇒ Object
(also: #to_a, #to_ary)
-
#list_element(*idxs) ⇒ Object
(also: #element_to_a)
-
#lset(idx, val) ⇒ Object
-
#nonzero? ⇒ Boolean
-
#numeric ⇒ Object
-
#numeric_element(*idxs) ⇒ Object
-
#numlist ⇒ Object
-
#numlist_element(*idxs) ⇒ Object
-
#procedure ⇒ Object
-
#procedure_element(*idxs) ⇒ Object
-
#ref(*idxs) ⇒ Object
-
#set_bool(val) ⇒ Object
(also: #bool=)
-
#set_bool_element(idxs, val) ⇒ Object
-
#set_bool_element_type(idxs, val) ⇒ Object
-
#set_bool_type(val) ⇒ Object
(also: #bool_type=)
-
#set_default_element_value_type(idxs, type) ⇒ Object
-
#set_default_value(val) ⇒ Object
(also: #default_value=)
-
#set_default_value_type(type) ⇒ Object
(also: #default_value_type=)
-
#set_element_value(idxs, val) ⇒ Object
-
#set_element_value_type(idxs, val) ⇒ Object
-
#set_list(val) ⇒ Object
(also: #list=, #set_numlist)
-
#set_list_element(idxs, val) ⇒ Object
(also: #set_numlist_element)
-
#set_list_element_type(idxs, val) ⇒ Object
-
#set_list_type(val) ⇒ Object
(also: #list_type=)
-
#set_numeric(val) ⇒ Object
(also: #numeric=)
-
#set_numeric_element(idxs, val) ⇒ Object
-
#set_numeric_element_type(idxs, val) ⇒ Object
-
#set_numeric_type(val) ⇒ Object
(also: #numeric_type=)
-
#set_numlist_element_type(idxs, val) ⇒ Object
-
#set_numlist_type(val) ⇒ Object
(also: #numlist_type=)
-
#set_procedure(cmd) ⇒ Object
(also: #procedure=)
-
#set_procedure_element(idxs, cmd) ⇒ Object
-
#set_procedure_element_type(idxs, cmd) ⇒ Object
-
#set_procedure_type(cmd) ⇒ Object
(also: #procedure_type=)
-
#set_string(val) ⇒ Object
(also: #string=)
-
#set_string_element(idxs, val) ⇒ Object
-
#set_string_element_type(idxs, val) ⇒ Object
-
#set_string_type(val) ⇒ Object
(also: #string_type=)
-
#set_symbol(val) ⇒ Object
(also: #symbol=)
-
#set_symbol_element(idxs, val) ⇒ Object
-
#set_symbol_element_type(idxs, val) ⇒ Object
-
#set_symbol_type(val) ⇒ Object
(also: #symbol_type=)
-
#set_value(val) ⇒ Object
-
#set_value_type(val) ⇒ Object
(also: #value_type=)
-
#set_variable(var) ⇒ Object
(also: #variable=)
-
#set_variable_element(idxs, var) ⇒ Object
-
#set_variable_element_type(idxs, var) ⇒ Object
-
#set_variable_type(var) ⇒ Object
(also: #variable_type=)
-
#set_window(win) ⇒ Object
(also: #window=)
-
#set_window_element(idxs, win) ⇒ Object
-
#set_window_element_type(idxs, win) ⇒ Object
-
#set_window_type(win) ⇒ Object
(also: #window_type=)
-
#size ⇒ Object
-
#string_element(*idxs) ⇒ Object
-
#thread_tkwait ⇒ Object
-
#thread_wait(check_root = false) ⇒ Object
-
#tkwait(on_thread = true) ⇒ Object
-
#to_eval ⇒ Object
-
#to_f ⇒ Object
-
#to_hash ⇒ Object
-
#to_i ⇒ Object
(also: #to_int)
-
#to_proc ⇒ Object
-
#to_s ⇒ Object
(also: #string, #to_str)
-
#to_sym ⇒ Object
(also: #symbol)
-
#trace(opts, cmd = Proc.new) ⇒ Object
-
#trace_callback(elem, op) ⇒ Object
-
#trace_element(elem, opts, cmd = Proc.new) ⇒ Object
-
#trace_info ⇒ Object
(also: #trace_vinfo)
-
#trace_info_for_element(elem) ⇒ Object
(also: #trace_vinfo_for_element)
-
#trace_remove(opts, cmd) ⇒ Object
(also: #trace_delete, #trace_vdelete)
-
#trace_remove_for_element(elem, opts, cmd) ⇒ Object
(also: #trace_delete_for_element, #trace_vdelete_for_element)
-
#undef_default ⇒ Object
-
#unset(*elems) ⇒ Object
(also: #remove)
-
#update(hash) ⇒ Object
-
#value ⇒ Object
-
#value=(val) ⇒ Object
-
#variable ⇒ Object
-
#variable_element(*idxs) ⇒ Object
-
#wait(on_thread = false, check_root = false) ⇒ Object
-
#window ⇒ Object
-
#window_element(*idxs) ⇒ Object
-
#zero? ⇒ Boolean
-
#|(other) ⇒ Object
Methods included from TkCore
_tk_call_to_list_core, after, after_cancel, after_idle, appname, appsend, appsend_deny, appsend_displayof, callback_break, callback_continue, callback_return, chooseColor, chooseDirectory, do_one_event, event_generate, getMultipleOpenFile, getMultipleSaveFile, getOpenFile, getSaveFile, get_eventloop_tick, get_eventloop_weight, get_no_event_wait, inactive, inactive_displayof, info, ip_eval, ip_eval_with_enc, ip_eval_without_enc, ip_invoke, ip_invoke_with_enc, ip_invoke_without_enc, is_mainloop?, load_cmd_on_ip, mainloop, mainloop_exist?, mainloop_thread?, mainloop_watchdog, messageBox, rb_appsend, rb_appsend_displayof, reset_inactive, reset_inactive_displayof, restart, scaling, scaling_displayof, set_eventloop_tick, set_eventloop_weight, set_no_event_wait, tk_call, tk_call_to_list, tk_call_to_list_with_enc, tk_call_to_list_without_enc, tk_call_to_simplelist, tk_call_to_simplelist_with_enc, tk_call_to_simplelist_without_enc, tk_call_with_enc, tk_call_without_enc, windowingsystem
Methods included from TkComm
_at, _callback_entry?, _callback_entry_class?, _curr_cmd_id, _fromUTF8, _genobj_for_tkwidget, _next_cmd_id, _toUTF8, array2tk_list, #bind, #bind_all, #bind_append, #bind_append_all, #bind_remove, #bind_remove_all, #bindinfo, #bindinfo_all, bool, image_obj, #install_cmd, install_cmd, list, num_or_nil, num_or_str, number, procedure, simplelist, slice_ary, string, #subst, tk_tcl2ruby, uninstall_cmd, #uninstall_cmd, window
Methods included from TkEvent
#install_bind, #install_bind_for_event_class
Methods included from TkUtil
#_conv_args, _conv_args, #_fromUTF8, _get_eval_enc_str, #_get_eval_enc_str, #_get_eval_string, _get_eval_string, _symbolkey2str, #_symbolkey2str, #_toUTF8, bool, eval_cmd, hash_kv, #hash_kv, install_cmd, num_or_nil, #num_or_nil, num_or_str, #num_or_str, number, #number, string, uninstall_cmd, untrust
Methods included from Tk
BinaryString, EncodedString, #Grid, #Pack, #Place, UTF8_String, __create_widget_set__, __disable_toplevel_control__, __import_toplevel_aliases__, __regist_toplevel_aliases__, __remove_toplevel_aliases__, __reset_toplevel_owner__, __set_loaded_toplevel_aliases__, __set_toplevel_aliases__, __toplevel_alias_setup_proc__, _replace_toplevel_aliases, add_kinsoku, backup_current_topdef, bell, bell_on_display, const_missing, current_grabs, cursor_display, default_widget_set, default_widget_set=, define_topalias, define_topobj, delete_kinsoku, destroy, #encoding, #encoding=, errorCode, errorInfo, exit, focus, focus_lastfor, focus_next, focus_prev, focus_to, fromUTF8, grid, grid_forget, has_mainwindow?, load_tcllibrary, load_tclscript, load_tclscript_rsrc, load_tclscript_rsrcid, lower_window, pack, pack_forget, pkgconfig_get, pkgconfig_list, place, place_forget, raise_window, regist_sym_for_loaded_file, replace_topalias, replace_topobj, #root, set_topalias, show_kinsoku, sleep, strictMotif, subst_tk_backslash, subst_utf_backslash, tcl_pkgconfig_get, tcl_pkgconfig_list, thread_update, thread_update_idletasks, tk_pkgconfig_get, tk_pkgconfig_list, toUTF8, to_backslash_sequence, topalias_defined?, toplevel_aliases_on_widget_set, topobj_defined?, ungrid, unload_tcllibrary, unpack, unplace, update, update_idletasks, utf_to_backslash, utf_to_backslash_sequence, wakeup, widget_set_symbols
#default_encoding=, #encoding=, #encoding_convertfrom, #encoding_convertto, #encoding_dirs, #encoding_dirs=, #encoding_name, #encoding_names, #encoding_obj, #encoding_objs, #encoding_system=, #encoding_system_name, #encoding_system_obj, #force_default_encoding, #force_default_encoding=, #force_default_encoding?, #tk_encoding_names
Constructor Details
#initialize(val = "", type = nil) ⇒ TkVariable
Returns a new instance of TkVariable.
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
|
# File 'lib/tk/variable.rb', line 283
def initialize(val="", type=nil)
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
INTERP._invoke_without_enc('global', @id)
if val.kind_of?(Hash)
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
|
Class Method Details
.callback(id, name1, name2, op) ⇒ Object
def TkVariable.callback(args)
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
# File 'lib/tk/variable.rb', line 56
def TkVariable.callback(id, name1, name2, op)
if cb_obj = TkVar_CB_TBL[id]
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
|
.new_hash(val = {}) ⇒ Object
107
108
109
110
111
112
113
|
# File 'lib/tk/variable.rb', line 107
def self.new_hash(val = {})
if val.kind_of?(Hash)
self.new(val)
else
fail ArgumentError, 'Hash is expected'
end
end
|
Instance Method Details
1227
1228
1229
1230
1231
1232
1233
1234
|
# File 'lib/tk/variable.rb', line 1227
def %(other)
num_or_str(self._value) % other
end
|
1181
1182
1183
1184
1185
1186
1187
|
# File 'lib/tk/variable.rb', line 1181
def &(other)
if other.kind_of?(Array)
self.to_a & other.to_a
else
self.to_i & other.to_i
end
end
|
1216
1217
1218
1219
1220
1221
1222
1223
|
# File 'lib/tk/variable.rb', line 1216
def *(other)
num_or_str(self._value) * other
end
|
#**(other) ⇒ Object
begin
number(self._value) % other
rescue
self._value % other
end
1235
1236
1237
|
# File 'lib/tk/variable.rb', line 1235
def **(other)
number(self._value) ** other
end
|
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
|
# File 'lib/tk/variable.rb', line 1195
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
|
1174
1175
1176
|
# File 'lib/tk/variable.rb', line 1174
def +@
self.numeric
end
|
1209
1210
1211
1212
1213
1214
1215
|
# File 'lib/tk/variable.rb', line 1209
def -(other)
if other.kind_of?(Array)
self.to_a - other
else
number(self._value) - other
end
end
|
1177
1178
1179
|
# File 'lib/tk/variable.rb', line 1177
def -@
-(self.numeric)
end
|
begin
number(self._value) * other
rescue
self._value * other
end
1224
1225
1226
|
# File 'lib/tk/variable.rb', line 1224
def /(other)
number(self._value) / other
end
|
#<=>(other) ⇒ Object
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
|
# File 'lib/tk/variable.rb', line 1281
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
|
#==(other) ⇒ Object
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
|
# File 'lib/tk/variable.rb', line 1242
def ==(other)
case other
when TkVariable
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
self._value == other
else
self._value == _get_eval_string(other)
end
end
|
#===(other) ⇒ Object
1266
1267
1268
1269
1270
1271
1272
|
# File 'lib/tk/variable.rb', line 1266
def ===(other)
if other.kind_of?(TkVariable)
self.id == other.id
else
super
end
end
|
#=~(other) ⇒ Object
1238
1239
1240
|
# File 'lib/tk/variable.rb', line 1238
def =~(other)
self._value =~ other
end
|
#[](*idxs) ⇒ Object
686
687
688
|
# File 'lib/tk/variable.rb', line 686
def [](*idxs)
_to_default_element_type(idxs, _element_value(*idxs))
end
|
#[]=(*args) ⇒ Object
530
531
532
533
534
535
536
537
538
539
540
|
# File 'lib/tk/variable.rb', line 530
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)))
end
|
775
776
777
778
779
780
781
782
783
784
785
786
|
# File 'lib/tk/variable.rb', line 775
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
|
#bool_element(*idxs) ⇒ Object
# see Tcl_GetBoolean man-page
case _value.downcase
when '0', 'false', 'no', 'off'
false
else
true
end
787
788
789
|
# File 'lib/tk/variable.rb', line 787
def bool_element(*idxs)
TkComm.bool(_element_value(*idxs))
end
|
443
444
445
446
447
448
449
|
# File 'lib/tk/variable.rb', line 443
def clear
if (is_scalar?)
fail RuntimeError, 'cannot clear a scalar variable'
end
keys.each{|k| unset(k)}
self
end
|
#coerce(other) ⇒ Object
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
|
# File 'lib/tk/variable.rb', line 1157
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
|
#default_element_value_type(idxs) ⇒ Object
149
150
151
152
153
154
155
156
|
# File 'lib/tk/variable.rb', line 149
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
|
#default_proc(cmd = Proc.new) ⇒ Object
134
135
136
137
138
|
# File 'lib/tk/variable.rb', line 134
def default_proc(cmd = Proc.new)
@def_default = :proc
@default_val = cmd
self
end
|
#default_value(val = nil, &b) ⇒ Object
default_value is available only when the variable is an assoc array.
118
119
120
121
122
123
124
125
126
127
|
# File 'lib/tk/variable.rb', line 118
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
|
#default_value_type ⇒ Object
146
147
148
|
# File 'lib/tk/variable.rb', line 146
def default_value_type
@type
end
|
#element_lappend(idxs, *elems) ⇒ Object
1104
1105
1106
1107
1108
1109
1110
|
# File 'lib/tk/variable.rb', line 1104
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
|
#element_lget_f(elem_idxs, idx) ⇒ Object
1136
1137
1138
|
# File 'lib/tk/variable.rb', line 1136
def element_lget_f(elem_idxs, idx)
number(element_lget(elem_idxs, idx)).to_f
end
|
#element_lget_i(elem_idxs, idx) ⇒ Object
1129
1130
1131
|
# File 'lib/tk/variable.rb', line 1129
def element_lget_i(elem_idxs, idx)
number(element_lget(elem_idxs, idx)).to_i
end
|
#element_lindex(elem_idxs, idx) ⇒ Object
Also known as:
element_lget
1116
1117
1118
1119
1120
1121
1122
1123
|
# File 'lib/tk/variable.rb', line 1116
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
|
#element_lset(elem_idxs, idx, val) ⇒ Object
1144
1145
1146
1147
1148
1149
1150
|
# File 'lib/tk/variable.rb', line 1144
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
|
#element_to_f(*idxs) ⇒ Object
951
952
953
|
# File 'lib/tk/variable.rb', line 951
def element_to_f(*idxs)
number(_element_value(*idxs)).to_f
end
|
#element_to_i(*idxs) ⇒ Object
944
945
946
|
# File 'lib/tk/variable.rb', line 944
def element_to_i(*idxs)
number(_element_value(*idxs)).to_i
end
|
#element_to_s(*idxs) ⇒ Object
961
962
963
|
# File 'lib/tk/variable.rb', line 961
def element_to_s(*idxs)
_element_value(*idxs)
end
|
#element_to_sym(*idxs) ⇒ Object
Also known as:
symbol_element
997
998
999
|
# File 'lib/tk/variable.rb', line 997
def element_to_sym(*idxs)
_element_value(*idxs).intern
end
|
#eventloop_tkwait ⇒ Object
388
389
390
|
# File 'lib/tk/variable.rb', line 388
def eventloop_tkwait
wait(false, true)
end
|
#eventloop_wait(check_root = false) ⇒ Object
379
380
381
|
# File 'lib/tk/variable.rb', line 379
def eventloop_wait(check_root = false)
wait(false, check_root)
end
|
#exist?(*elems) ⇒ Boolean
415
416
417
418
419
420
421
422
423
424
425
|
# File 'lib/tk/variable.rb', line 415
def exist?(*elems)
INTERP._invoke_without_enc('global', @id)
if elems.empty?
TkComm.bool(tk_call('info', 'exist', @id))
else
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
|
395
396
397
|
# File 'lib/tk/variable.rb', line 395
def id
@id
end
|
1152
1153
1154
1155
|
# File 'lib/tk/variable.rb', line 1152
def inspect
'#<TkVariable: ' + @id + '>'
end
|
#is_hash? ⇒ Boolean
404
405
406
407
408
409
|
# File 'lib/tk/variable.rb', line 404
def is_hash?
INTERP._invoke_without_enc('global', @id)
TkComm.bool(INTERP._invoke_without_enc('array', 'exist', @id))
end
|
#is_scalar? ⇒ Boolean
411
412
413
|
# File 'lib/tk/variable.rb', line 411
def is_scalar?
! is_hash?
end
|
427
428
429
430
431
432
433
434
435
436
|
# File 'lib/tk/variable.rb', line 427
def keys
if (is_scalar?)
fail RuntimeError, 'cannot get keys from a scalar variable'
end
INTERP._invoke_without_enc('global', @id)
tk_split_simplelist(INTERP._invoke_without_enc('array', 'names', @id),
false, true)
end
|
#lappend(*elems) ⇒ Object
1100
1101
1102
1103
|
# File 'lib/tk/variable.rb', line 1100
def lappend(*elems)
tk_call('lappend', @id, *elems)
self
end
|
#lget_f(idx) ⇒ Object
1133
1134
1135
|
# File 'lib/tk/variable.rb', line 1133
def lget_f(idx)
number(lget(idx)).to_f
end
|
#lget_i(idx) ⇒ Object
1126
1127
1128
|
# File 'lib/tk/variable.rb', line 1126
def lget_i(idx)
number(lget(idx)).to_i
end
|
#lindex(idx) ⇒ Object
Also known as:
lget
1112
1113
1114
|
# File 'lib/tk/variable.rb', line 1112
def lindex(idx)
tk_call('lindex', self._value, idx)
end
|
#list ⇒ Object
Also known as:
to_a, to_ary
1027
1028
1029
1030
|
# File 'lib/tk/variable.rb', line 1027
def list
tk_split_simplelist(_value)
end
|
#list_element(*idxs) ⇒ Object
Also known as:
element_to_a
1033
1034
1035
|
# File 'lib/tk/variable.rb', line 1033
def list_element(*idxs)
tk_split_simplelist(_element_value(*idxs))
end
|
#lset(idx, val) ⇒ Object
1140
1141
1142
1143
|
# File 'lib/tk/variable.rb', line 1140
def lset(idx, val)
tk_call('lset', @id, idx, val)
self
end
|
#nonzero? ⇒ Boolean
1277
1278
1279
|
# File 'lib/tk/variable.rb', line 1277
def nonzero?
!(numeric.zero?)
end
|
730
731
732
|
# File 'lib/tk/variable.rb', line 730
def numeric
number(_value)
end
|
#numeric_element(*idxs) ⇒ Object
733
734
735
|
# File 'lib/tk/variable.rb', line 733
def numeric_element(*idxs)
number(_element_value(*idxs))
end
|
1038
1039
1040
|
# File 'lib/tk/variable.rb', line 1038
def numlist
list.collect!{|val| number(val)}
end
|
#numlist_element(*idxs) ⇒ Object
1041
1042
1043
|
# File 'lib/tk/variable.rb', line 1041
def numlist_element(*idxs)
list_element(*idxs).collect!{|val| number(val)}
end
|
#procedure ⇒ Object
899
900
901
|
# File 'lib/tk/variable.rb', line 899
def procedure
TkComm.procedure(self._value)
end
|
#procedure_element(*idxs) ⇒ Object
902
903
904
|
# File 'lib/tk/variable.rb', line 902
def procedure_element(*idxs)
TkComm.procedure(_element_value(*idxs))
end
|
#ref(*idxs) ⇒ Object
399
400
401
402
|
# File 'lib/tk/variable.rb', line 399
def ref(*idxs)
TkVarAccess.new("#{@id}(#{idxs.collect{|idx| _get_eval_string(idx)}.join(',')})")
end
|
#set_bool(val) ⇒ Object
Also known as:
bool=
790
791
792
793
794
795
796
797
798
799
800
801
802
|
# File 'lib/tk/variable.rb', line 790
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
|
#set_bool_element(idxs, val) ⇒ Object
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
|
# File 'lib/tk/variable.rb', line 804
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
|
#set_bool_element_type(idxs, val) ⇒ Object
828
829
830
831
|
# File 'lib/tk/variable.rb', line 828
def set_bool_element_type(idxs, val)
self.set_default_element_value_type(idxs, :bool)
self.set_bool_element(idxs, val)
end
|
#set_bool_type(val) ⇒ Object
Also known as:
bool_type=
822
823
824
825
826
|
# File 'lib/tk/variable.rb', line 822
def set_bool_type(val)
@type = :bool
self.bool=(val)
self
end
|
#set_default_element_value_type(idxs, type) ⇒ Object
227
228
229
230
|
# File 'lib/tk/variable.rb', line 227
def set_default_element_value_type(idxs, type)
_set_default_value_type_core(type, idxs)
self
end
|
#set_default_value(val) ⇒ Object
Also known as:
default_value=
128
129
130
131
132
|
# File 'lib/tk/variable.rb', line 128
def set_default_value(val)
@def_default = :val
@default_val = val
self
end
|
#set_default_value_type(type) ⇒ Object
Also known as:
default_value_type=
221
222
223
224
|
# File 'lib/tk/variable.rb', line 221
def set_default_value_type(type)
_set_default_value_type_core(type, nil)
self
end
|
#set_element_value(idxs, val) ⇒ Object
703
704
705
706
707
708
709
710
|
# File 'lib/tk/variable.rb', line 703
def set_element_value(idxs, val)
if idxs.kind_of?(Array)
self[*idxs]=val
else
self[idxs]=val
end
self
end
|
#set_element_value_type(idxs, val) ⇒ Object
720
721
722
723
724
725
726
727
728
|
# File 'lib/tk/variable.rb', line 720
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
|
#set_list(val) ⇒ Object
Also known as:
list=, set_numlist
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
|
# File 'lib/tk/variable.rb', line 1045
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
|
#set_list_element(idxs, val) ⇒ Object
Also known as:
set_numlist_element
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
|
# File 'lib/tk/variable.rb', line 1061
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
|
#set_list_element_type(idxs, val) ⇒ Object
1085
1086
1087
1088
|
# File 'lib/tk/variable.rb', line 1085
def set_list_element_type(idxs, val)
self.set_default_element_value_type(idxs, :list)
self.set_list_element(idxs, val)
end
|
#set_list_type(val) ⇒ Object
Also known as:
list_type=
1079
1080
1081
1082
1083
|
# File 'lib/tk/variable.rb', line 1079
def set_list_type(val)
@type = :list
self.list=(val)
self
end
|
#set_numeric(val) ⇒ Object
Also known as:
numeric=
736
737
738
739
740
741
742
743
744
745
746
|
# File 'lib/tk/variable.rb', line 736
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
|
#set_numeric_element(idxs, val) ⇒ Object
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
|
# File 'lib/tk/variable.rb', line 748
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
|
#set_numeric_element_type(idxs, val) ⇒ Object
770
771
772
773
|
# File 'lib/tk/variable.rb', line 770
def set_numeric_element_type(idxs, val)
self.set_default_element_value_type(idxs, :numeric)
self.set_numeric_element(idxs, val)
end
|
#set_numeric_type(val) ⇒ Object
Also known as:
numeric_type=
764
765
766
767
768
|
# File 'lib/tk/variable.rb', line 764
def set_numeric_type(val)
@type = :numeric
self.numeric=(val)
self
end
|
#set_numlist_element_type(idxs, val) ⇒ Object
1095
1096
1097
1098
|
# File 'lib/tk/variable.rb', line 1095
def set_numlist_element_type(idxs, val)
self.set_default_element_value_type(idxs, :numlist)
self.set_numlist_element(idxs, val)
end
|
#set_numlist_type(val) ⇒ Object
Also known as:
numlist_type=
1089
1090
1091
1092
1093
|
# File 'lib/tk/variable.rb', line 1089
def set_numlist_type(val)
@type = :numlist
self.numlist=(val)
self
end
|
#set_procedure(cmd) ⇒ Object
Also known as:
procedure=
905
906
907
908
|
# File 'lib/tk/variable.rb', line 905
def set_procedure(cmd)
self.value = cmd
self
end
|
#set_procedure_element(idxs, cmd) ⇒ Object
910
911
912
913
914
915
916
917
918
|
# File 'lib/tk/variable.rb', line 910
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
|
#set_procedure_element_type(idxs, cmd) ⇒ Object
925
926
927
928
|
# File 'lib/tk/variable.rb', line 925
def set_procedure_element_type(idxs, cmd)
self.set_default_element_value_type(idxs, :procedure)
self.set_proceure_element(idxs, cmd)
end
|
#set_procedure_type(cmd) ⇒ Object
Also known as:
procedure_type=
919
920
921
922
923
|
# File 'lib/tk/variable.rb', line 919
def set_procedure_type(cmd)
@type = :procedure
self.procedure=(cmd)
self
end
|
#set_string(val) ⇒ Object
Also known as:
string=
967
968
969
970
971
|
# File 'lib/tk/variable.rb', line 967
def set_string(val)
val = val._value if val.kind_of?(TkVariable)
self.value=val
self
end
|
#set_string_element(idxs, val) ⇒ Object
973
974
975
976
977
978
979
980
981
|
# File 'lib/tk/variable.rb', line 973
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
|
#set_string_element_type(idxs, val) ⇒ Object
988
989
990
991
|
# File 'lib/tk/variable.rb', line 988
def set_string_element_type(idxs, val)
self.set_default_element_value_type(idxs, :string)
self.set_string_element(idxs, val)
end
|
#set_string_type(val) ⇒ Object
Also known as:
string_type=
982
983
984
985
986
|
# File 'lib/tk/variable.rb', line 982
def set_string_type(val)
@type = :string
self.string=(val)
self
end
|
#set_symbol(val) ⇒ Object
Also known as:
symbol=
1001
1002
1003
1004
1005
|
# File 'lib/tk/variable.rb', line 1001
def set_symbol(val)
val = val._value if val.kind_of?(TkVariable)
self.value=val
self
end
|
#set_symbol_element(idxs, val) ⇒ Object
1007
1008
1009
1010
1011
1012
1013
1014
1015
|
# File 'lib/tk/variable.rb', line 1007
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
|
#set_symbol_element_type(idxs, val) ⇒ Object
1022
1023
1024
1025
|
# File 'lib/tk/variable.rb', line 1022
def set_symbol_element_type(idxs, val)
self.set_default_element_value_type(idxs, :symbol)
self.set_symbol_element(idxs, val)
end
|
#set_symbol_type(val) ⇒ Object
Also known as:
symbol_type=
1016
1017
1018
1019
1020
|
# File 'lib/tk/variable.rb', line 1016
def set_symbol_type(val)
@type = :symbol
self.value=(val)
self
end
|
#set_value(val) ⇒ Object
690
691
692
693
|
# File 'lib/tk/variable.rb', line 690
def set_value(val)
self.value = val
self
end
|
#set_value_type(val) ⇒ Object
Also known as:
value_type=
712
713
714
715
716
|
# File 'lib/tk/variable.rb', line 712
def set_value_type(val)
self.default_value_type = val.class
self.value = val
self
end
|
#set_variable(var) ⇒ Object
Also known as:
variable=
840
841
842
843
844
|
# File 'lib/tk/variable.rb', line 840
def set_variable(var)
var = var.id if var.kind_of?(TkVariable)
self.value = var
self
end
|
#set_variable_element(idxs, var) ⇒ Object
846
847
848
849
850
851
852
853
854
|
# File 'lib/tk/variable.rb', line 846
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
|
#set_variable_element_type(idxs, var) ⇒ Object
862
863
864
865
|
# File 'lib/tk/variable.rb', line 862
def set_variable_element_type(idxs, var)
self.set_default_element_value_type(idxs, :variable)
self.set_variable_element(idxs, var)
end
|
#set_variable_type(var) ⇒ Object
Also known as:
variable_type=
855
856
857
858
859
860
|
# File 'lib/tk/variable.rb', line 855
def set_variable_type(var)
@type = :variable
var = var.id if var.kind_of?(TkVariable)
self.value = var
self
end
|
#set_window(win) ⇒ Object
Also known as:
window=
873
874
875
876
877
|
# File 'lib/tk/variable.rb', line 873
def set_window(win)
win = win._value if win.kind_of?(TkVariable)
self.value = win
self
end
|
#set_window_element(idxs, win) ⇒ Object
879
880
881
882
883
884
885
886
887
|
# File 'lib/tk/variable.rb', line 879
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
|
#set_window_element_type(idxs, win) ⇒ Object
894
895
896
897
|
# File 'lib/tk/variable.rb', line 894
def set_window_element_type(idxs, win)
self.set_default_element_value_type(idxs, :window)
self.set_window_element(idxs, win)
end
|
#set_window_type(win) ⇒ Object
Also known as:
window_type=
888
889
890
891
892
|
# File 'lib/tk/variable.rb', line 888
def set_window_type(win)
@type = :window
self.window=(win)
self
end
|
438
439
440
441
|
# File 'lib/tk/variable.rb', line 438
def size
INTERP._invoke_without_enc('global', @id)
TkComm.number(INTERP._invoke_without_enc('array', 'size', @id))
end
|
#string_element(*idxs) ⇒ Object
964
965
966
|
# File 'lib/tk/variable.rb', line 964
def string_element(*idxs)
_element_value(*idxs)
end
|
#thread_tkwait ⇒ Object
391
392
393
|
# File 'lib/tk/variable.rb', line 391
def thread_tkwait
wait(true, true)
end
|
#thread_wait(check_root = false) ⇒ Object
382
383
384
|
# File 'lib/tk/variable.rb', line 382
def thread_wait(check_root = false)
wait(true, check_root)
end
|
#tkwait(on_thread = true) ⇒ Object
385
386
387
|
# File 'lib/tk/variable.rb', line 385
def tkwait(on_thread = true)
wait(on_thread, true)
end
|
1302
1303
1304
|
# File 'lib/tk/variable.rb', line 1302
def to_eval
@id
end
|
948
949
950
|
# File 'lib/tk/variable.rb', line 948
def to_f
number(_value).to_f
end
|
695
696
697
698
699
700
701
|
# File 'lib/tk/variable.rb', line 695
def to_hash
hash = {}
self.keys.each{|k|
hash[k] = self[k]
}
hash
end
|
#to_i ⇒ Object
Also known as:
to_int
940
941
942
|
# File 'lib/tk/variable.rb', line 940
def to_i
number(_value).to_i
end
|
930
931
932
933
934
935
936
937
938
|
# File 'lib/tk/variable.rb', line 930
def to_proc
cmd = self.procedure
if cmd.respond_to?(:call)
cmd
else
cmd.to_sym.to_proc
end
end
|
#to_s ⇒ Object
Also known as:
string, to_str
955
956
957
958
|
# File 'lib/tk/variable.rb', line 955
def to_s
_value
end
|
#to_sym ⇒ Object
Also known as:
symbol
993
994
995
|
# File 'lib/tk/variable.rb', line 993
def to_sym
_value.intern
end
|
#trace(opts, cmd = Proc.new) ⇒ Object
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
|
# File 'lib/tk/variable.rb', line 1375
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
|
#trace_callback(elem, op) ⇒ Object
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
|
# File 'lib/tk/variable.rb', line 1306
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
|
#trace_element(elem, opts, cmd = Proc.new) ⇒ Object
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
|
# File 'lib/tk/variable.rb', line 1415
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
|
#trace_info ⇒ Object
Also known as:
trace_vinfo
1461
1462
1463
1464
|
# File 'lib/tk/variable.rb', line 1461
def trace_info
return [] unless @trace_var
@trace_var.dup
end
|
#trace_info_for_element(elem) ⇒ Object
Also known as:
trace_vinfo_for_element
1467
1468
1469
1470
1471
1472
1473
1474
1475
|
# File 'lib/tk/variable.rb', line 1467
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
|
#trace_remove(opts, cmd) ⇒ Object
Also known as:
trace_delete, trace_vdelete
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
|
# File 'lib/tk/variable.rb', line 1478
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
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?
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
|
#trace_remove_for_element(elem, opts, cmd) ⇒ Object
Also known as:
trace_delete_for_element, trace_vdelete_for_element
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
|
# File 'lib/tk/variable.rb', line 1558
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
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?
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
|
#undef_default ⇒ Object
140
141
142
143
144
|
# File 'lib/tk/variable.rb', line 140
def undef_default
@default_val = nil
@def_default = false
self
end
|
#unset(*elems) ⇒ Object
Also known as:
remove
542
543
544
545
546
547
548
549
|
# File 'lib/tk/variable.rb', line 542
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
|
#update(hash) ⇒ Object
451
452
453
454
455
456
457
|
# File 'lib/tk/variable.rb', line 451
def update(hash)
if (is_scalar?)
fail RuntimeError, 'cannot update a scalar variable'
end
hash.each{|k,v| self[k] = v}
self
end
|
682
683
684
|
# File 'lib/tk/variable.rb', line 682
def value
_to_default_type(_value)
end
|
#value=(val) ⇒ Object
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
|
# File 'lib/tk/variable.rb', line 480
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, _get_eval_string(k, true),
_get_eval_string(v, true))
}
self.value
=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
else
_fromUTF8(INTERP._set_global_var(@id, _get_eval_string(val, true)))
end
end
|
833
834
835
836
|
# File 'lib/tk/variable.rb', line 833
def variable
TkVarAccess.new(self._value)
end
|
#variable_element(*idxs) ⇒ Object
837
838
839
|
# File 'lib/tk/variable.rb', line 837
def variable_element(*idxs)
TkVarAccess.new(_element_value(*idxs))
end
|
#wait(on_thread = false, check_root = false) ⇒ Object
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
|
# File 'lib/tk/variable.rb', line 363
def wait(on_thread = false, check_root = false)
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
|
867
868
869
|
# File 'lib/tk/variable.rb', line 867
def window
TkComm.window(self._value)
end
|
#window_element(*idxs) ⇒ Object
870
871
872
|
# File 'lib/tk/variable.rb', line 870
def window_element(*idxs)
TkComm.window(_element_value(*idxs))
end
|
#zero? ⇒ Boolean
1274
1275
1276
|
# File 'lib/tk/variable.rb', line 1274
def zero?
numeric.zero?
end
|
1188
1189
1190
1191
1192
1193
1194
|
# File 'lib/tk/variable.rb', line 1188
def |(other)
if other.kind_of?(Array)
self.to_a | other.to_a
else
self.to_i | other.to_i
end
end
|