Class: TkNamespace
Defined Under Namespace
Classes: Ensemble, NsCode, ScopeArgs
Constant Summary
collapse
- TkCommandNames =
[
'namespace'.freeze,
].freeze
- Tk_Namespace_ID_TBL =
TkCore::INTERP.create_table
- Tk_Namespace_ID =
["ns".freeze, "00000".taint].freeze
- Tk_NsCode_RetObjID_TBL =
TkCore::INTERP.create_table
Constants included
from Tk
Tk::AUTO_PATH, 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
Constants included
from TkCore
TkCore::EventFlag, TkCore::INTERP, TkCore::WIDGET_DESTROY_HOOK
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
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Tk
BinaryString, EncodedString, UTF8_String, add_kinsoku, bell, bell_on_display, const_missing, current_grabs, cursor_display, 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, root, show_kinsoku, 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, ungrid, unload_tcllibrary, unpack, unplace, update, update, update_idletasks, utf_to_backslash, utf_to_backslash_sequence
#encoding, #encoding=, #encoding_convertfrom, #encoding_convertto, #encoding_dirs, #encoding_dirs=, #encoding_names, #encoding_system, #encoding_system=
Methods included from TkCore
#_tk_call_to_list_core, #after, #after_cancel, #after_idle, #appname, #appsend, #appsend_deny, #appsend_displayof, callback, #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_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, #windowingsystem
Methods included from TkComm
#_at, #bind, #bind_all, #bind_append, #bind_append_all, #bind_remove, #bind_remove_all, #bindinfo, #bindinfo_all, #image_obj, #subst, #uninstall_cmd
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, #bool, callback, eval_cmd, #hash_kv, hash_kv, install_cmd, num_or_str, #num_or_str, number, #number, string, #string, uninstall_cmd
Methods inherited from TkObject
#destroy, #epath, #event_generate, #method_missing, #path, #tk_send, #tk_send_to_list, #tk_send_to_list_with_enc, #tk_send_to_list_without_enc, #tk_send_to_simplelist, #tk_send_to_simplelist_with_enc, #tk_send_to_simplelist_without_enc, #tk_send_with_enc, #tk_send_without_enc, #to_eval
Methods included from TkBindCore
#bind, #bind_append, #bind_remove, #bindinfo
#[], #[]=, #cget, #config_hash_kv, #configinfo, #configure, #configure_cmd, #current_configinfo
#font_configinfo, #font_configure, #font_copy, #kanjifont_configure, #kanjifont_copy, #latinfont_configure, #latinfont_copy
Methods inherited from TkKernel
new
Constructor Details
#initialize(name = nil, parent = nil) ⇒ TkNamespace
Returns a new instance of TkNamespace.
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
|
# File 'lib/tk/namespace.rb', line 216
def initialize(name = nil, parent = nil)
unless name
name = Tk_Namespace_ID.join(TkCore::INTERP._ip_id_)
Tk_Namespace_ID[1].succ!
end
name = __tk_call('namespace', 'current') if name == ''
if parent
if parent =~ /^::/
if name =~ /^::/
@fullname = parent + name
else
@fullname = parent +'::'+ name
end
else
ancestor = __tk_call('namespace', 'current')
ancestor = '' if ancestor == '::'
if name =~ /^::/
@fullname = ancestor + '::' + parent + name
else
@fullname = ancestor + '::'+ parent +'::'+ name
end
end
else ancestor = __tk_call('namespace', 'current')
ancestor = '' if ancestor == '::'
if name =~ /^::/
@fullname = name
else
@fullname = ancestor + '::' + name
end
end
@path = @fullname
@parent = __tk_call('namespace', 'qualifiers', @fullname)
@name = __tk_call('namespace', 'tail', @fullname)
__tk_call('namespace', 'eval', @fullname, '')
Tk_Namespace_ID_TBL[@fullname] = self
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class TkObject
Class Method Details
.children(*args) ⇒ Object
258
259
260
261
262
263
264
265
266
267
268
269
|
# File 'lib/tk/namespace.rb', line 258
def self.children(*args)
tk_split_simplelist(tk_call('namespace', 'children', *args)).collect{|ns|
if Tk_Namespace_ID_TBL.key?(ns)
Tk_Namespace_ID_TBL[ns]
else
ns
end
}
end
|
.code(script = Proc.new) ⇒ Object
274
275
276
|
# File 'lib/tk/namespace.rb', line 274
def self.code(script = Proc.new)
TkNamespace.new('').code(script)
end
|
.current_path ⇒ Object
313
314
315
|
# File 'lib/tk/namespace.rb', line 313
def self.current_path
tk_call('namespace', 'current')
end
|
.delete(*ns_list) ⇒ Object
335
336
337
338
339
340
341
342
343
344
|
# File 'lib/tk/namespace.rb', line 335
def self.delete(*ns_list)
tk_call('namespace', 'delete', *ns_list)
ns_list.each{|ns|
if ns.kind_of?(TkNamespace)
Tk_Namespace_ID_TBL.delete(ns.path)
else
Tk_Namespace_ID_TBL.delete(ns.to_s)
end
}
end
|
.ensemble_configinfo(cmd, slot = nil) ⇒ Object
359
360
361
362
363
364
365
366
367
|
# File 'lib/tk/namespace.rb', line 359
def self.ensemble_configinfo(cmd, slot = nil)
if slot
tk_call('namespace', 'ensemble', 'configure', cmd, '-' + slot.to_s)
else
inf = {}
Hash(*tk_split_simplelist(tk_call('namespace', 'ensemble', 'configure', cmd))).each{|k, v| inf[k[1..-1]] = v}
inf
end
end
|
352
353
354
355
356
357
358
|
# File 'lib/tk/namespace.rb', line 352
def self.ensemble_configure(cmd, slot, value=None)
if slot.kind_of?(Hash)
tk_call('namespace', 'ensemble', 'configure', cmd, *hash_kv(slot))
else
tk_call('namespace', 'ensemble', 'configure', cmd, '-'+slot.to_s, value)
end
end
|
.ensemble_create(*keys) ⇒ Object
349
350
351
|
# File 'lib/tk/namespace.rb', line 349
def self.ensemble_create(*keys)
tk_call('namespace', 'ensemble', 'create', *hash_kv(keys))
end
|
.ensemble_exist?(cmd) ⇒ Boolean
368
369
370
|
# File 'lib/tk/namespace.rb', line 368
def self.ensemble_exist?(cmd)
bool(tk_call('namespace', 'ensemble', 'exists', cmd))
end
|
.eval(namespace, cmd = Proc.new, *args) ⇒ Object
372
373
374
375
|
# File 'lib/tk/namespace.rb', line 372
def self.eval(namespace, cmd = Proc.new, *args)
TkNamespace.new(namespece).eval(cmd, *args)
end
|
.exist?(ns) ⇒ Boolean
394
395
396
|
# File 'lib/tk/namespace.rb', line 394
def self.exist?(ns)
bool(tk_call('namespace', 'exists', ns))
end
|
.export(*patterns) ⇒ Object
401
402
403
|
# File 'lib/tk/namespace.rb', line 401
def self.export(*patterns)
tk_call('namespace', 'export', *patterns)
end
|
.export_with_clear(*patterns) ⇒ Object
404
405
406
|
# File 'lib/tk/namespace.rb', line 404
def self.export_with_clear(*patterns)
tk_call('namespace', 'export', '-clear', *patterns)
end
|
.force_import(*patterns) ⇒ Object
424
425
426
|
# File 'lib/tk/namespace.rb', line 424
def self.force_import(*patterns)
tk_call('namespace', 'import', '-force', *patterns)
end
|
.forget(*patterns) ⇒ Object
414
415
416
|
# File 'lib/tk/namespace.rb', line 414
def self.forget(*patterns)
tk_call('namespace', 'forget', *patterns)
end
|
457
458
459
|
# File 'lib/tk/namespace.rb', line 457
def self.get_path
tk_call('namespace', 'path')
end
|
.get_unknown_handler ⇒ Object
482
483
484
|
# File 'lib/tk/namespace.rb', line 482
def self.get_unknown_handler
tk_tcl2ruby(tk_call('namespace', 'unknown'))
end
|
.import(*patterns) ⇒ Object
421
422
423
|
# File 'lib/tk/namespace.rb', line 421
def self.import(*patterns)
tk_call('namespace', 'import', *patterns)
end
|
.inscope(namespace, script, *args) ⇒ Object
434
435
436
|
# File 'lib/tk/namespace.rb', line 434
def self.inscope(namespace, script, *args)
tk_call('namespace', 'inscope', namespace, script, *args)
end
|
.origin(cmd) ⇒ Object
441
442
443
|
# File 'lib/tk/namespace.rb', line 441
def self.origin(cmd)
tk_call('namespace', 'origin', cmd)
end
|
.parent(namespace = None) ⇒ Object
445
446
447
448
449
450
451
452
|
# File 'lib/tk/namespace.rb', line 445
def self.parent(namespace=None)
ns = tk_call('namespace', 'parent', namespace)
if Tk_Namespace_ID_TBL.key?(ns)
Tk_Namespace_ID_TBL[ns]
else
ns
end
end
|
.qualifiers(str) ⇒ Object
467
468
469
|
# File 'lib/tk/namespace.rb', line 467
def self.qualifiers(str)
tk_call('namespace', 'qualifiers', str)
end
|
.set_path(*namespace_list) ⇒ Object
460
461
462
|
# File 'lib/tk/namespace.rb', line 460
def self.set_path(*namespace_list)
tk_call('namespace', 'path', array2tk_list(namespace_list))
end
|
.set_unknown_handler(cmd = Proc.new) ⇒ Object
485
486
487
|
# File 'lib/tk/namespace.rb', line 485
def self.set_unknown_handler(cmd = Proc.new)
tk_call('namespace', 'unknown', cmd)
end
|
.tail(str) ⇒ Object
471
472
473
|
# File 'lib/tk/namespace.rb', line 471
def self.tail(str)
tk_call('namespace', 'tail', str)
end
|
.upvar(namespace, *var_pairs) ⇒ Object
475
476
477
|
# File 'lib/tk/namespace.rb', line 475
def self.upvar(namespace, *var_pairs)
tk_call('namespace', 'upvar', namespace, *(var_pairs.flatten))
end
|
.which(name) ⇒ Object
489
490
491
|
# File 'lib/tk/namespace.rb', line 489
def self.which(name)
tk_call('namespace', 'which', name)
end
|
.which_command(name) ⇒ Object
492
493
494
|
# File 'lib/tk/namespace.rb', line 492
def self.which_command(name)
tk_call('namespace', 'which', '-command', name)
end
|
.which_variable(name) ⇒ Object
495
496
497
|
# File 'lib/tk/namespace.rb', line 495
def self.which_variable(name)
tk_call('namespace', 'which', '-variable', name)
end
|
Instance Method Details
#__tk_call ⇒ Object
191
|
# File 'lib/tk/namespace.rb', line 191
alias __tk_call tk_call
|
#__tk_call_with_enc ⇒ Object
193
|
# File 'lib/tk/namespace.rb', line 193
alias __tk_call_with_enc tk_call_with_enc
|
#__tk_call_without_enc ⇒ Object
192
|
# File 'lib/tk/namespace.rb', line 192
alias __tk_call_without_enc tk_call_without_enc
|
#children(pattern = None) ⇒ Object
270
271
272
|
# File 'lib/tk/namespace.rb', line 270
def children(pattern=None)
TkNamespace.children(@fullname, pattern)
end
|
#code(script = Proc.new) ⇒ Object
def code(script = Proc.new)
if script.kind_of?(String)
cmd = proc{|*args| ScopeArgs.new(@fullname,*args).instance_eval(script)}
elsif script.kind_of?(Proc)
cmd = proc{|*args| ScopeArgs.new(@fullname,*args).instance_eval(&script)}
else
fail ArgumentError, "String or Proc is expected"
end
TkNamespace::NsCode.new(tk_call_without_enc('namespace', 'code',
_get_eval_string(cmd, false)))
end
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
|
# File 'lib/tk/namespace.rb', line 290
def code(script = Proc.new)
if script.kind_of?(String)
cmd = proc{|*args|
ret = ScopeArgs.new(@fullname,*args).instance_eval(script)
id = ret.object_id
TkNamespace::Tk_NsCode_RetObjID_TBL[id] = ret
id
}
elsif script.kind_of?(Proc)
cmd = proc{|*args|
ret = ScopeArgs.new(@fullname,*args).instance_eval(&script)
id = ret.object_id
TkNamespace::Tk_NsCode_RetObjID_TBL[id] = ret
id
}
else
fail ArgumentError, "String or Proc is expected"
end
TkNamespace::NsCode.new(tk_call_without_enc('namespace', 'code',
_get_eval_string(cmd, false)),
true)
end
|
#current_namespace ⇒ Object
Also known as:
current
328
329
330
331
332
|
# File 'lib/tk/namespace.rb', line 328
def current_namespace
self
end
|
#current_path ⇒ Object
316
317
318
|
# File 'lib/tk/namespace.rb', line 316
def current_path
@fullname
end
|
345
346
347
|
# File 'lib/tk/namespace.rb', line 345
def delete
TkNamespece.delete(@fullname)
end
|
#eval(cmd = Proc.new, *args) ⇒ Object
def eval(cmd = Proc.new, *args)
#TkNamespace.eval(@fullname, cmd, *args)
#ns_tk_call(cmd, *args)
code_obj = code(cmd)
ret = code_obj.call(*args)
# uninstall_cmd(TkCore::INTERP._split_tklist(code_obj.path)[-1])
uninstall_cmd(_fromUTF8(TkCore::INTERP._split_tklist(_toUTF8(code_obj.path))[-1]))
tk_tcl2ruby(ret)
end
387
388
389
390
391
392
|
# File 'lib/tk/namespace.rb', line 387
def eval(cmd = Proc.new, *args)
code_obj = code(cmd)
ret = code_obj.call(*args)
uninstall_cmd(_fromUTF8(TkCore::INTERP._split_tklist(_toUTF8(code_obj.path))[-1]))
ret
end
|
#exist? ⇒ Boolean
397
398
399
|
# File 'lib/tk/namespace.rb', line 397
def exist?
TkNamespece.exist?(@fullname)
end
|
407
408
409
|
# File 'lib/tk/namespace.rb', line 407
def export
TkNamespace.export(@fullname)
end
|
417
418
419
|
# File 'lib/tk/namespace.rb', line 417
def forget
TkNamespace.forget(@fullname)
end
|
427
428
429
|
# File 'lib/tk/namespace.rb', line 427
def import
TkNamespace.import(@fullname)
end
|
#inscope(script, *args) ⇒ Object
437
438
439
|
# File 'lib/tk/namespace.rb', line 437
def inscope(script, *args)
TkNamespace.inscope(@fullname, script, *args)
end
|
#install_cmd(cmd) ⇒ Object
181
182
183
184
185
186
187
188
189
|
# File 'lib/tk/namespace.rb', line 181
def install_cmd(cmd)
lst = tk_split_simplelist(super(cmd), false, false)
if lst[1] =~ /^::/
lst[1] = @fullname
else
lst.insert(1, @fullname)
end
TkCore::INTERP._merge_tklist(*lst)
end
|
453
454
455
|
# File 'lib/tk/namespace.rb', line 453
def parent
tk_call('namespace', 'parent', @fullname)
end
|
463
464
465
|
# File 'lib/tk/namespace.rb', line 463
def set_path
tk_call('namespace', 'path', @fullname)
end
|
#tk_call(*args) ⇒ Object
Also known as:
ns_tk_call
194
195
196
197
198
199
|
# File 'lib/tk/namespace.rb', line 194
def tk_call(*args)
args = args.collect{|arg| (s = _get_eval_string(arg, true))? s: ''}
super('namespace', 'eval', @fullname,
TkCore::INTERP._merge_tklist(*args))
end
|
#tk_call_with_enc(*args) ⇒ Object
Also known as:
ns_tk_call_with_enc
206
207
208
209
210
211
|
# File 'lib/tk/namespace.rb', line 206
def tk_call_with_enc(*args)
args = args.collect{|arg| (s = _get_eval_string(arg, true))? s: ''}
super('namespace', 'eval', @fullname,
TkCore::INTERP._merge_tklist(*args))
end
|
#tk_call_without_enc(*args) ⇒ Object
Also known as:
ns_tk_call_without_enc
200
201
202
203
204
205
|
# File 'lib/tk/namespace.rb', line 200
def tk_call_without_enc(*args)
args = args.collect{|arg| (s = _get_eval_string(arg, true))? s: ''}
super('namespace', 'eval', @fullname,
TkCore::INTERP._merge_tklist(*args))
end
|
#upvar(*var_pairs) ⇒ Object
478
479
480
|
# File 'lib/tk/namespace.rb', line 478
def upvar(*var_pairs)
TkNamespace.inscope(@fullname, *(var_pairs.flatten))
end
|