2
# tk.rb - Tk interface module using tcltklib
3
# $Date: 2007-02-13 08:01:19 +0900 (Tue, 13 Feb 2007) $
4
# by Yukihiro Matsumoto <matz@netlab.jp>
6
# use Shigehiro's tcltklib
14
# backup original (without encoding) _eval and _invoke
15
alias _eval_without_enc _eval
16
alias _invoke_without_enc _invoke
24
# define TkComm module (step 1: basic functions)
29
WidgetClassNames = {}.taint
30
TkExtlibAutoloadModule = [].taint
32
# None = Object.new ### --> definition is moved to TkUtil module
40
Tk_IDs = ["00000".taint, "00000".taint].freeze # [0]-cmdid, [1]-winid
42
# for backward compatibility
43
Tk_CMDTBL = Object.new
44
def Tk_CMDTBL.method_missing(id, *args)
45
TkCore::INTERP.tk_cmd_tbl.__send__(id, *args)
48
Tk_WINDOWS = Object.new
49
def Tk_WINDOWS.method_missing(id, *args)
50
TkCore::INTERP.tk_windows.__send__(id, *args)
58
unless const_defined?(:GET_CONFIGINFO_AS_ARRAY)
59
# GET_CONFIGINFO_AS_ARRAY = false => returns a Hash { opt =>val, ... }
60
# true => returns an Array [[opt,val], ... ]
61
# val is a list which includes resource info.
62
GET_CONFIGINFO_AS_ARRAY = true
64
unless const_defined?(:GET_CONFIGINFOwoRES_AS_ARRAY)
65
# for configinfo without resource info; list of [opt, value] pair
66
# false => returns a Hash { opt=>val, ... }
67
# true => returns an Array [[opt,val], ... ]
68
GET_CONFIGINFOwoRES_AS_ARRAY = true
71
# 'current_configinfo' method always returns a Hash under all cases of above.
75
frames.delete_if do |c|
76
c =~ %r!/tk(|core|thcore|canvas|text|entry|scrollbox)\.rb:\d+!
82
def _genobj_for_tkwidget(path)
83
return TkRoot.new if path == '.'
86
#tk_class = TkCore::INTERP._invoke('winfo', 'class', path)
87
tk_class = Tk.ip_invoke_without_enc('winfo', 'class', path)
92
if ruby_class = WidgetClassNames[tk_class]
93
ruby_class_name = ruby_class.name
94
# gen_class_name = ruby_class_name + 'GeneratedOnTk'
95
gen_class_name = ruby_class_name
97
else # ruby_class == nil
98
mods = TkExtlibAutoloadModule.find_all{|m| m.const_defined?(tk_class)}
101
mod.const_get(tk_class) # auto_load
102
break if (ruby_class = WidgetClassNames[tk_class])
109
std_class = 'Tk' << tk_class
110
if Object.const_defined?(std_class)
111
Object.const_get(std_class) # auto_load
112
ruby_class = WidgetClassNames[tk_class]
118
ruby_class_name = ruby_class.name
119
gen_class_name = ruby_class_name
123
ruby_class_name = 'TkWindow'
124
gen_class_name = 'TkWidget_' + tk_class
125
classname_def = "WidgetClassName = '#{tk_class}'.freeze"
129
###################################
131
if ruby_class = WidgetClassNames[tk_class]
132
ruby_class_name = ruby_class.name
133
# gen_class_name = ruby_class_name + 'GeneratedOnTk'
134
gen_class_name = ruby_class_name
137
mod = TkExtlibAutoloadModule.find{|m| m.const_defined?(tk_class)}
139
ruby_class_name = mod.name + '::' + tk_class
140
gen_class_name = ruby_class_name
142
elsif Object.const_defined?('Tk' + tk_class)
143
ruby_class_name = 'Tk' + tk_class
144
# gen_class_name = ruby_class_name + 'GeneratedOnTk'
145
gen_class_name = ruby_class_name
148
ruby_class_name = 'TkWindow'
149
# gen_class_name = ruby_class_name + tk_class + 'GeneratedOnTk'
150
gen_class_name = 'TkWidget_' + tk_class
151
classname_def = "WidgetClassName = '#{tk_class}'.freeze"
157
unless Object.const_defined? gen_class_name
158
Object.class_eval "class #{gen_class_name}<#{ruby_class_name}
162
Object.class_eval "#{gen_class_name}.new('widgetname'=>'#{path}',
163
'without_creating'=>true)"
166
gen_class_name.split('::').each{|klass|
168
if base.const_defined?(klass)
169
base = base.class_eval klass
171
base = base.class_eval "class #{klass}<#{ruby_class_name}
177
base.class_eval "#{gen_class_name}.new('widgetname'=>'#{path}',
178
'without_creating'=>true)"
180
private :_genobj_for_tkwidget
181
module_function :_genobj_for_tkwidget
185
"@#{Integer(x)},#{Integer(y)}"
192
def tk_tcl2ruby(val, enc_mode = false, listobj = true)
194
if val =~ /^rb_out\S* (c(_\d+_)?\d+)/
195
#return Tk_CMDTBL[$1]
196
return TkCore::INTERP.tk_cmd_tbl[$1]
197
#cmd_obj = TkCore::INTERP.tk_cmd_tbl[$1]
198
#if cmd_obj.kind_of?(Proc) || cmd_obj.kind_of?(Method)
205
if val =~ /rb_out\S*(?:\s+(::\S*|[{](::.*)[}]|["](::.*)["]))? (c(_\d+_)?(\d+))/
206
return TkCore::INTERP.tk_cmd_tbl[$4]
209
# return val.split.collect{|v| tk_tcl2ruby(v)}
217
#Tk_WINDOWS[val] ? Tk_WINDOWS[val] : _genobj_for_tkwidget(val)
218
TkCore::INTERP.tk_windows[val]?
219
TkCore::INTERP.tk_windows[val] : _genobj_for_tkwidget(val)
220
when /\Ai(_\d+_)?\d+\z/
221
TkImage::Tk_IMGTBL[val]? TkImage::Tk_IMGTBL[val] : val
222
when /\A-?\d+\.?\d*(e[-+]?\d+)?\z/
228
#tk_split_escstr(val).collect{|elt|
229
# tk_tcl2ruby(elt, enc_mode, listobj)
231
val = _toUTF8(val) unless enc_mode
232
tk_split_escstr(val, false, false).collect{|elt|
233
tk_tcl2ruby(elt, true, listobj)
250
module_function :tk_tcl2ruby
251
#private_class_method :tk_tcl2ruby
253
unless const_defined?(:USE_TCLs_LIST_FUNCTIONS)
254
USE_TCLs_LIST_FUNCTIONS = true
257
if USE_TCLs_LIST_FUNCTIONS
258
###########################################################################
259
# use Tcl function version of split_list
260
###########################################################################
262
def tk_split_escstr(str, src_enc=true, dst_enc=true)
263
str = _toUTF8(str) if src_enc
265
TkCore::INTERP._split_tklist(str).map!{|s| _fromUTF8(s)}
267
TkCore::INTERP._split_tklist(str)
271
def tk_split_sublist(str, depth=-1, src_enc=true, dst_enc=true)
272
# return [] if str == ""
273
# list = TkCore::INTERP._split_tklist(str)
274
str = _toUTF8(str) if src_enc
277
return "" if str == ""
280
return [] if str == ""
281
list = TkCore::INTERP._split_tklist(str)
284
# tk_tcl2ruby(list[0], nil, false)
285
tk_tcl2ruby(list[0], dst_enc, false)
287
list.collect{|token| tk_split_sublist(token, depth - 1, false, dst_enc)}
291
def tk_split_list(str, depth=0, src_enc=true, dst_enc=true)
292
return [] if str == ""
293
str = _toUTF8(str) if src_enc
294
TkCore::INTERP._split_tklist(str).map!{|token|
295
tk_split_sublist(token, depth - 1, false, dst_enc)
299
def tk_split_simplelist(str, src_enc=true, dst_enc=true)
300
#lst = TkCore::INTERP._split_tklist(str)
301
#if (lst.size == 1 && lst =~ /^\{.*\}$/)
302
# TkCore::INTERP._split_tklist(str[1..-2])
307
str = _toUTF8(str) if src_enc
309
TkCore::INTERP._split_tklist(str).map!{|s| _fromUTF8(s)}
311
TkCore::INTERP._split_tklist(str)
315
def array2tk_list(ary, enc=nil)
316
return "" if ary.size == 0
318
sys_enc = TkCore::INTERP.encoding
319
sys_enc = TclTkLib.encoding_system unless sys_enc
321
dst_enc = (enc == nil)? sys_enc: enc
323
dst = ary.collect{|e|
325
s = array2tk_list(e, enc)
326
elsif e.kind_of? Hash
328
#e.each{|k,v| tmp_ary << k << v }
329
e.each{|k,v| tmp_ary << "-#{_get_eval_string(k)}" << v }
330
s = array2tk_list(tmp_ary, enc)
332
s = _get_eval_string(e, enc)
335
if dst_enc != true && dst_enc != false
336
if (s_enc = s.instance_variable_get(:@encoding))
341
dst_enc = true if s_enc != dst_enc
347
if sys_enc && dst_enc
348
dst.map!{|s| _toUTF8(s)}
349
ret = TkCore::INTERP._merge_tklist(*dst)
350
if dst_enc.kind_of?(String)
351
ret = _fromUTF8(ret, dst_enc)
352
ret.instance_variable_set(:@encoding, dst_enc)
354
ret.instance_variable_set(:@encoding, 'utf-8')
358
TkCore::INTERP._merge_tklist(*dst)
363
###########################################################################
364
# use Ruby script version of split_list (traditional methods)
365
###########################################################################
367
def tk_split_escstr(str, src_enc=true, dst_enc=true)
368
return [] if str == ""
373
str.split('').each {|c|
374
brace += 1 if c == '{' && !escape
375
brace -= 1 if c == '}' && !escape
376
if brace == 0 && c == ' ' && !escape
377
list << token.gsub(/^\{(.*)\}$/, '\1') if token
380
token = (token || "") << c
382
escape = (c == '\\' && !escape)
384
list << token.gsub(/^\{(.*)\}$/, '\1') if token
388
def tk_split_sublist(str, depth=-1, src_enc=true, dst_enc=true)
389
#return [] if str == ""
390
#return [tk_split_sublist(str[1..-2])] if str =~ /^\{.*\}$/
391
#list = tk_split_escstr(str)
393
return "" if str == ""
394
str = str[1..-2] if str =~ /^\{.*\}$/
397
return [] if str == []
398
return [tk_split_sublist(str[1..-2], depth - 1)] if str =~ /^\{.*\}$/
399
list = tk_split_escstr(str)
402
tk_tcl2ruby(list[0], nil, false)
404
list.collect{|token| tk_split_sublist(token, depth - 1)}
408
def tk_split_list(str, depth=0, src_enc=true, dst_enc=true)
409
return [] if str == ""
410
tk_split_escstr(str).collect{|token|
411
tk_split_sublist(token, depth - 1)
415
def tk_split_list(str)
416
return [] if str == ""
418
while idx and idx > 0 and str[idx-1] == ?\\
419
idx = str.index('{', idx+1)
422
list = tk_tcl2ruby(str)
423
unless Array === list
429
list = tk_tcl2ruby(str[0,idx])
430
list = [] if list == ""
437
brace += 1 if c == ?{ && !escape
438
brace -= 1 if c == ?} && !escape
443
return tk_split_list(str[0, i])
448
list.push tk_split_list(str[0, i])
450
list += tk_split_list(str[i+1..-1])
455
def tk_split_simplelist(str, src_enc=true, dst_enc=true)
456
return [] if str == ""
461
str.split('').each {|c|
462
if c == '\\' && !escape
464
token = (token || "") << c if brace > 0
467
brace += 1 if c == '{' && !escape
468
brace -= 1 if c == '}' && !escape
469
if brace == 0 && c == ' ' && !escape
470
list << token.gsub(/^\{(.*)\}$/, '\1') if token
473
token = (token || "") << c
477
list << token.gsub(/^\{(.*)\}$/, '\1') if token
481
def array2tk_list(ary, enc=nil)
484
"{#{array2tk_list(e, enc)}}"
485
elsif e.kind_of? Hash
486
# "{#{e.to_a.collect{|ee| array2tk_list(ee)}.join(' ')}}"
487
e.each{|k,v| tmp_ary << "-#{_get_eval_string(k)}" << v }
488
array2tk_list(tmp_ary, enc)
490
s = _get_eval_string(e, enc)
491
(s.index(/\s/) || s.size == 0)? "{#{s}}": s
497
private :tk_split_escstr, :tk_split_sublist
498
private :tk_split_list, :tk_split_simplelist
499
private :array2tk_list
501
module_function :tk_split_escstr, :tk_split_sublist
502
module_function :tk_split_list, :tk_split_simplelist
503
module_function :array2tk_list
505
private_class_method :tk_split_escstr, :tk_split_sublist
506
private_class_method :tk_split_list, :tk_split_simplelist
507
# private_class_method :array2tk_list
510
### --> definition is moved to TkUtil module
511
def _symbolkey2str(keys)
513
keys.each{|key,value| h[key.to_s] = value}
516
private :_symbolkey2str
517
module_function :_symbolkey2str
521
### --> definition is moved to TkUtil module
522
# def hash_kv(keys, enc_mode = nil, conf = [], flat = false)
523
def hash_kv(keys, enc_mode = nil, conf = nil)
524
# Hash {key=>val, key=>val, ... } or Array [ [key, val], [key, val], ... ]
525
# ==> Array ['-key', val, '-key', val, ... ]
527
if keys and keys != None
530
dst.push('-' + k.to_s)
532
# v = _get_eval_string(v, enc_mode) if (enc_mode || flat)
533
v = _get_eval_string(v, enc_mode) if enc_mode
545
module_function :hash_kv
549
### --> definition is moved to TkUtil module
552
when "1", 1, 'yes', 'true'
563
when /^-?\d+\.?\d*(e[-+]?\d+)?$/
566
fail(ArgumentError, "invalid value for Number:'#{val}'")
572
elsif val[0] == ?{ && val[-1] == ?}
587
def list(val, depth=0, enc=true)
588
tk_split_list(val, depth, enc, enc)
590
def simplelist(val, src_enc=true, dst_enc=true)
591
tk_split_simplelist(val, src_enc, dst_enc)
595
#Tk_WINDOWS[val]? Tk_WINDOWS[val] : _genobj_for_tkwidget(val)
596
TkCore::INTERP.tk_windows[val]?
597
TkCore::INTERP.tk_windows[val] : _genobj_for_tkwidget(val)
603
if val =~ /^i(_\d+_)?\d+$/
604
TkImage::Tk_IMGTBL[val]? TkImage::Tk_IMGTBL[val] : val
611
if val =~ /^rb_out\S* (c(_\d+_)?\d+)/
613
#TkCore::INTERP.tk_cmd_tbl[$1]
614
TkCore::INTERP.tk_cmd_tbl[$1].cmd
616
if val =~ /rb_out\S*(?:\s+(::\S*|[{](::.*)[}]|["](::.*)["]))? (c(_\d+_)?(\d+))/
617
return TkCore::INTERP.tk_cmd_tbl[$4].cmd
623
private :bool, :number, :string, :num_or_str
624
private :list, :simplelist, :window, :procedure
625
module_function :bool, :number, :num_or_str, :string
626
module_function :list, :simplelist, :window, :image_obj, :procedure
628
def subst(str, *opts)
629
# opts := :nobackslashes | :nocommands | novariables
633
(opt[0] == ?-)? opt: '-' << opt
637
def _toUTF8(str, encoding = nil)
638
TkCore::INTERP._toUTF8(str, encoding)
640
def _fromUTF8(str, encoding = nil)
641
TkCore::INTERP._fromUTF8(str, encoding)
643
private :_toUTF8, :_fromUTF8
644
module_function :_toUTF8, :_fromUTF8
646
def _callback_entry_class?(cls)
647
cls <= Proc || cls <= Method || cls <= TkCallbackEntry
649
private :_callback_entry_class?
650
module_function :_callback_entry_class?
652
def _callback_entry?(obj)
653
obj.kind_of?(Proc) || obj.kind_of?(Method) || obj.kind_of?(TkCallbackEntry)
655
private :_callback_entry?
656
module_function :_callback_entry?
659
### --> definition is moved to TkUtil module
660
def _get_eval_string(str, enc_mode = nil)
661
return nil if str == None
662
if str.kind_of?(TkObject)
664
elsif str.kind_of?(String)
665
str = _toUTF8(str) if enc_mode
666
elsif str.kind_of?(Symbol)
668
str = _toUTF8(str) if enc_mode
669
elsif str.kind_of?(Hash)
670
str = hash_kv(str, enc_mode).join(" ")
671
elsif str.kind_of?(Array)
672
str = array2tk_list(str)
673
str = _toUTF8(str) if enc_mode
674
elsif str.kind_of?(Proc)
675
str = install_cmd(str)
682
elsif (str.respond_to?(:to_eval))
684
str = _toUTF8(str) if enc_mode
686
str = str.to_s() || ''
687
unless str.kind_of? String
688
fail RuntimeError, "fail to convert the object to a string"
690
str = _toUTF8(str) if enc_mode
696
def _get_eval_string(obj, enc_mode = nil)
701
(enc_mode)? _toUTF8(obj): obj
703
(enc_mode)? _toUTF8(obj.id2name): obj.id2name
707
hash_kv(obj, enc_mode).join(' ')
709
(enc_mode)? _toUTF8(array2tk_list(obj)): array2tk_list(obj)
710
when Proc, Method, TkCallbackEntry
721
if (obj.respond_to?(:to_eval))
722
(enc_mode)? _toUTF8(obj.to_eval): obj.to_eval
727
fail RuntimeError, "fail to convert object '#{obj}' to string"
729
(enc_mode)? _toUTF8(obj): obj
733
private :_get_eval_string
734
module_function :_get_eval_string
738
### --> definition is moved to TkUtil module
739
def _get_eval_enc_str(obj)
740
return obj if obj == None
741
_get_eval_string(obj, true)
743
private :_get_eval_enc_str
744
module_function :_get_eval_enc_str
749
def ruby2tcl(v, enc_mode = nil)
753
v.collect{|e|ruby2tcl(e, enc_mode)}
755
_get_eval_string(v, enc_mode)
762
### --> definition is moved to TkUtil module
763
def _conv_args(args, enc_mode, *src_args)
766
conv_args << _get_eval_string(arg, enc_mode) unless arg == None
767
# if arg.kind_of?(Hash)
769
# args << '-' + k.to_s
770
# args << _get_eval_string(v, enc_mode)
773
# args << _get_eval_string(arg, enc_mode)
782
#id = format("c%.4d", Tk_IDs[0])
783
id = "c" + TkCore::INTERP._ip_id_ + TkComm::Tk_IDs[0]
788
TkComm::Tk_IDs[0].succ!
791
private :_curr_cmd_id, :_next_cmd_id
792
module_function :_curr_cmd_id, :_next_cmd_id
795
return '' if cmd == ''
797
ns = TkCore::INTERP._invoke_without_enc('namespace', 'current')
798
ns = nil if ns == '::' # for backward compatibility
805
if cmd.kind_of?(TkCallbackEntry)
806
TkCore::INTERP.tk_cmd_tbl[id] = cmd
808
TkCore::INTERP.tk_cmd_tbl[id] = TkCore::INTERP.get_cb_entry(cmd)
810
@cmdtbl = [] unless defined? @cmdtbl
811
@cmdtbl.taint unless @cmdtbl.tainted?
813
#return Kernel.format("rb_out %s", id);
815
'rb_out' << TkCore::INTERP._ip_id_ << ' ' << ns << ' ' << id
817
'rb_out' << TkCore::INTERP._ip_id_ << ' ' << id
820
def uninstall_cmd(id)
821
#id = $1 if /rb_out\S* (c(_\d+_)?\d+)/ =~ id
822
id = $4 if id =~ /rb_out\S*(?:\s+(::\S*|[{](::.*)[}]|["](::.*)["]))? (c(_\d+_)?(\d+))/
823
#Tk_CMDTBL.delete(id)
824
TkCore::INTERP.tk_cmd_tbl.delete(id)
826
# private :install_cmd, :uninstall_cmd
827
module_function :install_cmd, :uninstall_cmd
830
def install_win(ppath,name=nil)
831
if !name or name == ''
832
#name = format("w%.4d", Tk_IDs[1])
834
name = "w" + Tk_IDs[1]
839
elsif !ppath or ppath == "."
840
@path = Kernel.format(".%s", name);
842
@path = Kernel.format("%s.%s", ppath, name)
844
#Tk_WINDOWS[@path] = self
845
TkCore::INTERP.tk_windows[@path] = self
848
def install_win(ppath,name=nil)
851
raise ArgumentError, "invalid wiget-name '#{name}'"
856
return TkCore::INTERP.tk_windows[@path] = self
859
name = "w" + TkCore::INTERP._ip_id_ + Tk_IDs[1]
862
if !ppath or ppath == '.'
865
@path = ppath + '.' + name
868
TkCore::INTERP.tk_windows[@path] = self
872
#Tk_WINDOWS.delete(@path)
873
TkCore::INTERP.tk_windows.delete(@path)
875
private :install_win, :uninstall_win
878
if win.kind_of?(TkObject)
880
elsif win.respond_to?(:epath)
889
# define TkComm module (step 2: event binding)
894
def tk_event_sequence(context)
895
if context.kind_of? TkVirtualEvent
896
context = context.path
898
if context.kind_of? Array
899
context = context.collect{|ev|
900
if ev.kind_of? TkVirtualEvent
908
context = context.split(/\s*,\s*/).join("><")
914
def _bind_core(mode, what, context, cmd, *args)
915
id = install_bind(cmd, *args) if cmd
917
tk_call_without_enc(*(what + ["<#{tk_event_sequence(context)}>",
920
uninstall_cmd(id) if cmd
925
def _bind(what, context, cmd, *args)
926
_bind_core('', what, context, cmd, *args)
929
def _bind_append(what, context, cmd, *args)
930
_bind_core('+', what, context, cmd, *args)
933
def _bind_remove(what, context)
934
tk_call_without_enc(*(what + ["<#{tk_event_sequence(context)}>", '']))
937
def _bindinfo(what, context=nil)
939
tk_call_without_enc(*what+["<#{tk_event_sequence(context)}>"]) .collect {|cmdline|
941
if cmdline =~ /^rb_out\S* (c(?:_\d+_)?\d+)\s+(.*)$/
943
[TkCore::INTERP.tk_cmd_tbl[$1], $2]
945
if cmdline =~ /rb_out\S*(?:\s+(::\S*|[{](::.*)[}]|["](::.*)["]))? (c(_\d+_)?(\d+))/
946
[TkCore::INTERP.tk_cmd_tbl[$4], $5]
952
tk_split_simplelist(tk_call_without_enc(*what)).collect!{|seq|
953
l = seq.scan(/<*[^<>]+>*/).collect!{|subseq|
956
TkVirtualEvent.getobj(subseq[1..-2])
963
(l.size == 1) ? l[0] : l
968
def _bind_core_for_event_class(klass, mode, what, context, cmd, *args)
969
id = install_bind_for_event_class(klass, cmd, *args) if cmd
971
tk_call_without_enc(*(what + ["<#{tk_event_sequence(context)}>",
974
uninstall_cmd(id) if cmd
979
def _bind_for_event_class(klass, what, context, cmd, *args)
980
_bind_core_for_event_class(klass, '', what, context, cmd, *args)
983
def _bind_append_for_event_class(klass, what, context, cmd, *args)
984
_bind_core_for_event_class(klass, '+', what, context, cmd, *args)
987
def _bind_remove_for_event_class(klass, what, context)
988
_bind_remove(what, context)
991
def _bindinfo_for_event_class(klass, what, context=nil)
992
_bindinfo(what, context)
995
private :tk_event_sequence
996
private :_bind_core, :_bind, :_bind_append, :_bind_remove, :_bindinfo
997
private :_bind_core_for_event_class, :_bind_for_event_class,
998
:_bind_append_for_event_class, :_bind_remove_for_event_class,
999
:_bindinfo_for_event_class
1001
#def bind(tagOrClass, context, cmd=Proc.new, *args)
1002
# _bind(["bind", tagOrClass], context, cmd, *args)
1005
def bind(tagOrClass, context, *args)
1006
# if args[0].kind_of?(Proc) || args[0].kind_of?(Method)
1007
if TkComm._callback_entry?(args[0]) || !block_given?
1012
_bind(["bind", tagOrClass], context, cmd, *args)
1016
#def bind_append(tagOrClass, context, cmd=Proc.new, *args)
1017
# _bind_append(["bind", tagOrClass], context, cmd, *args)
1020
def bind_append(tagOrClass, context, *args)
1021
# if args[0].kind_of?(Proc) || args[0].kind_of?(Method)
1022
if TkComm._callback_entry?(args[0]) || !block_given?
1027
_bind_append(["bind", tagOrClass], context, cmd, *args)
1031
def bind_remove(tagOrClass, context)
1032
_bind_remove(['bind', tagOrClass], context)
1036
def bindinfo(tagOrClass, context=nil)
1037
_bindinfo(['bind', tagOrClass], context)
1040
#def bind_all(context, cmd=Proc.new, *args)
1041
# _bind(['bind', 'all'], context, cmd, *args)
1044
def bind_all(context, *args)
1045
# if args[0].kind_of?(Proc) || args[0].kind_of?(Method)
1046
if TkComm._callback_entry?(args[0]) || !block_given?
1051
_bind(['bind', 'all'], context, cmd, *args)
1055
#def bind_append_all(context, cmd=Proc.new, *args)
1056
# _bind_append(['bind', 'all'], context, cmd, *args)
1059
def bind_append_all(context, *args)
1060
# if args[0].kind_of?(Proc) || args[0].kind_of?(Method)
1061
if TkComm._callback_entry?(args[0]) || !block_given?
1066
_bind_append(['bind', 'all'], context, cmd, *args)
1070
def bind_remove_all(context)
1071
_bind_remove(['bind', 'all'], context)
1075
def bindinfo_all(context=nil)
1076
_bindinfo(['bind', 'all'], context)
1085
unless self.const_defined? :INTERP
1086
if self.const_defined? :IP_NAME
1092
if self.const_defined? :IP_OPTS
1093
if IP_OPTS.kind_of?(Hash)
1094
opts = hash_kv(IP_OPTS).join(' ')
1102
INTERP = TclTkIp.new(name, opts)
1108
INTERP.instance_eval{
1109
@tk_cmd_tbl = {}.taint
1110
def @tk_cmd_tbl.[]=(idx,val)
1111
if self.has_key?(idx) && Thread.current.group != ThreadGroup::Default
1112
fail SecurityError,"cannot change the entried command"
1117
@tk_windows = {}.taint
1119
@tk_table_list = [].taint
1121
@init_ip_env = [].taint # table of Procs
1122
@add_tk_procs = [].taint # table of [name, args, body]
1124
@cb_entry_class = Class.new(TkCallbackEntry){
1127
sprintf("#<Class(TkCallbackEntry):%0x>", self.__id__)
1132
def initialize(ip, cmd)
1136
attr_reader :ip, :cmd
1138
@ip.cb_eval(@cmd, *args)
1141
sprintf("#<cb_entry:%0x>", self.__id__)
1147
def INTERP.cb_entry_class
1150
def INTERP.tk_cmd_tbl
1153
def INTERP.tk_windows
1157
class Tk_OBJECT_TABLE
1161
def method_missing(m, *args, &b)
1162
TkCore::INTERP.tk_object_table(@id).__send__(m, *args, &b)
1166
def INTERP.tk_object_table(id)
1169
def INTERP.create_table
1170
id = @tk_table_list.size
1171
(tbl = {}).tainted? || tbl.taint
1172
@tk_table_list << tbl
1174
# obj.instance_eval <<-EOD
1175
# def self.method_missing(m, *args)
1176
# TkCore::INTERP.tk_object_table(#{id}).send(m, *args)
1180
Tk_OBJECT_TABLE.new(id)
1183
def INTERP.get_cb_entry(cmd)
1184
@cb_entry_class.new(__getip, cmd).freeze
1186
def INTERP.cb_eval(cmd, *args)
1187
TkUtil._get_eval_string(TkUtil.eval_cmd(cmd, *args))
1190
def INTERP.init_ip_env(script = Proc.new)
1191
@init_ip_env << script
1194
def INTERP.add_tk_procs(name, args = nil, body = nil)
1195
if name.kind_of?(Array)
1196
name.each{|param| self.add_tk_procs(*param)}
1199
@add_tk_procs << [name, args, body]
1200
self._invoke('proc', name, args, body) if args && body
1203
def INTERP.remove_tk_procs(*names)
1206
@add_tk_procs.delete_if{|elem|
1207
elem.kind_of?(Array) && elem[0].to_s == name
1209
self._invoke('rename', name, '')
1212
def INTERP.init_ip_internal
1214
@init_ip_env.each{|script| script.call(ip)}
1215
@add_tk_procs.each{|name,args,body| ip._invoke('proc',name,args,body)}
1219
WIDGET_DESTROY_HOOK = '<WIDGET_DESTROY_HOOK>'
1220
INTERP._invoke_without_enc('event', 'add',
1221
"<#{WIDGET_DESTROY_HOOK}>", '<Destroy>')
1222
INTERP._invoke_without_enc('bind', 'all', "<#{WIDGET_DESTROY_HOOK}>",
1223
install_cmd(proc{|path|
1224
unless TkCore::INTERP.deleted?
1226
if (widget=TkCore::INTERP.tk_windows[path])
1227
if widget.respond_to?(:__destroy_hook__)
1228
widget.__destroy_hook__
1237
INTERP.add_tk_procs(TclTkLib::FINALIZE_PROC_NAME, '',
1238
"bind all <#{WIDGET_DESTROY_HOOK}> {}")
1240
INTERP.add_tk_procs('rb_out', 'ns args', <<-'EOL')
1241
if [regexp {^::} $ns] {
1242
set cmd {namespace eval $ns {ruby_cmd TkCore callback} $args}
1244
set cmd {eval {ruby_cmd TkCore callback} $ns $args}
1246
if {[set st [catch $cmd ret]] != 0} {
1247
#return -code $st $ret
1248
set idx [string first "\n\n" $ret]
1251
-errorinfo [string range $ret [expr $idx + 2] \
1252
[string length $ret]] \
1253
[string range $ret 0 [expr $idx - 1]]
1255
return -code $st $ret
1262
INTERP.add_tk_procs('rb_out', 'args', <<-'EOL')
1263
if {[set st [catch {eval {ruby_cmd TkCore callback} $args} ret]] != 0} {
1264
#return -code $st $ret
1265
set idx [string first "\n\n" $ret]
1268
-errorinfo [string range $ret [expr $idx + 2] \
1269
[string length $ret]] \
1270
[string range $ret 0 [expr $idx - 1]]
1272
return -code $st $ret
1280
INTERP.add_tk_procs('rb_out', 'args', <<-'EOL')
1281
#regsub -all {\\} $args {\\\\} args
1282
#regsub -all {!} $args {\\!} args
1283
#regsub -all "{" $args "\\{" args
1284
regsub -all {(\\|!|\{|\})} $args {\\\1} args
1285
if {[set st [catch {ruby [format "TkCore.callback %%Q!%s!" $args]} ret]] != 0} {
1286
#return -code $st $ret
1287
set idx [string first "\n\n" $ret]
1290
-errorinfo [string range $ret [expr $idx + 2] \
1291
[string length $ret]] \
1292
[string range $ret 0 [expr $idx - 1]]
1294
return -code $st $ret
1302
at_exit{ INTERP.remove_tk_procs(TclTkLib::FINALIZE_PROC_NAME) }
1304
EventFlag = TclTkLib::EventFlag
1307
fail TkCallbackBreak, "Tk callback returns 'break' status"
1310
def callback_continue
1311
fail TkCallbackContinue, "Tk callback returns 'continue' status"
1315
fail TkCallbackReturn, "Tk callback returns 'return' status"
1318
def TkCore.callback(*arg)
1320
if TkCore::INTERP.tk_cmd_tbl.kind_of?(Hash)
1321
#TkCore::INTERP.tk_cmd_tbl[arg.shift].call(*arg)
1323
ret = catch(:IRB_EXIT) do # IRB hack
1324
retval = TkCore::INTERP.tk_cmd_tbl[arg.shift].call(*arg)
1334
rescue SystemExit=>e
1338
rescue Exception => e
1340
msg = _toUTF8(e.class.inspect) + ': ' +
1341
_toUTF8(e.message) + "\n" +
1342
"\n---< backtrace of Ruby side >-----\n" +
1343
_toUTF8(e.backtrace.join("\n")) +
1344
"\n---< backtrace of Tk side >-------"
1345
msg.instance_variable_set(:@encoding, 'utf-8')
1347
msg = e.class.inspect + ': ' + e.message + "\n" +
1348
"\n---< backtrace of Ruby side >-----\n" +
1349
e.backtrace.join("\n") +
1350
"\n---< backtrace of Tk side >-------"
1352
# TkCore::INTERP._set_global_var('errorInfo', msg)
1358
def TkCore.callback(arg_str)
1359
# arg = tk_split_list(arg_str)
1360
arg = tk_split_simplelist(arg_str)
1361
#_get_eval_string(TkUtil.eval_cmd(Tk_CMDTBL[arg.shift], *arg))
1362
#_get_eval_string(TkUtil.eval_cmd(TkCore::INTERP.tk_cmd_tbl[arg.shift],
1364
# TkCore::INTERP.tk_cmd_tbl[arg.shift].call(*arg)
1366
TkCore::INTERP.tk_cmd_tbl[arg.shift].call(*arg)
1367
rescue Exception => e
1368
raise(e, e.class.inspect + ': ' + e.message + "\n" +
1369
"\n---< backtrace of Ruby side >-----\n" +
1370
e.backtrace.join("\n") +
1371
"\n---< backtrace of Tk side >-------")
1374
# cb_obj = TkCore::INTERP.tk_cmd_tbl[arg.shift]
1379
# raise 'check backtrace'
1381
# # ignore backtrace before 'callback'
1382
# pos = -($!.backtrace.size)
1387
# trace = $!.backtrace
1388
# raise $!, "\n#{trace[0]}: #{$!.message} (#{$!.class})\n" +
1389
# "\tfrom #{trace[1..pos].join("\n\tfrom ")}"
1396
def load_cmd_on_ip(tk_cmd)
1397
bool(tk_call('auto_load', tk_cmd))
1400
def after(ms, cmd=Proc.new)
1401
crit_bup = Thread.critical
1402
Thread.critical = true
1405
cmdid = install_cmd(proc{ret = cmd.call;uninstall_cmd(myid); ret})
1407
Thread.critical = crit_bup
1409
tk_call_without_enc("after",ms,cmdid) # return id
1411
# if false #defined? Thread
1413
# ms = Float(ms)/1000
1414
# ms = 10 if ms == 0
1419
# cmdid = install_cmd(cmd)
1420
# tk_call("after",ms,cmdid)
1424
def after_idle(cmd=Proc.new)
1425
crit_bup = Thread.critical
1426
Thread.critical = true
1429
cmdid = install_cmd(proc{ret = cmd.call;uninstall_cmd(myid); ret})
1431
Thread.critical = crit_bup
1433
tk_call_without_enc('after','idle',cmdid)
1436
def after_cancel(afterId)
1437
tk_call_without_enc('after','cancel',afterId)
1441
tk_call_without_enc('tk', 'windowingsystem')
1444
def scaling(scale=nil)
1446
tk_call_without_enc('tk', 'scaling', scale)
1448
Float(number(tk_call_without_enc('tk', 'scaling')))
1451
def scaling_displayof(win, scale=nil)
1453
tk_call_without_enc('tk', 'scaling', '-displayof', win, scale)
1455
Float(number(tk_call_without_enc('tk', '-displayof', win, 'scaling')))
1460
Integer(tk_call_without_enc('tk', 'inactive'))
1462
def inactive_displayof(win)
1463
Integer(tk_call_without_enc('tk', 'inactive', '-displayof', win))
1466
tk_call_without_enc('tk', 'inactive', 'reset')
1468
def reset_inactive_displayof(win)
1469
tk_call_without_enc('tk', 'inactive', '-displayof', win, 'reset')
1472
def appname(name=None)
1473
tk_call('tk', 'appname', name)
1477
tk_call('rename', 'send', '')
1480
def appsend(interp, async, *args)
1482
fail SecurityError, "cannot send Tk commands at level 4"
1483
elsif $SAFE >= 1 && args.find{|obj| obj.tainted?}
1484
fail SecurityError, "cannot send tainted Tk commands at level #{$SAFE}"
1486
if async != true && async != false && async != nil
1491
tk_call('send', '-async', '--', interp, *args)
1493
tk_call('send', '--', interp, *args)
1497
def rb_appsend(interp, async, *args)
1499
fail SecurityError, "cannot send Ruby commands at level 4"
1500
elsif $SAFE >= 1 && args.find{|obj| obj.tainted?}
1501
fail SecurityError, "cannot send tainted Ruby commands at level #{$SAFE}"
1503
if async != true && async != false && async != nil
1507
#args = args.collect!{|c| _get_eval_string(c).gsub(/[\[\]$"]/, '\\\\\&')}
1508
args = args.collect!{|c| _get_eval_string(c).gsub(/[\[\]$"\\]/, '\\\\\&')}
1509
# args.push(').to_s"')
1510
# appsend(interp, async, 'ruby "(', *args)
1511
args.push('}.call)"')
1512
appsend(interp, async, 'ruby "TkComm._get_eval_string(proc{', *args)
1515
def appsend_displayof(interp, win, async, *args)
1517
fail SecurityError, "cannot send Tk commands at level 4"
1518
elsif $SAFE >= 1 && args.find{|obj| obj.tainted?}
1519
fail SecurityError, "cannot send tainted Tk commands at level #{$SAFE}"
1521
win = '.' if win == nil
1522
if async != true && async != false && async != nil
1527
tk_call('send', '-async', '-displayof', win, '--', interp, *args)
1529
tk_call('send', '-displayor', win, '--', interp, *args)
1533
def rb_appsend_displayof(interp, win, async, *args)
1535
fail SecurityError, "cannot send Ruby commands at level 4"
1536
elsif $SAFE >= 1 && args.find{|obj| obj.tainted?}
1537
fail SecurityError, "cannot send tainted Ruby commands at level #{$SAFE}"
1539
win = '.' if win == nil
1540
if async != true && async != false && async != nil
1544
#args = args.collect!{|c| _get_eval_string(c).gsub(/[\[\]$"]/, '\\\\\&')}
1545
args = args.collect!{|c| _get_eval_string(c).gsub(/[\[\]$"\\]/, '\\\\\&')}
1546
# args.push(').to_s"')
1547
# appsend_displayof(interp, win, async, 'ruby "(', *args)
1548
args.push('}.call)"')
1549
appsend(interp, win, async, 'ruby "TkComm._get_eval_string(proc{', *args)
1553
tk_call('info', *args)
1556
def mainloop(check_root = true)
1557
TclTkLib.mainloop(check_root)
1560
def mainloop_thread?
1561
# true : current thread is mainloop
1562
# nil : there is no mainloop
1563
# false : mainloop is running on the other thread
1564
# ( At then, it is dangerous to call Tk interpreter directly. )
1565
TclTkLib.mainloop_thread?
1569
TclTkLib.mainloop_thread? != nil
1573
TclTkLib.mainloop_thread? == true
1576
def mainloop_watchdog(check_root = true)
1577
# watchdog restarts mainloop when mainloop is dead
1578
TclTkLib.mainloop_watchdog(check_root)
1581
def do_one_event(flag = TclTkLib::EventFlag::ALL)
1582
TclTkLib.do_one_event(flag)
1585
def set_eventloop_tick(timer_tick)
1586
TclTkLib.set_eventloop_tick(timer_tick)
1589
def get_eventloop_tick()
1590
TclTkLib.get_eventloop_tick
1593
def set_no_event_wait(wait)
1594
TclTkLib.set_no_even_wait(wait)
1597
def get_no_event_wait()
1598
TclTkLib.get_no_eventloop_wait
1601
def set_eventloop_weight(loop_max, no_event_tick)
1602
TclTkLib.set_eventloop_weight(loop_max, no_event_tick)
1605
def get_eventloop_weight()
1606
TclTkLib.get_eventloop_weight
1609
def restart(app_name = nil, keys = {})
1610
TkCore::INTERP.init_ip_internal
1612
tk_call('set', 'argv0', app_name) if app_name
1613
if keys.kind_of?(Hash)
1614
# tk_call('set', 'argc', keys.size * 2)
1615
tk_call('set', 'argv', hash_kv(keys).join(' '))
1622
def event_generate(win, context, keys=nil)
1623
#win = win.path if win.kind_of?(TkObject)
1624
if context.kind_of?(TkEvent::Event)
1625
context.generate(win, ((keys)? keys: {}))
1627
tk_call_without_enc('event', 'generate', win,
1628
"<#{tk_event_sequence(context)}>",
1629
*hash_kv(keys, true))
1631
tk_call_without_enc('event', 'generate', win,
1632
"<#{tk_event_sequence(context)}>")
1637
def messageBox(keys)
1638
tk_call('tk_messageBox', *hash_kv(keys))
1641
def getOpenFile(keys = nil)
1642
tk_call('tk_getOpenFile', *hash_kv(keys))
1644
def getMultipleOpenFile(keys = nil)
1645
simplelist(tk_call('tk_getOpenFile', '-multiple', '1', *hash_kv(keys)))
1648
def getSaveFile(keys = nil)
1649
tk_call('tk_getSaveFile', *hash_kv(keys))
1651
def getMultipleSaveFile(keys = nil)
1652
simplelist(tk_call('tk_getSaveFile', '-multiple', '1', *hash_kv(keys)))
1655
def chooseColor(keys = nil)
1656
tk_call('tk_chooseColor', *hash_kv(keys))
1659
def chooseDirectory(keys = nil)
1660
tk_call('tk_chooseDirectory', *hash_kv(keys))
1663
def _ip_eval_core(enc_mode, cmd_string)
1666
res = INTERP._eval(cmd_string)
1668
res = INTERP._eval_without_enc(cmd_string)
1670
res = INTERP._eval_with_enc(cmd_string)
1672
if INTERP._return_value() != 0
1673
fail RuntimeError, res, error_at
1677
private :_ip_eval_core
1679
def ip_eval(cmd_string)
1680
_ip_eval_core(nil, cmd_string)
1683
def ip_eval_without_enc(cmd_string)
1684
_ip_eval_core(false, cmd_string)
1687
def ip_eval_with_enc(cmd_string)
1688
_ip_eval_core(true, cmd_string)
1691
def _ip_invoke_core(enc_mode, *args)
1694
res = INTERP._invoke_without_enc(*args)
1696
res = INTERP._invoke(*args)
1698
res = INTERP._invoke_with_enc(*args)
1700
if INTERP._return_value() != 0
1701
fail RuntimeError, res, error_at
1705
private :_ip_invoke_core
1707
def ip_invoke(*args)
1708
_ip_invoke_core(nil, *args)
1711
def ip_invoke_without_enc(*args)
1712
_ip_invoke_core(false, *args)
1715
def ip_invoke_with_enc(*args)
1716
_ip_invoke_core(true, *args)
1719
def _tk_call_core(enc_mode, *args)
1720
### puts args.inspect if $DEBUG
1721
#args.collect! {|x|ruby2tcl(x, enc_mode)}
1724
args = _conv_args([], enc_mode, *args)
1725
puts 'invoke args => ' + args.inspect if $DEBUG
1726
### print "=> ", args.join(" ").inspect, "\n" if $DEBUG
1728
# res = INTERP._invoke(*args).taint
1729
# res = INTERP._invoke(enc_mode, *args)
1730
res = _ip_invoke_core(enc_mode, *args)
1731
# >>>>> _invoke returns a TAINTED string <<<<<
1732
rescue NameError => err
1735
args.unshift "unknown"
1736
#res = INTERP._invoke(*args).taint
1737
#res = INTERP._invoke(enc_mode, *args)
1738
res = _ip_invoke_core(enc_mode, *args)
1739
# >>>>> _invoke returns a TAINTED string <<<<<
1740
rescue StandardError => err2
1741
fail err2 unless /^invalid command/ =~ err2.message
1745
if INTERP._return_value() != 0
1746
fail RuntimeError, res, error_at
1748
### print "==> ", res.inspect, "\n" if $DEBUG
1751
private :_tk_call_core
1754
_tk_call_core(nil, *args)
1757
def tk_call_without_enc(*args)
1758
_tk_call_core(false, *args)
1761
def tk_call_with_enc(*args)
1762
_tk_call_core(true, *args)
1765
def _tk_call_to_list_core(depth, arg_enc, val_enc, *args)
1766
args = _conv_args([], arg_enc, *args)
1767
val = _tk_call_core(false, *args)
1768
if !depth.kind_of?(Integer) || depth == 0
1769
tk_split_simplelist(val, false, val_enc)
1771
tk_split_list(val, depth, false, val_enc)
1774
#private :_tk_call_to_list_core
1776
def tk_call_to_list(*args)
1777
_tk_call_to_list_core(-1, nil, true, *args)
1780
def tk_call_to_list_without_enc(*args)
1781
_tk_call_to_list_core(-1, false, false, *args)
1784
def tk_call_to_list_with_enc(*args)
1785
_tk_call_to_list_core(-1, true, true, *args)
1788
def tk_call_to_simplelist(*args)
1789
_tk_call_to_list_core(0, nil, true, *args)
1792
def tk_call_to_simplelist_without_enc(*args)
1793
_tk_call_to_list_core(0, false, false, *args)
1796
def tk_call_to_simplelist_with_enc(*args)
1797
_tk_call_to_list_core(0, true, true, *args)
1806
TCL_VERSION = INTERP._invoke_without_enc("info", "tclversion").freeze
1807
TCL_PATCHLEVEL = INTERP._invoke_without_enc("info", "patchlevel").freeze
1809
major, minor = TCL_VERSION.split('.')
1810
TCL_MAJOR_VERSION = major.to_i
1811
TCL_MINOR_VERSION = minor.to_i
1813
TK_VERSION = INTERP._invoke_without_enc("set", "tk_version").freeze
1814
TK_PATCHLEVEL = INTERP._invoke_without_enc("set", "tk_patchLevel").freeze
1816
major, minor = TK_VERSION.split('.')
1817
TK_MAJOR_VERSION = major.to_i
1818
TK_MINOR_VERSION = minor.to_i
1820
JAPANIZED_TK = (INTERP._invoke_without_enc("info", "commands",
1821
"kanji") != "").freeze
1823
def Tk.const_missing(sym)
1826
INTERP._invoke_without_enc('global', 'tcl_library')
1827
INTERP._invoke("set", "tcl_library").freeze
1830
INTERP._invoke_without_enc('global', 'tk_library')
1831
INTERP._invoke("set", "tk_library").freeze
1834
INTERP._invoke("info", "library").freeze
1836
#when :PKG_PATH, :PACKAGE_PATH, :TCL_PACKAGE_PATH
1837
# INTERP._invoke_without_enc('global', 'tcl_pkgPath')
1838
# tk_split_simplelist(INTERP._invoke('set', 'tcl_pkgPath'))
1840
#when :LIB_PATH, :LIBRARY_PATH, :TCL_LIBRARY_PATH
1841
# INTERP._invoke_without_enc('global', 'tcl_libPath')
1842
# tk_split_simplelist(INTERP._invoke('set', 'tcl_libPath'))
1844
when :PLATFORM, :TCL_PLATFORM
1846
fail SecurityError, "can't get #{sym} when $SAFE >= 4"
1848
INTERP._invoke_without_enc('global', 'tcl_platform')
1849
Hash[*tk_split_simplelist(INTERP._invoke_without_enc('array', 'get',
1853
INTERP._invoke_without_enc('global', 'env')
1854
Hash[*tk_split_simplelist(INTERP._invoke('array', 'get', 'env'))]
1856
#when :AUTO_PATH #<===
1857
# tk_split_simplelist(INTERP._invoke('set', 'auto_path'))
1860
# tk_split_simplelist(INTERP._invoke('set', 'auto_oldpath'))
1863
INTERP._invoke_without_enc('global', 'auto_index')
1864
Hash[*tk_split_simplelist(INTERP._invoke('array', 'get', 'auto_index'))]
1866
when :PRIV, :PRIVATE, :TK_PRIV
1868
if INTERP._invoke_without_enc('info', 'vars', 'tk::Priv') != ""
1869
var_nam = 'tk::Priv'
1873
INTERP._invoke_without_enc('global', var_nam)
1874
Hash[*tk_split_simplelist(INTERP._invoke('array', 'get',
1875
var_nam))].each{|k,v|
1880
when /^-?\d+\.?\d*(e[-+]?\d+)?$/
1889
raise NameError, 'uninitialized constant Tk::' + sym.id2name
1894
INTERP._invoke_without_enc('global', 'errorInfo')
1895
INTERP._invoke_without_enc('set', 'errorInfo')
1899
INTERP._invoke_without_enc('global', 'errorCode')
1900
code = tk_split_simplelist(INTERP._invoke_without_enc('set', 'errorCode'))
1902
when 'CHILDKILLED', 'CHILDSTATUS', 'CHILDSUSP'
1904
pid = Integer(code[1])
1912
def Tk.has_mainwindow?
1913
INTERP.has_mainwindow?
1920
def Tk.load_tclscript(file, enc=nil)
1922
# TCL_VERSION >= 8.5
1923
tk_call('source', '-encoding', enc, file)
1925
tk_call('source', file)
1929
def Tk.load_tcllibrary(file, pkg_name=None, interp=None)
1930
tk_call('load', file, pkg_name, interp)
1933
def Tk.unload_tcllibrary(*args)
1934
if args[-1].kind_of?(Hash)
1935
keys = _symbolkey2str(args.pop)
1936
nocomp = (keys['nocomplain'])? '-nocomplain': None
1937
keeplib = (keys['keeplibrary'])? '-keeplibrary': None
1938
tk_call('unload', nocomp, keeplib, '--', *args)
1940
tk_call('unload', *args)
1944
def Tk.pkgconfig_list(mod)
1946
if mod.kind_of?(Module)
1947
if mod.respond_to?(:package_name)
1948
pkgname = mod.package_name
1949
elsif mod.const_defined?(:PACKAGE_NAME)
1950
pkgname = mod::PACKAGE_NAME
1952
fail NotImplementedError, 'may not be a module for a Tcl extension'
1958
pkgname = '::' << pkgname unless pkgname =~ /^::/
1960
tk_split_list(tk_call(pkgname + '::pkgconfig', 'list'))
1963
def Tk.pkgconfig_get(mod, key)
1965
if mod.kind_of?(Module)
1966
if mod.respond_to?(:package_name)
1967
pkgname = mod.package_name
1969
fail NotImplementedError, 'may not be a module for a Tcl extension'
1975
pkgname = '::' << pkgname unless pkgname =~ /^::/
1977
tk_call(pkgname + '::pkgconfig', 'get', key)
1980
def Tk.tcl_pkgconfig_list
1982
Tk.pkgconfig_list('::tcl')
1985
def Tk.tcl_pkgconfig_get(key)
1987
Tk.pkgconfig_get('::tcl', key)
1990
def Tk.tk_pkgconfig_list
1992
Tk.pkgconfig_list('::tk')
1995
def Tk.tk_pkgconfig_get(key)
1997
Tk.pkgconfig_get('::tk', key)
2000
def Tk.bell(nice = false)
2002
tk_call_without_enc('bell', '-nice')
2004
tk_call_without_enc('bell')
2009
def Tk.bell_on_display(win, nice = false)
2011
tk_call_without_enc('bell', '-displayof', win, '-nice')
2013
tk_call_without_enc('bell', '-displayof', win)
2018
def Tk.destroy(*wins)
2019
#tk_call_without_enc('destroy', *wins)
2020
tk_call_without_enc('destroy', *(wins.collect{|win|
2021
if win.kind_of?(TkWindow)
2030
tk_call_without_enc('destroy', '.')
2034
TkPack.configure(*args)
2036
def Tk.pack_forget(*args)
2037
TkPack.forget(*args)
2039
def Tk.unpack(*args)
2040
TkPack.forget(*args)
2044
TkGrid.configure(*args)
2046
def Tk.grid_forget(*args)
2047
TkGrid.forget(*args)
2049
def Tk.ungrid(*args)
2050
TkGrid.forget(*args)
2054
TkPlace.configure(*args)
2056
def Tk.place_forget(*args)
2057
TkPlace.forget(*args)
2059
def Tk.unplace(*args)
2060
TkPlace.forget(*args)
2063
def Tk.update(idle=nil)
2065
tk_call_without_enc('update', 'idletasks')
2067
tk_call_without_enc('update')
2070
def Tk.update_idletasks
2073
def update(idle=nil)
2074
# only for backward compatibility (This never be recommended to use)
2080
# If no eventloop-thread is running, "thread_update" method is same
2081
# to "update" method. Else, "thread_update" method waits to complete
2082
# idletask operation on the eventloop-thread.
2083
def Tk.thread_update(idle=nil)
2085
tk_call_without_enc('thread_update', 'idletasks')
2087
tk_call_without_enc('thread_update')
2090
def Tk.thread_update_idletasks
2094
def Tk.lower_window(win, below=None)
2095
tk_call('lower', _epath(win), _epath(below))
2098
def Tk.raise_window(win, above=None)
2099
tk_call('raise', _epath(win), _epath(above))
2103
def Tk.current_grabs(win = nil)
2105
window(tk_call_without_enc('grab', 'current', win))
2107
tk_split_list(tk_call_without_enc('grab', 'current'))
2111
def Tk.focus(display=nil)
2113
window(tk_call_without_enc('focus'))
2115
window(tk_call_without_enc('focus', '-displayof', display))
2119
def Tk.focus_to(win, force=false)
2121
tk_call_without_enc('focus', '-force', win)
2123
tk_call_without_enc('focus', win)
2127
def Tk.focus_lastfor(win)
2128
window(tk_call_without_enc('focus', '-lastfor', win))
2131
def Tk.focus_next(win)
2132
TkManageFocus.next(win)
2135
def Tk.focus_prev(win)
2136
TkManageFocus.prev(win)
2139
def Tk.strictMotif(mode=None)
2140
bool(tk_call_without_enc('set', 'tk_strictMotif', mode))
2143
def Tk.show_kinsoku(mode='both')
2145
if /^8\.*/ === TK_VERSION && JAPANIZED_TK
2146
tk_split_simplelist(tk_call('kinsoku', 'show', mode))
2151
def Tk.add_kinsoku(chars, mode='both')
2153
if /^8\.*/ === TK_VERSION && JAPANIZED_TK
2154
tk_split_simplelist(tk_call('kinsoku', 'add', mode,
2155
*(chars.split(''))))
2163
def Tk.delete_kinsoku(chars, mode='both')
2165
if /^8\.*/ === TK_VERSION && JAPANIZED_TK
2166
tk_split_simplelist(tk_call('kinsoku', 'delete', mode,
2167
*(chars.split(''))))
2173
def Tk.toUTF8(str, encoding = nil)
2174
_toUTF8(str, encoding)
2177
def Tk.fromUTF8(str, encoding = nil)
2178
_fromUTF8(str, encoding)
2182
###########################################
2183
# string with Tcl's encoding
2184
###########################################
2186
def Tk.subst_utf_backslash(str)
2187
Tk::EncodedString.subst_utf_backslash(str)
2189
def Tk.subst_tk_backslash(str)
2190
Tk::EncodedString.subst_tk_backslash(str)
2192
def Tk.utf_to_backslash_sequence(str)
2193
Tk::EncodedString.utf_to_backslash_sequence(str)
2195
def Tk.utf_to_backslash(str)
2196
Tk::EncodedString.utf_to_backslash_sequence(str)
2198
def Tk.to_backslash_sequence(str)
2199
Tk::EncodedString.to_backslash_sequence(str)
2204
###########################################
2205
# convert kanji string to/from utf-8
2206
###########################################
2207
if (/^(8\.[1-9]|9\.|[1-9][0-9])/ =~ Tk::TCL_VERSION && !Tk::JAPANIZED_TK)
2209
# from tkencoding.rb by ttate@jaist.ac.jp
2210
attr_accessor :encoding
2213
alias __invoke _invoke
2215
alias __toUTF8 _toUTF8
2216
alias __fromUTF8 _fromUTF8
2219
#### --> definition is moved to TclTkIp module
2221
def _toUTF8(str, encoding = nil)
2224
encoding = encoding.to_s
2225
elsif str.kind_of?(Tk::EncodedString) && str.encoding != nil
2226
encoding = str.encoding.to_s
2227
elsif str.instance_variable_get(:@encoding)
2228
encoding = str.instance_variable_get(:@encoding).to_s
2229
elsif defined?(@encoding) && @encoding != nil
2230
encoding = @encoding.to_s
2232
encoding = __invoke('encoding', 'system')
2237
when 'utf-8', 'binary'
2240
__toUTF8(str, encoding)
2244
def _fromUTF8(str, encoding = nil)
2246
if defined?(@encoding) && @encoding != nil
2247
encoding = @encoding.to_s
2249
encoding = __invoke('encoding', 'system')
2253
if str.kind_of?(Tk::EncodedString)
2254
if str.encoding == 'binary'
2257
__fromUTF8(str, encoding)
2259
elsif str.instance_variable_get(:@encoding).to_s == 'binary'
2262
__fromUTF8(str, encoding)
2268
_fromUTF8(__eval(_toUTF8(cmd)))
2272
_fromUTF8(__invoke(*(cmds.collect{|cmd| _toUTF8(cmd)})))
2275
alias _eval_with_enc _eval
2276
alias _invoke_with_enc _invoke
2280
if defined?(@encoding) && @encoding != 'utf-8'
2281
ret = if cmd.kind_of?(Tk::EncodedString)
2283
when 'utf-8', 'binary'
2286
__eval(_toUTF8(cmd, cmd.encoding))
2288
elsif cmd.instance_variable_get(:@encoding) == 'binary'
2291
__eval(_toUTF8(cmd, @encoding))
2293
if ret.kind_of?(String) && ret.instance_variable_get(:@encoding) == 'binary'
2296
_fromUTF8(ret, @encoding)
2304
if defined?(@encoding) && @encoding != 'utf-8'
2305
cmds = cmds.collect{|cmd|
2306
if cmd.kind_of?(Tk::EncodedString)
2308
when 'utf-8', 'binary'
2311
_toUTF8(cmd, cmd.encoding)
2313
elsif cmd.instance_variable_get(:@encoding) == 'binary'
2316
_toUTF8(cmd, @encoding)
2319
ret = __invoke(*cmds)
2320
if ret.kind_of?(String) && ret.instance_variable_get(:@encoding) == 'binary'
2323
_fromUTF8(ret, @encoding)
2334
alias _encoding encoding
2335
alias _encoding= encoding=
2337
TkCore::INTERP.encoding = name
2340
TkCore::INTERP.encoding
2349
TkCommandNames = ['encoding'.freeze].freeze
2352
TkCore::INTERP.encoding = name
2356
TkCore::INTERP.encoding
2360
TkComm.simplelist(Tk.tk_call('encoding', 'names'))
2364
Tk.tk_call('encoding', 'system')
2367
def encoding_system=(enc)
2368
Tk.tk_call('encoding', 'system', enc)
2371
def encoding_convertfrom(str, enc=nil)
2372
# str is an usual enc string or a Tcl's internal string expression
2373
# in enc (which is returned from 'encoding_convertto' method).
2374
# the return value is a UTF-8 string.
2375
enc = encoding_system unless enc
2376
ret = TkCore::INTERP.__invoke('encoding', 'convertfrom', enc, str)
2377
ret.instance_variable_set('@encoding', 'utf-8')
2380
alias encoding_convert_from encoding_convertfrom
2382
def encoding_convertto(str, enc=nil)
2383
# str must be a UTF-8 string.
2384
# The return value is a Tcl's internal string expression in enc.
2385
# To get an usual enc string, use Tk.fromUTF8(ret_val, enc).
2386
enc = encoding_system unless enc
2387
ret = TkCore::INTERP.__invoke('encoding', 'convertto', enc, str)
2388
ret.instance_variable_set('@encoding', 'binary')
2391
alias encoding_convert_to encoding_convertto
2395
TkComm.simplelist(Tk.tk_call_without_enc('encoding', 'dirs'))
2398
def encoding_dirs=(dir_list) # an array or a Tcl's list string
2400
Tk.tk_call_without_enc('encoding', 'dirs', dir_list)
2410
Tk.encoding = 'euc-jp'
2411
Tk.encoding_system = 'euc-jp'
2414
if Tk.encoding_system == 'cp932'
2415
Tk.encoding = 'cp932'
2417
Tk.encoding = 'shiftjis'
2418
Tk.encoding_system = 'shiftjis'
2420
rescue StandardError, NameError
2421
Tk.encoding = 'shiftjis'
2422
Tk.encoding_system = 'shiftjis'
2425
Tk.encoding = 'utf-8'
2426
Tk.encoding_system = 'utf-8'
2428
if defined? DEFAULT_TK_ENCODING
2429
Tk.encoding_system = DEFAULT_TK_ENCODING
2432
Tk.encoding = Tk.encoding_system
2433
rescue StandardError, NameError
2434
Tk.encoding = 'utf-8'
2435
Tk.encoding_system = 'utf-8'
2442
attr_accessor :encoding
2445
alias __invoke _invoke
2447
alias _eval_with_enc _eval
2448
alias _invoke_with_enc _invoke
2467
def encoding_system=(enc)
2471
def encoding_convertfrom(str, enc=None)
2474
alias encoding_convert_from encoding_convertfrom
2476
def encoding_convertto(str, enc=None)
2479
alias encoding_convert_to encoding_convertto
2483
def encoding_dirs=(dir_array)
2494
#def bind(context, cmd=Proc.new, *args)
2495
# Tk.bind(self, context, cmd, *args)
2497
def bind(context, *args)
2498
# if args[0].kind_of?(Proc) || args[0].kind_of?(Method)
2499
if TkComm._callback_entry?(args[0]) || !block_given?
2504
Tk.bind(self, context, cmd, *args)
2507
#def bind_append(context, cmd=Proc.new, *args)
2508
# Tk.bind_append(self, context, cmd, *args)
2510
def bind_append(context, *args)
2511
# if args[0].kind_of?(Proc) || args[0].kind_of?(Method)
2512
if TkComm._callback_entry?(args[0]) || !block_given?
2517
Tk.bind_append(self, context, cmd, *args)
2520
def bind_remove(context)
2521
Tk.bind_remove(self, context)
2524
def bindinfo(context=nil)
2525
Tk.bindinfo(self, context)
2534
private :__font_optkeys
2541
################################
2543
def font_configinfo(key = nil)
2544
optkeys = __font_optkeys
2545
if key && !optkeys.find{|opt| opt.to_s == key.to_s}
2546
fail ArgumentError, "unknown font option name `#{key}'"
2549
win, tag = __pathname.split(':')
2552
pathname = [win, tag, key].join(';')
2553
TkFont.used_on(pathname) ||
2554
TkFont.init_widget_font(pathname, *__confinfo_cmd)
2555
elsif optkeys.size == 1
2556
pathname = [win, tag, optkeys[0]].join(';')
2557
TkFont.used_on(pathname) ||
2558
TkFont.init_widget_font(pathname, *__confinfo_cmd)
2563
pathname = [win, tag, key].join(';')
2565
TkFont.used_on(pathname) ||
2566
TkFont.init_widget_font(pathname, *__confinfo_cmd)
2571
alias fontobj font_configinfo
2573
def font_configure(slot)
2574
pathname = __pathname
2576
slot = _symbolkey2str(slot)
2578
__font_optkeys.each{|optkey|
2579
optkey = optkey.to_s
2580
l_optkey = 'latin' << optkey
2581
a_optkey = 'ascii' << optkey
2582
k_optkey = 'kanji' << optkey
2584
if slot.key?(optkey)
2585
fnt = slot.delete(optkey)
2586
if fnt.kind_of?(TkFont)
2587
slot.delete(l_optkey)
2588
slot.delete(a_optkey)
2589
slot.delete(k_optkey)
2591
fnt.call_font_configure([pathname, optkey], *(__config_cmd << {}))
2595
if (slot.key?(l_optkey) ||
2596
slot.key?(a_optkey) ||
2597
slot.key?(k_optkey))
2598
fnt = TkFont.new(fnt)
2600
lfnt = slot.delete(l_optkey)
2601
lfnt = slot.delete(a_optkey) if slot.key?(a_optkey)
2602
kfnt = slot.delete(k_optkey)
2604
fnt.latin_replace(lfnt) if lfnt
2605
fnt.kanji_replace(kfnt) if kfnt
2607
fnt.call_font_configure([pathname, optkey],
2608
*(__config_cmd << {}))
2611
fnt = hash_kv(fnt) if fnt.kind_of?(Hash)
2612
tk_call(*(__config_cmd << "-#{optkey}" << fnt))
2619
lfnt = slot.delete(l_optkey)
2620
lfnt = slot.delete(a_optkey) if slot.key?(a_optkey)
2621
kfnt = slot.delete(k_optkey)
2624
TkFont.new(lfnt, kfnt).call_font_configure([pathname, optkey],
2625
*(__config_cmd << {}))
2627
latinfont_configure([lfnt, optkey])
2629
kanjifont_configure([kfnt, optkey])
2633
# configure other (without font) options
2634
tk_call(*(__config_cmd.concat(hash_kv(slot)))) if slot != {}
2638
def latinfont_configure(ltn, keys=nil)
2639
if ltn.kind_of?(Array)
2646
optkeys = __font_optkeys
2647
if key && !optkeys.find{|opt| opt.to_s == key.to_s}
2648
fail ArgumentError, "unknown font option name `#{key}'"
2651
win, tag = __pathname.split(':')
2653
optkeys = [key] if key
2655
optkeys.each{|optkey|
2656
optkey = optkey.to_s
2658
pathname = [win, tag, optkey].join(';')
2660
if (fobj = TkFont.used_on(pathname))
2661
fobj = TkFont.new(fobj) # create a new TkFont object
2662
elsif Tk::JAPANIZED_TK
2663
fobj = fontobj # create a new TkFont object
2665
ltn = hash_kv(ltn) if ltn.kind_of?(Hash)
2666
tk_call(*(__config_cmd << "-#{optkey}" << ltn))
2670
if fobj.kind_of?(TkFont)
2671
if ltn.kind_of?(TkFont)
2673
ltn.latin_configinfo.each{|key,val| conf[key] = val}
2675
fobj.latin_configure(conf.update(keys))
2677
fobj.latin_configure(conf)
2680
fobj.latin_replace(ltn)
2684
fobj.call_font_configure([pathname, optkey], *(__config_cmd << {}))
2688
alias asciifont_configure latinfont_configure
2690
def kanjifont_configure(knj, keys=nil)
2691
if knj.kind_of?(Array)
2698
optkeys = __font_optkeys
2699
if key && !optkeys.find{|opt| opt.to_s == key.to_s}
2700
fail ArgumentError, "unknown font option name `#{key}'"
2703
win, tag = __pathname.split(':')
2705
optkeys = [key] if key
2707
optkeys.each{|optkey|
2708
optkey = optkey.to_s
2710
pathname = [win, tag, optkey].join(';')
2712
if (fobj = TkFont.used_on(pathname))
2713
fobj = TkFont.new(fobj) # create a new TkFont object
2714
elsif Tk::JAPANIZED_TK
2715
fobj = fontobj # create a new TkFont object
2717
knj = hash_kv(knj) if knj.kind_of?(Hash)
2718
tk_call(*(__config_cmd << "-#{optkey}" << knj))
2722
if fobj.kind_of?(TkFont)
2723
if knj.kind_of?(TkFont)
2725
knj.kanji_configinfo.each{|key,val| conf[key] = val}
2727
fobj.kanji_configure(conf.update(keys))
2729
fobj.kanji_configure(conf)
2732
fobj.kanji_replace(knj)
2736
fobj.call_font_configure([pathname, optkey], *(__config_cmd << {}))
2741
def font_copy(win, wintag=nil, winkey=nil, targetkey=nil)
2744
fnt = win.tagfontobj(wintag, winkey).dup
2746
fnt = win.tagfontobj(wintag).dup
2750
fnt = win.fontobj(winkey).dup
2752
fnt = win.fontobj.dup
2757
fnt.call_font_configure([__pathname, targetkey], *(__config_cmd << {}))
2759
fnt.call_font_configure(__pathname, *(__config_cmd << {}))
2764
def latinfont_copy(win, wintag=nil, winkey=nil, targetkey=nil)
2766
fontobj(targetkey).dup.call_font_configure([__pathname, targetkey],
2767
*(__config_cmd << {}))
2769
fontobj.dup.call_font_configure(__pathname, *(__config_cmd << {}))
2774
fontobj.latin_replace(win.tagfontobj(wintag, winkey).latin_font_id)
2776
fontobj.latin_replace(win.tagfontobj(wintag).latin_font_id)
2780
fontobj.latin_replace(win.fontobj(winkey).latin_font_id)
2782
fontobj.latin_replace(win.fontobj.latin_font_id)
2787
alias asciifont_copy latinfont_copy
2789
def kanjifont_copy(win, wintag=nil, winkey=nil, targetkey=nil)
2791
fontobj(targetkey).dup.call_font_configure([__pathname, targetkey],
2792
*(__config_cmd << {}))
2794
fontobj.dup.call_font_configure(__pathname, *(__config_cmd << {}))
2799
fontobj.kanji_replace(win.tagfontobj(wintag, winkey).kanji_font_id)
2801
fontobj.kanji_replace(win.tagfontobj(wintag).kanji_font_id)
2805
fontobj.kanji_replace(win.fontobj(winkey).kanji_font_id)
2807
fontobj.kanji_replace(win.fontobj.kanji_font_id)
2815
module TkConfigMethod
2825
[self.path, 'configure']
2827
private :__config_cmd
2832
private :__confinfo_cmd
2834
def __configinfo_struct
2835
{:key=>0, :alias=>1, :db_name=>1, :db_class=>2,
2836
:default_value=>3, :current_value=>4}
2838
private :__configinfo_struct
2840
def __numval_optkeys
2843
private :__numval_optkeys
2845
def __numstrval_optkeys
2848
private :__numstrval_optkeys
2850
def __boolval_optkeys
2851
['exportselection', 'jump', 'setgrid', 'takefocus']
2853
private :__boolval_optkeys
2855
def __strval_optkeys
2857
'text', 'label', 'show', 'data', 'file',
2858
'activebackground', 'activeforeground', 'background',
2859
'disabledforeground', 'disabledbackground', 'foreground',
2860
'highlightbackground', 'highlightcolor', 'insertbackground',
2861
'selectbackground', 'selectforeground', 'troughcolor'
2864
private :__strval_optkeys
2866
def __listval_optkeys
2869
private :__listval_optkeys
2871
def __numlistval_optkeys
2874
private :__numlistval_optkeys
2876
def __tkvariable_optkeys
2877
['variable', 'textvariable']
2879
private :__tkvariable_optkeys
2881
def __val2ruby_optkeys # { key=>proc, ... }
2882
# The method is used to convert a opt-value to a ruby's object.
2883
# When get the value of the option "key", "proc.call(value)" is called.
2886
private :__val2ruby_optkeys
2888
def __ruby2val_optkeys # { key=>proc, ... }
2889
# The method is used to convert a ruby's object to a opt-value.
2890
# When set the value of the option "key", "proc.call(value)" is called.
2891
# That is, "-#{key} #{proc.call(value)}".
2894
private :__ruby2val_optkeys
2896
def __methodcall_optkeys # { key=>method, ... }
2897
# The method is used to both of get and set.
2898
# Usually, the 'key' will not be a widget option.
2901
private :__methodcall_optkeys
2903
def __keyonly_optkeys # { def_key=>undef_key or nil, ... }
2906
private :__keyonly_optkeys
2908
def __conv_keyonly_opts(keys)
2909
return keys unless keys.kind_of?(Hash)
2910
keyonly = __keyonly_optkeys
2913
optkey = keyonly.find{|kk,vv| kk.to_s == k.to_s}
2915
defkey, undefkey = optkey
2917
keys2[defkey.to_s] = None
2919
keys2[undefkey.to_s] = None
2929
private :__conv_keyonly_opts
2931
def config_hash_kv(keys, enc_mode = nil, conf = nil)
2932
hash_kv(__conv_keyonly_opts(keys), enc_mode, conf)
2935
################################
2951
fail ArgumentError, "Invalid option `#{orig_slot.inspect}'"
2954
if ( method = _symbolkey2str(__val2ruby_optkeys())[slot] )
2955
optval = tk_call_without_enc(*(__cget_cmd << "-#{slot}"))
2957
return method.call(optval)
2959
warn("Warning:: #{e.message} (when #{method}.call(#{optval.inspect})") if $DEBUG
2964
if ( method = _symbolkey2str(__methodcall_optkeys)[slot] )
2965
return self.__send__(method)
2969
when /^(#{__numval_optkeys.join('|')})$/
2971
number(tk_call_without_enc(*(__cget_cmd << "-#{slot}")))
2976
when /^(#{__numstrval_optkeys.join('|')})$/
2977
num_or_str(tk_call_without_enc(*(__cget_cmd << "-#{slot}")))
2979
when /^(#{__boolval_optkeys.join('|')})$/
2981
bool(tk_call_without_enc(*(__cget_cmd << "-#{slot}")))
2986
when /^(#{__listval_optkeys.join('|')})$/
2987
simplelist(tk_call_without_enc(*(__cget_cmd << "-#{slot}")))
2989
when /^(#{__numlistval_optkeys.join('|')})$/
2990
conf = tk_call_without_enc(*(__cget_cmd << "-#{slot}"))
2991
if conf =~ /^[0-9+-]/
2997
when /^(#{__strval_optkeys.join('|')})$/
2998
_fromUTF8(tk_call_without_enc(*(__cget_cmd << "-#{slot}")))
3000
when /^(|latin|ascii|kanji)(#{__font_optkeys.join('|')})$/
3003
fnt = tk_tcl2ruby(tk_call_without_enc(*(__cget_cmd << "-#{fontkey}")), true)
3004
unless fnt.kind_of?(TkFont)
3005
fnt = fontobj(fontkey)
3007
if fontcode == 'kanji' && JAPANIZED_TK && TK_VERSION =~ /^4\.*/
3008
# obsolete; just for compatibility
3014
when /^(#{__tkvariable_optkeys.join('|')})$/
3015
v = tk_call_without_enc(*(__cget_cmd << "-#{slot}"))
3016
(v.empty?)? nil: TkVarAccess.new(v)
3019
tk_tcl2ruby(tk_call_without_enc(*(__cget_cmd << "-#{slot}")), true)
3023
def configure(slot, value=None)
3024
if slot.kind_of? Hash
3025
slot = _symbolkey2str(slot)
3027
__methodcall_optkeys.each{|key, method|
3028
value = slot.delete(key.to_s)
3029
self.__send__(method, value) if value
3032
__ruby2val_optkeys.each{|key, method|
3034
slot[key] = method.call(slot[key]) if slot.has_key?(key)
3037
__keyonly_optkeys.each{|defkey, undefkey|
3038
conf = slot.find{|kk, vv| kk == defkey.to_s}
3044
slot[undefkey.to_s] = None if undefkey
3050
if (slot.find{|k, v| k =~ /^(|latin|ascii|kanji)(#{__font_optkeys.join('|')})$/})
3051
font_configure(slot)
3053
tk_call(*(__config_cmd.concat(hash_kv(slot))))
3060
fail ArgumentError, "Invalid option `#{orig_slot.inspect}'"
3063
if ( conf = __keyonly_optkeys.find{|k, v| k.to_s == slot} )
3064
defkey, undefkey = conf
3066
tk_call(*(__config_cmd << "-#{defkey}"))
3068
tk_call(*(__config_cmd << "-#{undefkey}"))
3070
elsif ( method = _symbolkey2str(__ruby2val_optkeys)[slot] )
3071
tk_call(*(__config_cmd << "-#{slot}" << method.call(value)))
3072
elsif ( method = _symbolkey2str(__methodcall_optkeys)[slot] )
3073
self.__send__(method, value)
3074
elsif (slot =~ /^(|latin|ascii|kanji)(#{__font_optkeys.join('|')})$/)
3078
font_configure({slot=>value})
3081
tk_call(*(__config_cmd << "-#{slot}" << value))
3087
def configure_cmd(slot, value)
3088
configure(slot, install_cmd(value))
3091
def configinfo(slot = nil)
3092
if TkComm::GET_CONFIGINFO_AS_ARRAY
3094
slot.to_s =~ /^(|latin|ascii|kanji)(#{__font_optkeys.join('|')})$/)
3096
# conf = tk_split_simplelist(_fromUTF8(tk_call_without_enc(*(__confinfo_cmd << "-#{fontkey}"))))
3097
conf = tk_split_simplelist(tk_call_without_enc(*(__confinfo_cmd << "-#{fontkey}")), false, true)
3098
conf[__configinfo_struct[:key]] =
3099
conf[__configinfo_struct[:key]][1..-1]
3100
if ( ! __configinfo_struct[:alias] \
3101
|| conf.size > __configinfo_struct[:alias] + 1 )
3102
conf[__configinfo_struct[:current_value]] = fontobj(fontkey)
3103
elsif ( __configinfo_struct[:alias] \
3104
&& conf.size == __configinfo_struct[:alias] + 1 \
3105
&& conf[__configinfo_struct[:alias]][0] == ?- )
3106
conf[__configinfo_struct[:alias]] =
3107
conf[__configinfo_struct[:alias]][1..-1]
3114
when /^(#{__val2ruby_optkeys().keys.join('|')})$/
3115
method = _symbolkey2str(__val2ruby_optkeys())[slot]
3116
conf = tk_split_simplelist(tk_call_without_enc(*(__confinfo_cmd() << "-#{slot}")), false, true)
3117
if ( __configinfo_struct[:default_value] \
3118
&& conf[__configinfo_struct[:default_value]] )
3119
optval = conf[__configinfo_struct[:default_value]]
3121
val = method.call(optval)
3123
warn("Warning:: #{e.message} (when #{method}.call(#{optval.inspect})") if $DEBUG
3126
conf[__configinfo_struct[:default_value]] = val
3128
if ( conf[__configinfo_struct[:current_value]] )
3129
optval = conf[__configinfo_struct[:current_value]]
3131
val = method.call(optval)
3133
warn("Warning:: #{e.message} (when #{method}.call(#{optval.inspect})") if $DEBUG
3136
conf[__configinfo_struct[:current_value]] = val
3139
when /^(#{__methodcall_optkeys.keys.join('|')})$/
3140
method = _symbolkey2str(__methodcall_optkeys)[slot]
3141
return [slot, '', '', '', self.__send__(method)]
3143
when /^(#{__numval_optkeys.join('|')})$/
3144
# conf = tk_split_simplelist(_fromUTF8(tk_call_without_enc(*(__confinfo_cmd << "-#{slot}"))))
3145
conf = tk_split_simplelist(tk_call_without_enc(*(__confinfo_cmd << "-#{slot}")), false, true)
3147
if ( __configinfo_struct[:default_value] \
3148
&& conf[__configinfo_struct[:default_value]])
3150
conf[__configinfo_struct[:default_value]] =
3151
number(conf[__configinfo_struct[:default_value]])
3153
conf[__configinfo_struct[:default_value]] = nil
3156
if ( conf[__configinfo_struct[:current_value]] )
3158
conf[__configinfo_struct[:current_value]] =
3159
number(conf[__configinfo_struct[:current_value]])
3161
conf[__configinfo_struct[:current_value]] = nil
3165
when /^(#{__numstrval_optkeys.join('|')})$/
3166
# conf = tk_split_simplelist(_fromUTF8(tk_call_without_enc(*(__confinfo_cmd << "-#{slot}"))))
3167
conf = tk_split_simplelist(tk_call_without_enc(*(__confinfo_cmd << "-#{slot}")), false, true)
3169
if ( __configinfo_struct[:default_value] \
3170
&& conf[__configinfo_struct[:default_value]])
3171
conf[__configinfo_struct[:default_value]] =
3172
num_or_str(conf[__configinfo_struct[:default_value]])
3174
if ( conf[__configinfo_struct[:current_value]] )
3175
conf[__configinfo_struct[:current_value]] =
3176
num_or_str(conf[__configinfo_struct[:current_value]])
3179
when /^(#{__boolval_optkeys.join('|')})$/
3180
# conf = tk_split_simplelist(_fromUTF8(tk_call_without_enc(*(__confinfo_cmd << "-#{slot}"))))
3181
conf = tk_split_simplelist(tk_call_without_enc(*(__confinfo_cmd << "-#{slot}")), false, true)
3183
if ( __configinfo_struct[:default_value] \
3184
&& conf[__configinfo_struct[:default_value]])
3186
conf[__configinfo_struct[:default_value]] =
3187
bool(conf[__configinfo_struct[:default_value]])
3189
conf[__configinfo_struct[:default_value]] = nil
3192
if ( conf[__configinfo_struct[:current_value]] )
3194
conf[__configinfo_struct[:current_value]] =
3195
bool(conf[__configinfo_struct[:current_value]])
3197
conf[__configinfo_struct[:current_value]] = nil
3201
when /^(#{__listval_optkeys.join('|')})$/
3202
# conf = tk_split_simplelist(_fromUTF8(tk_call_without_enc(*(__confinfo_cmd << "-#{slot}"))))
3203
conf = tk_split_simplelist(tk_call_without_enc(*(__confinfo_cmd << "-#{slot}")), false, true)
3205
if ( __configinfo_struct[:default_value] \
3206
&& conf[__configinfo_struct[:default_value]])
3207
conf[__configinfo_struct[:default_value]] =
3208
simplelist(conf[__configinfo_struct[:default_value]])
3210
if ( conf[__configinfo_struct[:current_value]] )
3211
conf[__configinfo_struct[:current_value]] =
3212
simplelist(conf[__configinfo_struct[:current_value]])
3215
when /^(#{__numlistval_optkeys.join('|')})$/
3216
# conf = tk_split_simplelist(_fromUTF8(tk_call_without_enc(*(__confinfo_cmd << "-#{slot}"))))
3217
conf = tk_split_simplelist(tk_call_without_enc(*(__confinfo_cmd << "-#{slot}")), false, true)
3219
if ( __configinfo_struct[:default_value] \
3220
&& conf[__configinfo_struct[:default_value]] \
3221
&& conf[__configinfo_struct[:default_value]] =~ /^[0-9]/ )
3222
conf[__configinfo_struct[:default_value]] =
3223
list(conf[__configinfo_struct[:default_value]])
3225
if ( conf[__configinfo_struct[:current_value]] \
3226
&& conf[__configinfo_struct[:current_value]] =~ /^[0-9]/ )
3227
conf[__configinfo_struct[:current_value]] =
3228
list(conf[__configinfo_struct[:current_value]])
3231
when /^(#{__strval_optkeys.join('|')})$/
3232
# conf = tk_split_simplelist(_fromUTF8(tk_call_without_enc(*(__confinfo_cmd << "-#{slot}"))))
3233
conf = tk_split_simplelist(tk_call_without_enc(*(__confinfo_cmd << "-#{slot}")), false, true)
3235
when /^(#{__tkvariable_optkeys.join('|')})$/
3236
conf = tk_split_simplelist(tk_call_without_enc(*(__confinfo_cmd << "-#{slot}")), false, true)
3238
if ( __configinfo_struct[:default_value] \
3239
&& conf[__configinfo_struct[:default_value]])
3240
v = conf[__configinfo_struct[:default_value]]
3242
conf[__configinfo_struct[:default_value]] = nil
3244
conf[__configinfo_struct[:default_value]] = TkVarAccess.new(v)
3247
if ( conf[__configinfo_struct[:current_value]] )
3248
v = conf[__configinfo_struct[:current_value]]
3250
conf[__configinfo_struct[:current_value]] = nil
3252
conf[__configinfo_struct[:current_value]] = TkVarAccess.new(v)
3257
# conf = tk_split_list(_fromUTF8(tk_call_without_enc(*(__confinfo_cmd << "-#{slot}"))))
3258
conf = tk_split_list(tk_call_without_enc(*(__confinfo_cmd << "-#{slot}")), 0, false, true)
3260
conf[__configinfo_struct[:key]] =
3261
conf[__configinfo_struct[:key]][1..-1]
3263
if ( __configinfo_struct[:alias] \
3264
&& conf.size == __configinfo_struct[:alias] + 1 \
3265
&& conf[__configinfo_struct[:alias]][0] == ?- )
3266
conf[__configinfo_struct[:alias]] =
3267
conf[__configinfo_struct[:alias]][1..-1]
3273
# ret = tk_split_simplelist(_fromUTF8(tk_call_without_enc(*__confinfo_cmd))).collect{|conflist|
3274
# conf = tk_split_simplelist(conflist)
3275
ret = tk_split_simplelist(tk_call_without_enc(*__confinfo_cmd), false, false).collect{|conflist|
3276
conf = tk_split_simplelist(conflist, false, true)
3277
conf[__configinfo_struct[:key]] =
3278
conf[__configinfo_struct[:key]][1..-1]
3280
optkey = conf[__configinfo_struct[:key]]
3282
when /^(#{__val2ruby_optkeys().keys.join('|')})$/
3283
method = _symbolkey2str(__val2ruby_optkeys())[optkey]
3284
if ( __configinfo_struct[:default_value] \
3285
&& conf[__configinfo_struct[:default_value]] )
3286
optval = conf[__configinfo_struct[:default_value]]
3288
val = method.call(optval)
3290
warn("Warning:: #{e.message} (when #{method}.call(#{optval.inspect})") if $DEBUG
3293
conf[__configinfo_struct[:default_value]] = val
3295
if ( conf[__configinfo_struct[:current_value]] )
3296
optval = conf[__configinfo_struct[:current_value]]
3298
val = method.call(optval)
3300
warn("Warning:: #{e.message} (when #{method}.call(#{optval.inspect})") if $DEBUG
3303
conf[__configinfo_struct[:current_value]] = val
3306
when /^(#{__strval_optkeys.join('|')})$/
3309
when /^(#{__numval_optkeys.join('|')})$/
3310
if ( __configinfo_struct[:default_value] \
3311
&& conf[__configinfo_struct[:default_value]] )
3313
conf[__configinfo_struct[:default_value]] =
3314
number(conf[__configinfo_struct[:default_value]])
3316
conf[__configinfo_struct[:default_value]] = nil
3319
if ( conf[__configinfo_struct[:current_value]] )
3321
conf[__configinfo_struct[:current_value]] =
3322
number(conf[__configinfo_struct[:current_value]])
3324
conf[__configinfo_struct[:current_value]] = nil
3328
when /^(#{__numstrval_optkeys.join('|')})$/
3329
if ( __configinfo_struct[:default_value] \
3330
&& conf[__configinfo_struct[:default_value]] )
3331
conf[__configinfo_struct[:default_value]] =
3332
num_or_str(conf[__configinfo_struct[:default_value]])
3334
if ( conf[__configinfo_struct[:current_value]] )
3335
conf[__configinfo_struct[:current_value]] =
3336
num_or_str(conf[__configinfo_struct[:current_value]])
3339
when /^(#{__boolval_optkeys.join('|')})$/
3340
if ( __configinfo_struct[:default_value] \
3341
&& conf[__configinfo_struct[:default_value]] )
3343
conf[__configinfo_struct[:default_value]] =
3344
bool(conf[__configinfo_struct[:default_value]])
3346
conf[__configinfo_struct[:default_value]] = nil
3349
if ( conf[__configinfo_struct[:current_value]] )
3351
conf[__configinfo_struct[:current_value]] =
3352
bool(conf[__configinfo_struct[:current_value]])
3354
conf[__configinfo_struct[:current_value]] = nil
3358
when /^(#{__listval_optkeys.join('|')})$/
3359
if ( __configinfo_struct[:default_value] \
3360
&& conf[__configinfo_struct[:default_value]] )
3361
conf[__configinfo_struct[:default_value]] =
3362
simplelist(conf[__configinfo_struct[:default_value]])
3364
if ( conf[__configinfo_struct[:current_value]] )
3365
conf[__configinfo_struct[:current_value]] =
3366
simplelist(conf[__configinfo_struct[:current_value]])
3369
when /^(#{__numlistval_optkeys.join('|')})$/
3370
if ( __configinfo_struct[:default_value] \
3371
&& conf[__configinfo_struct[:default_value]] \
3372
&& conf[__configinfo_struct[:default_value]] =~ /^[0-9]/ )
3373
conf[__configinfo_struct[:default_value]] =
3374
list(conf[__configinfo_struct[:default_value]])
3376
if ( conf[__configinfo_struct[:current_value]] \
3377
&& conf[__configinfo_struct[:current_value]] =~ /^[0-9]/ )
3378
conf[__configinfo_struct[:current_value]] =
3379
list(conf[__configinfo_struct[:current_value]])
3382
when /^(#{__tkvariable_optkeys.join('|')})$/
3383
if ( __configinfo_struct[:default_value] \
3384
&& conf[__configinfo_struct[:default_value]] )
3385
v = conf[__configinfo_struct[:default_value]]
3387
conf[__configinfo_struct[:default_value]] = nil
3389
conf[__configinfo_struct[:default_value]] = TkVarAccess.new(v)
3392
if ( conf[__configinfo_struct[:current_value]] )
3393
v = conf[__configinfo_struct[:current_value]]
3395
conf[__configinfo_struct[:current_value]] = nil
3397
conf[__configinfo_struct[:current_value]] = TkVarAccess.new(v)
3402
if ( __configinfo_struct[:default_value] \
3403
&& conf[__configinfo_struct[:default_value]] )
3404
if conf[__configinfo_struct[:default_value]].index('{')
3405
conf[__configinfo_struct[:default_value]] =
3406
tk_split_list(conf[__configinfo_struct[:default_value]])
3408
conf[__configinfo_struct[:default_value]] =
3409
tk_tcl2ruby(conf[__configinfo_struct[:default_value]])
3412
if conf[__configinfo_struct[:current_value]]
3413
if conf[__configinfo_struct[:current_value]].index('{')
3414
conf[__configinfo_struct[:current_value]] =
3415
tk_split_list(conf[__configinfo_struct[:current_value]])
3417
conf[__configinfo_struct[:current_value]] =
3418
tk_tcl2ruby(conf[__configinfo_struct[:current_value]])
3423
if ( __configinfo_struct[:alias] \
3424
&& conf.size == __configinfo_struct[:alias] + 1 \
3425
&& conf[__configinfo_struct[:alias]][0] == ?- )
3426
conf[__configinfo_struct[:alias]] =
3427
conf[__configinfo_struct[:alias]][1..-1]
3433
__font_optkeys.each{|optkey|
3434
optkey = optkey.to_s
3435
fontconf = ret.assoc(optkey)
3436
if fontconf && fontconf.size > 2
3437
ret.delete_if{|inf| inf[0] =~ /^(|latin|ascii|kanji)#{optkey}$/}
3438
fontconf[__configinfo_struct[:current_value]] = fontobj(optkey)
3443
__methodcall_optkeys.each{|optkey, method|
3444
ret << [optkey.to_s, '', '', '', self.__send__(method)]
3451
else # ! TkComm::GET_CONFIGINFO_AS_ARRAY
3453
slot.to_s =~ /^(|latin|ascii|kanji)(#{__font_optkeys.join('|')})$/)
3455
# conf = tk_split_simplelist(_fromUTF8(tk_call_without_enc(*(__confinfo_cmd << "-#{fontkey}"))))
3456
conf = tk_split_simplelist(tk_call_without_enc(*(__confinfo_cmd << "-#{fontkey}")), false, true)
3457
conf[__configinfo_struct[:key]] =
3458
conf[__configinfo_struct[:key]][1..-1]
3460
if ( ! __configinfo_struct[:alias] \
3461
|| conf.size > __configinfo_struct[:alias] + 1 )
3462
conf[__configinfo_struct[:current_value]] = fontobj(fontkey)
3463
{ conf.shift => conf }
3464
elsif ( __configinfo_struct[:alias] \
3465
&& conf.size == __configinfo_struct[:alias] + 1 )
3466
if conf[__configinfo_struct[:alias]][0] == ?-
3467
conf[__configinfo_struct[:alias]] =
3468
conf[__configinfo_struct[:alias]][1..-1]
3470
{ conf[0] => conf[1] }
3472
{ conf.shift => conf }
3478
when /^(#{__val2ruby_optkeys().keys.join('|')})$/
3479
method = _symbolkey2str(__val2ruby_optkeys())[slot]
3480
conf = tk_split_simplelist(tk_call_without_enc(*(__confinfo_cmd << "-#{slot}")), false, true)
3481
if ( __configinfo_struct[:default_value] \
3482
&& conf[__configinfo_struct[:default_value]] )
3483
optval = conf[__configinfo_struct[:default_value]]
3485
val = method.call(optval)
3487
warn("Warning:: #{e.message} (when #{method}.call(#{optval.inspect})") if $DEBUG
3490
conf[__configinfo_struct[:default_value]] = val
3492
if ( conf[__configinfo_struct[:current_value]] )
3493
optval = conf[__configinfo_struct[:current_value]]
3495
val = method.call(optval)
3497
warn("Warning:: #{e.message} (when #{method}.call(#{optval.inspect})") if $DEBUG
3500
conf[__configinfo_struct[:current_value]] = val
3503
when /^(#{__methodcall_optkeys.keys.join('|')})$/
3504
method = _symbolkey2str(__methodcall_optkeys)[slot]
3505
return {slot => ['', '', '', self.__send__(method)]}
3507
when /^(#{__numval_optkeys.join('|')})$/
3508
# conf = tk_split_simplelist(_fromUTF8(tk_call_without_enc(*(__confinfo_cmd << "-#{slot}"))))
3509
conf = tk_split_simplelist(tk_call_without_enc(*(__confinfo_cmd << "-#{slot}")), false, true)
3511
if ( __configinfo_struct[:default_value] \
3512
&& conf[__configinfo_struct[:default_value]] )
3514
conf[__configinfo_struct[:default_value]] =
3515
number(conf[__configinfo_struct[:default_value]])
3517
conf[__configinfo_struct[:default_value]] = nil
3520
if ( conf[__configinfo_struct[:current_value]] )
3522
conf[__configinfo_struct[:current_value]] =
3523
number(conf[__configinfo_struct[:current_value]])
3525
conf[__configinfo_struct[:current_value]] = nil
3529
when /^(#{__numstrval_optkeys.join('|')})$/
3530
# conf = tk_split_simplelist(_fromUTF8(tk_call_without_enc(*(__confinfo_cmd << "-#{slot}"))))
3531
conf = tk_split_simplelist(tk_call_without_enc(*(__confinfo_cmd << "-#{slot}")), false, true)
3533
if ( __configinfo_struct[:default_value] \
3534
&& conf[__configinfo_struct[:default_value]] )
3535
conf[__configinfo_struct[:default_value]] =
3536
num_or_str(conf[__configinfo_struct[:default_value]])
3538
if ( conf[__configinfo_struct[:current_value]] )
3539
conf[__configinfo_struct[:current_value]] =
3540
num_or_str(conf[__configinfo_struct[:current_value]])
3543
when /^(#{__boolval_optkeys.join('|')})$/
3544
# conf = tk_split_simplelist(_fromUTF8(tk_call_without_enc(*(__confinfo_cmd << "-#{slot}"))))
3545
conf = tk_split_simplelist(tk_call_without_enc(*(__confinfo_cmd << "-#{slot}")), false, true)
3547
if ( __configinfo_struct[:default_value] \
3548
&& conf[__configinfo_struct[:default_value]] )
3550
conf[__configinfo_struct[:default_value]] =
3551
bool(conf[__configinfo_struct[:default_value]])
3553
conf[__configinfo_struct[:default_value]] = nil
3556
if ( conf[__configinfo_struct[:current_value]] )
3558
conf[__configinfo_struct[:current_value]] =
3559
bool(conf[__configinfo_struct[:current_value]])
3561
conf[__configinfo_struct[:current_value]] = nil
3565
when /^(#{__listval_optkeys.join('|')})$/
3566
# conf = tk_split_simplelist(_fromUTF8(tk_call_without_enc(*(__confinfo_cmd << "-#{slot}"))))
3567
conf = tk_split_simplelist(tk_call_without_enc(*(__confinfo_cmd << "-#{slot}")), false, true)
3569
if ( __configinfo_struct[:default_value] \
3570
&& conf[__configinfo_struct[:default_value]] )
3571
conf[__configinfo_struct[:default_value]] =
3572
simplelist(conf[__configinfo_struct[:default_value]])
3574
if ( conf[__configinfo_struct[:current_value]] )
3575
conf[__configinfo_struct[:current_value]] =
3576
simplelist(conf[__configinfo_struct[:current_value]])
3579
when /^(#{__numlistval_optkeys.join('|')})$/
3580
# conf = tk_split_simplelist(_fromUTF8(tk_call_without_enc(*(__confinfo_cmd << "-#{slot}"))))
3581
conf = tk_split_simplelist(tk_call_without_enc(*(__confinfo_cmd << "-#{slot}")), false, true)
3583
if ( __configinfo_struct[:default_value] \
3584
&& conf[__configinfo_struct[:default_value]] \
3585
&& conf[__configinfo_struct[:default_value]] =~ /^[0-9]/ )
3586
conf[__configinfo_struct[:default_value]] =
3587
list(conf[__configinfo_struct[:default_value]])
3589
if ( conf[__configinfo_struct[:current_value]] \
3590
&& conf[__configinfo_struct[:current_value]] =~ /^[0-9]/ )
3591
conf[__configinfo_struct[:current_value]] =
3592
list(conf[__configinfo_struct[:current_value]])
3595
when /^(#{__tkvariable_optkeys.join('|')})$/
3596
conf = tk_split_simplelist(tk_call_without_enc(*(__confinfo_cmd << "-#{slot}")), false, true)
3598
if ( __configinfo_struct[:default_value] \
3599
&& conf[__configinfo_struct[:default_value]] )
3600
v = conf[__configinfo_struct[:default_value]]
3602
conf[__configinfo_struct[:default_value]] = nil
3604
conf[__configinfo_struct[:default_value]] = TkVarAccess.new(v)
3607
if ( conf[__configinfo_struct[:current_value]] )
3608
v = conf[__configinfo_struct[:current_value]]
3610
conf[__configinfo_struct[:current_value]] = nil
3612
conf[__configinfo_struct[:current_value]] = TkVarAccess.new(v)
3616
when /^(#{__strval_optkeys.join('|')})$/
3617
# conf = tk_split_simplelist(_fromUTF8(tk_call_without_enc(*(__confinfo_cmd << "-#{slot}"))))
3618
conf = tk_split_simplelist(tk_call_without_enc(*(__confinfo_cmd << "-#{slot}")), false, true)
3620
# conf = tk_split_list(_fromUTF8(tk_call_without_enc(*(__confinfo_cmd << "-#{slot}"))))
3621
conf = tk_split_list(tk_call_without_enc(*(__confinfo_cmd << "-#{slot}")), 0, false, true)
3623
conf[__configinfo_struct[:key]] =
3624
conf[__configinfo_struct[:key]][1..-1]
3626
if ( __configinfo_struct[:alias] \
3627
&& conf.size == __configinfo_struct[:alias] + 1 )
3628
if conf[__configinfo_struct[:alias]][0] == ?-
3629
conf[__configinfo_struct[:alias]] =
3630
conf[__configinfo_struct[:alias]][1..-1]
3632
{ conf[0] => conf[1] }
3634
{ conf.shift => conf }
3639
# tk_split_simplelist(_fromUTF8(tk_call_without_enc(*__confinfo_cmd))).each{|conflist|
3640
# conf = tk_split_simplelist(conflist)
3641
tk_split_simplelist(tk_call_without_enc(*__confinfo_cmd), false, false).each{|conflist|
3642
conf = tk_split_simplelist(conflist, false, true)
3643
conf[__configinfo_struct[:key]] =
3644
conf[__configinfo_struct[:key]][1..-1]
3646
optkey = conf[__configinfo_struct[:key]]
3648
when /^(#{__val2ruby_optkeys().keys.join('|')})$/
3649
method = _symbolkey2str(__val2ruby_optkeys())[optkey]
3650
if ( __configinfo_struct[:default_value] \
3651
&& conf[__configinfo_struct[:default_value]] )
3652
optval = conf[__configinfo_struct[:default_value]]
3654
val = method.call(optval)
3656
warn("Warning:: #{e.message} (when #{method}.call(#{optval.inspect})") if $DEBUG
3659
conf[__configinfo_struct[:default_value]] = val
3661
if ( conf[__configinfo_struct[:current_value]] )
3662
optval = conf[__configinfo_struct[:current_value]]
3664
val = method.call(optval)
3666
warn("Warning:: #{e.message} (when #{method}.call(#{optval.inspect})") if $DEBUG
3669
conf[__configinfo_struct[:current_value]] = val
3672
when /^(#{__strval_optkeys.join('|')})$/
3675
when /^(#{__numval_optkeys.join('|')})$/
3676
if ( __configinfo_struct[:default_value] \
3677
&& conf[__configinfo_struct[:default_value]] )
3679
conf[__configinfo_struct[:default_value]] =
3680
number(conf[__configinfo_struct[:default_value]])
3682
conf[__configinfo_struct[:default_value]] = nil
3685
if ( conf[__configinfo_struct[:current_value]] )
3687
conf[__configinfo_struct[:current_value]] =
3688
number(conf[__configinfo_struct[:current_value]])
3690
conf[__configinfo_struct[:current_value]] = nil
3694
when /^(#{__numstrval_optkeys.join('|')})$/
3695
if ( __configinfo_struct[:default_value] \
3696
&& conf[__configinfo_struct[:default_value]] )
3697
conf[__configinfo_struct[:default_value]] =
3698
num_or_str(conf[__configinfo_struct[:default_value]])
3700
if ( conf[__configinfo_struct[:current_value]] )
3701
conf[__configinfo_struct[:current_value]] =
3702
num_or_str(conf[__configinfo_struct[:current_value]])
3705
when /^(#{__boolval_optkeys.join('|')})$/
3706
if ( __configinfo_struct[:default_value] \
3707
&& conf[__configinfo_struct[:default_value]] )
3709
conf[__configinfo_struct[:default_value]] =
3710
bool(conf[__configinfo_struct[:default_value]])
3712
conf[__configinfo_struct[:default_value]] = nil
3715
if ( conf[__configinfo_struct[:current_value]] )
3717
conf[__configinfo_struct[:current_value]] =
3718
bool(conf[__configinfo_struct[:current_value]])
3720
conf[__configinfo_struct[:current_value]] = nil
3724
when /^(#{__listval_optkeys.join('|')})$/
3725
if ( __configinfo_struct[:default_value] \
3726
&& conf[__configinfo_struct[:default_value]] )
3727
conf[__configinfo_struct[:default_value]] =
3728
simplelist(conf[__configinfo_struct[:default_value]])
3730
if ( conf[__configinfo_struct[:current_value]] )
3731
conf[__configinfo_struct[:current_value]] =
3732
simplelist(conf[__configinfo_struct[:current_value]])
3735
when /^(#{__numlistval_optkeys.join('|')})$/
3736
if ( __configinfo_struct[:default_value] \
3737
&& conf[__configinfo_struct[:default_value]] \
3738
&& conf[__configinfo_struct[:default_value]] =~ /^[0-9]/ )
3739
conf[__configinfo_struct[:default_value]] =
3740
list(conf[__configinfo_struct[:default_value]])
3742
if ( conf[__configinfo_struct[:current_value]] \
3743
&& conf[__configinfo_struct[:current_value]] =~ /^[0-9]/ )
3744
conf[__configinfo_struct[:current_value]] =
3745
list(conf[__configinfo_struct[:current_value]])
3748
when /^(#{__tkvariable_optkeys.join('|')})$/
3749
if ( __configinfo_struct[:default_value] \
3750
&& conf[__configinfo_struct[:default_value]] )
3751
v = conf[__configinfo_struct[:default_value]]
3753
conf[__configinfo_struct[:default_value]] = nil
3755
conf[__configinfo_struct[:default_value]] = TkVarAccess.new
3758
if ( conf[__configinfo_struct[:current_value]] )
3759
v = conf[__configinfo_struct[:current_value]]
3761
conf[__configinfo_struct[:current_value]] = nil
3763
conf[__configinfo_struct[:current_value]] = TkVarAccess.new
3768
if ( __configinfo_struct[:default_value] \
3769
&& conf[__configinfo_struct[:default_value]] )
3770
if conf[__configinfo_struct[:default_value]].index('{')
3771
conf[__configinfo_struct[:default_value]] =
3772
tk_split_list(conf[__configinfo_struct[:default_value]])
3774
conf[__configinfo_struct[:default_value]] =
3775
tk_tcl2ruby(conf[__configinfo_struct[:default_value]])
3778
if conf[__configinfo_struct[:current_value]]
3779
if conf[__configinfo_struct[:current_value]].index('{')
3780
conf[__configinfo_struct[:current_value]] =
3781
tk_split_list(conf[__configinfo_struct[:current_value]])
3783
conf[__configinfo_struct[:current_value]] =
3784
tk_tcl2ruby(conf[__configinfo_struct[:current_value]])
3789
if ( __configinfo_struct[:alias] \
3790
&& conf.size == __configinfo_struct[:alias] + 1 )
3791
if conf[__configinfo_struct[:alias]][0] == ?-
3792
conf[__configinfo_struct[:alias]] =
3793
conf[__configinfo_struct[:alias]][1..-1]
3795
ret[conf[0]] = conf[1]
3797
ret[conf.shift] = conf
3801
__font_optkeys.each{|optkey|
3802
optkey = optkey.to_s
3803
fontconf = ret[optkey]
3804
if fontconf.kind_of?(Array)
3806
ret.delete('latin' << optkey)
3807
ret.delete('ascii' << optkey)
3808
ret.delete('kanji' << optkey)
3809
fontconf[__configinfo_struct[:current_value]] = fontobj(optkey)
3810
ret[optkey] = fontconf
3814
__methodcall_optkeys.each{|optkey, method|
3815
ret[optkey.to_s] = ['', '', '', self.__send__(method)]
3824
def current_configinfo(slot = nil)
3825
if TkComm::GET_CONFIGINFO_AS_ARRAY
3829
conf = configinfo(slot)
3830
if ( ! __configinfo_struct[:alias] \
3831
|| conf.size > __configinfo_struct[:alias] + 1 )
3832
return {conf[0] => conf[-1]}
3834
slot = conf[__configinfo_struct[:alias]]
3835
end while(org_slot != slot)
3837
"there is a configure alias loop about '#{org_slot}'"
3840
configinfo().each{|conf|
3841
if ( ! __configinfo_struct[:alias] \
3842
|| conf.size > __configinfo_struct[:alias] + 1 )
3843
ret[conf[0]] = conf[-1]
3848
else # ! TkComm::GET_CONFIGINFO_AS_ARRAY
3850
configinfo(slot).each{|key, conf|
3851
ret[key] = conf[-1] if conf.kind_of?(Array)
3858
class TkObject<TkKernel
3861
include TkConfigMethod
3864
### --> definition is moved to TkUtil module
3877
def tk_send(cmd, *rest)
3878
tk_call(path, cmd, *rest)
3880
def tk_send_without_enc(cmd, *rest)
3881
tk_call_without_enc(path, cmd, *rest)
3883
def tk_send_with_enc(cmd, *rest)
3884
tk_call_with_enc(path, cmd, *rest)
3886
# private :tk_send, :tk_send_without_enc, :tk_send_with_enc
3888
def tk_send_to_list(cmd, *rest)
3889
tk_call_to_list(path, cmd, *rest)
3891
def tk_send_to_list_without_enc(cmd, *rest)
3892
tk_call_to_list_without_enc(path, cmd, *rest)
3894
def tk_send_to_list_with_enc(cmd, *rest)
3895
tk_call_to_list_with_enc(path, cmd, *rest)
3897
def tk_send_to_simplelist(cmd, *rest)
3898
tk_call_to_simplelist(path, cmd, *rest)
3900
def tk_send_to_simplelist_without_enc(cmd, *rest)
3901
tk_call_to_simplelist_without_enc(path, cmd, *rest)
3903
def tk_send_to_simplelist_with_enc(cmd, *rest)
3904
tk_call_to_simplelist_with_enc(path, cmd, *rest)
3907
def method_missing(id, *args)
3912
configure name[0..-2], args[0]
3915
configure name, args[0]
3924
# "undefined local variable or method `#{name}' for #{self.to_s}",
3929
# fail NameError, "undefined method `#{name}' for #{self.to_s}", error_at
3944
def event_generate(context, keys=nil)
3945
if context.kind_of?(TkEvent::Event)
3946
context.generate(self, ((keys)? keys: {}))
3948
#tk_call('event', 'generate', path,
3949
# "<#{tk_event_sequence(context)}>", *hash_kv(keys))
3950
tk_call_without_enc('event', 'generate', path,
3951
"<#{tk_event_sequence(context)}>",
3952
*hash_kv(keys, true))
3954
#tk_call('event', 'generate', path, "<#{tk_event_sequence(context)}>")
3955
tk_call_without_enc('event', 'generate', path,
3956
"<#{tk_event_sequence(context)}>")
3960
def tk_trace_variable(v)
3961
#unless v.kind_of?(TkVariable)
3962
# fail(ArgumentError, "type error (#{v.class}); must be TkVariable object")
3966
private :tk_trace_variable
3969
#tk_call 'trace', 'vdelete', @tk_vn, 'w', @var_id if @var_id
3974
class TkWindow<TkObject
3978
TkCommandNames = [].freeze
3979
## ==> If TkCommandNames[0] is a string (not a null string),
3980
## assume the string is a Tcl/Tk's create command of the widget class.
3981
WidgetClassName = ''.freeze
3982
# WidgetClassNames[WidgetClassName] = self
3983
## ==> If self is a widget class, entry to the WidgetClassNames table.
3985
self::WidgetClassName
3988
def initialize(parent=nil, keys=nil)
3989
if parent.kind_of? Hash
3990
keys = _symbolkey2str(parent)
3991
parent = keys.delete('parent')
3992
widgetname = keys.delete('widgetname')
3993
install_win(if parent then parent.path end, widgetname)
3994
without_creating = keys.delete('without_creating')
3995
# if without_creating && !widgetname
3996
# fail ArgumentError,
3997
# "if set 'without_creating' to true, need to define 'widgetname'"
4000
keys = _symbolkey2str(keys)
4001
widgetname = keys.delete('widgetname')
4002
install_win(if parent then parent.path end, widgetname)
4003
without_creating = keys.delete('without_creating')
4004
# if without_creating && !widgetname
4005
# fail ArgumentError,
4006
# "if set 'without_creating' to true, need to define 'widgetname'"
4009
install_win(if parent then parent.path end)
4011
if self.method(:create_self).arity == 0
4012
p 'create_self has no arg' if $DEBUG
4013
create_self unless without_creating
4015
# tk_call @path, 'configure', *hash_kv(keys)
4019
p 'create_self has args' if $DEBUG
4023
#['font', 'kanjifont', 'latinfont', 'asciifont'].each{|key|
4024
# fontkeys[key] = keys.delete(key) if keys.key?(key)
4026
__font_optkeys.each{|key|
4028
fontkeys[fkey] = keys.delete(fkey) if keys.key?(fkey)
4030
fkey = "kanji#{key}"
4031
fontkeys[fkey] = keys.delete(fkey) if keys.key?(fkey)
4033
fkey = "latin#{key}"
4034
fontkeys[fkey] = keys.delete(fkey) if keys.key?(fkey)
4036
fkey = "ascii#{key}"
4037
fontkeys[fkey] = keys.delete(fkey) if keys.key?(fkey)
4040
__methodcall_optkeys.each{|key|
4042
methodkeys[key] = keys.delete(key) if keys.key?(key)
4045
__ruby2val_optkeys.each{|key, method|
4047
keys[key] = method.call(keys[key]) if keys.has_key?(key)
4050
if without_creating && keys
4052
configure(__conv_keyonly_opts(keys))
4055
create_self(__conv_keyonly_opts(keys))
4057
font_configure(fontkeys) unless fontkeys.empty?
4058
configure(methodkeys) unless methodkeys.empty?
4062
def create_self(keys)
4063
# may need to override
4065
cmd = self.class::TkCommandNames[0]
4066
fail unless (cmd.kind_of?(String) && cmd.length > 0)
4068
fail RuntimeError, "class #{self.class} may be an abstract class"
4071
if keys and keys != None
4072
tk_call_without_enc(cmd, @path, *hash_kv(keys, true))
4074
tk_call_without_enc(cmd, @path)
4077
private :create_self
4080
TkWinfo.exist?(self)
4084
@db_class || self.class()
4087
def database_classname
4088
TkWinfo.classname(self)
4091
name = database_classname()
4092
if WidgetClassNames[name]
4093
WidgetClassNames[name]
4095
TkDatabaseClass.new(name)
4098
def self.database_classname
4099
self::WidgetClassName
4101
def self.database_class
4102
WidgetClassNames[self::WidgetClassName]
4105
def pack(keys = nil)
4106
#tk_call_without_enc('pack', epath, *hash_kv(keys, true))
4108
TkPack.configure(self, keys)
4110
TkPack.configure(self)
4115
def pack_in(target, keys = nil)
4120
keys = {'in'=>target}
4122
#tk_call 'pack', epath, *hash_kv(keys)
4123
TkPack.configure(self, keys)
4128
#tk_call_without_enc('pack', 'forget', epath)
4132
alias unpack pack_forget
4134
def pack_config(slot, value=None)
4135
#if slot.kind_of? Hash
4136
# tk_call 'pack', 'configure', epath, *hash_kv(slot)
4138
# tk_call 'pack', 'configure', epath, "-#{slot}", value
4140
if slot.kind_of? Hash
4141
TkPack.configure(self, slot)
4143
TkPack.configure(self, slot=>value)
4146
alias pack_configure pack_config
4149
#ilist = list(tk_call('pack', 'info', epath))
4151
#while key = ilist.shift
4152
# info[key[1..-1]] = ilist.shift
4158
def pack_propagate(mode=None)
4160
# bool(tk_call('pack', 'propagate', epath))
4162
# tk_call('pack', 'propagate', epath, mode)
4166
TkPack.propagate(self)
4168
TkPack.propagate(self, mode)
4174
#list(tk_call('pack', 'slaves', epath))
4178
def grid(keys = nil)
4179
#tk_call 'grid', epath, *hash_kv(keys)
4181
TkGrid.configure(self, keys)
4183
TkGrid.configure(self)
4188
def grid_in(target, keys = nil)
4193
keys = {'in'=>target}
4195
#tk_call 'grid', epath, *hash_kv(keys)
4196
TkGrid.configure(self, keys)
4201
#tk_call('grid', 'forget', epath)
4205
alias ungrid grid_forget
4207
def grid_bbox(*args)
4208
#list(tk_call('grid', 'bbox', epath, *args))
4209
TkGrid.bbox(self, *args)
4212
def grid_config(slot, value=None)
4213
#if slot.kind_of? Hash
4214
# tk_call 'grid', 'configure', epath, *hash_kv(slot)
4216
# tk_call 'grid', 'configure', epath, "-#{slot}", value
4218
if slot.kind_of? Hash
4219
TkGrid.configure(self, slot)
4221
TkGrid.configure(self, slot=>value)
4224
alias grid_configure grid_config
4226
def grid_columnconfig(index, keys)
4227
#tk_call('grid', 'columnconfigure', epath, index, *hash_kv(keys))
4228
TkGrid.columnconfigure(self, index, keys)
4230
alias grid_columnconfigure grid_columnconfig
4232
def grid_rowconfig(index, keys)
4233
#tk_call('grid', 'rowconfigure', epath, index, *hash_kv(keys))
4234
TkGrid.rowconfigure(self, index, keys)
4236
alias grid_rowconfigure grid_rowconfig
4238
def grid_columnconfiginfo(index, slot=nil)
4240
# tk_call('grid', 'columnconfigure', epath, index, "-#{slot}").to_i
4242
# ilist = list(tk_call('grid', 'columnconfigure', epath, index))
4244
# while key = ilist.shift
4245
# info[key[1..-1]] = ilist.shift
4249
TkGrid.columnconfiginfo(self, index, slot)
4252
def grid_rowconfiginfo(index, slot=nil)
4254
# tk_call('grid', 'rowconfigure', epath, index, "-#{slot}").to_i
4256
# ilist = list(tk_call('grid', 'rowconfigure', epath, index))
4258
# while key = ilist.shift
4259
# info[key[1..-1]] = ilist.shift
4263
TkGrid.rowconfiginfo(self, index, slot)
4267
#list(tk_call('grid', 'info', epath))
4271
def grid_location(x, y)
4272
#list(tk_call('grid', 'location', epath, x, y))
4273
TkGrid.location(self, x, y)
4276
def grid_propagate(mode=None)
4278
# bool(tk_call('grid', 'propagate', epath))
4280
# tk_call('grid', 'propagate', epath, mode)
4284
TkGrid.propagate(self)
4286
TkGrid.propagate(self, mode)
4292
#tk_call 'grid', 'remove', epath
4298
#list(tk_call('grid', 'size', epath))
4302
def grid_slaves(args)
4303
#list(tk_call('grid', 'slaves', epath, *hash_kv(args)))
4304
TkGrid.slaves(self, args)
4308
#tk_call 'place', epath, *hash_kv(keys)
4309
TkPlace.configure(self, keys)
4313
def place_in(target, keys = nil)
4318
keys = {'in'=>target}
4320
#tk_call 'place', epath, *hash_kv(keys)
4321
TkPlace.configure(self, keys)
4326
#tk_call 'place', 'forget', epath
4327
TkPlace.forget(self)
4330
alias unplace place_forget
4332
def place_config(slot, value=None)
4333
#if slot.kind_of? Hash
4334
# tk_call 'place', 'configure', epath, *hash_kv(slot)
4336
# tk_call 'place', 'configure', epath, "-#{slot}", value
4338
TkPlace.configure(self, slot, value)
4340
alias place_configure place_config
4342
def place_configinfo(slot = nil)
4345
# conf = tk_split_list(tk_call('place', 'configure', epath, "-#{slot}") )
4346
# conf[0] = conf[0][1..-1]
4349
# tk_split_simplelist(tk_call('place',
4350
# 'configure', epath)).collect{|conflist|
4351
# conf = tk_split_simplelist(conflist)
4352
# conf[0] = conf[0][1..-1]
4356
TkPlace.configinfo(self, slot)
4360
#ilist = list(tk_call('place', 'info', epath))
4362
#while key = ilist.shift
4363
# info[key[1..-1]] = ilist.shift
4370
#list(tk_call('place', 'slaves', epath))
4371
TkPlace.slaves(self)
4374
def set_focus(force=false)
4376
tk_call_without_enc('focus', '-force', path)
4378
tk_call_without_enc('focus', path)
4382
alias focus set_focus
4386
tk_call_without_enc('grab', 'set', path)
4392
tk_call_without_enc('grab', 'set', path)
4394
when 'global', :global
4395
#return(tk_call('grab', 'set', '-global', path))
4396
tk_call_without_enc('grab', 'set', '-global', path)
4398
when 'release', :release
4399
#return tk_call('grab', 'release', path)
4400
tk_call_without_enc('grab', 'release', path)
4402
when 'current', :current
4403
return window(tk_call_without_enc('grab', 'current', path))
4404
when 'status', :status
4405
return tk_call_without_enc('grab', 'status', path)
4407
return tk_call_without_enc('grab', opt, path)
4414
alias current_grab grab_current
4418
alias release_grab grab_release
4422
alias set_grab grab_set
4426
alias set_global_grab grab_set_global
4431
def lower(below=None)
4432
# below = below.epath if below.kind_of?(TkObject)
4433
below = _epath(below)
4434
tk_call 'lower', epath, below
4437
alias lower_window lower
4438
def raise(above=None)
4439
#above = above.epath if above.kind_of?(TkObject)
4440
above = _epath(above)
4441
tk_call 'raise', epath, above
4444
alias raise_window raise
4446
def command(cmd=nil, &b)
4448
configure_cmd('command', cmd)
4450
configure_cmd('command', Proc.new(&b))
4456
def colormodel(model=None)
4457
tk_call('tk', 'colormodel', path, model)
4462
TkXIM.caret(path, keys)
4468
rexp = /^#{self.path}\.[^.]+$/
4469
TkCore::INTERP.tk_windows.each{|path, obj|
4470
children << [path, obj] if path =~ rexp
4472
if defined?(@cmdtbl)
4478
children.each{|path, obj|
4479
if defined?(@cmdtbl)
4484
TkCore::INTERP.tk_windows.delete(path)
4488
tk_call_without_enc('destroy', epath)
4494
def wait_visibility(on_thread = true)
4496
fail SecurityError, "can't wait visibility at $SAFE >= 4"
4498
on_thread &= (Thread.list.size != 1)
4500
INTERP._thread_tkwait('visibility', path)
4502
INTERP._invoke('tkwait', 'visibility', path)
4505
def eventloop_wait_visibility
4506
wait_visibility(false)
4508
def thread_wait_visibility
4509
wait_visibility(true)
4511
alias wait wait_visibility
4512
alias tkwait wait_visibility
4513
alias eventloop_wait eventloop_wait_visibility
4514
alias eventloop_tkwait eventloop_wait_visibility
4515
alias eventloop_tkwait_visibility eventloop_wait_visibility
4516
alias thread_wait thread_wait_visibility
4517
alias thread_tkwait thread_wait_visibility
4518
alias thread_tkwait_visibility thread_wait_visibility
4520
def wait_destroy(on_thread = true)
4522
fail SecurityError, "can't wait destroy at $SAFE >= 4"
4524
on_thread &= (Thread.list.size != 1)
4526
INTERP._thread_tkwait('window', epath)
4528
INTERP._invoke('tkwait', 'window', epath)
4531
alias wait_window wait_destroy
4532
def eventloop_wait_destroy
4535
alias eventloop_wait_window eventloop_wait_destroy
4536
def thread_wait_destroy
4539
alias thread_wait_window thread_wait_destroy
4541
alias tkwait_destroy wait_destroy
4542
alias tkwait_window wait_destroy
4544
alias eventloop_tkwait_destroy eventloop_wait_destroy
4545
alias eventloop_tkwait_window eventloop_wait_destroy
4547
alias thread_tkwait_destroy thread_wait_destroy
4548
alias thread_tkwait_window thread_wait_destroy
4550
def bindtags(taglist=nil)
4552
fail ArgumentError, "taglist must be Array" unless taglist.kind_of? Array
4553
tk_call('bindtags', path, taglist)
4556
list(tk_call('bindtags', path)).collect{|tag|
4557
if tag.kind_of?(String)
4558
if cls = WidgetClassNames[tag]
4560
elsif btag = TkBindTag.id2obj(tag)
4572
def bindtags=(taglist)
4584
def bindtags_unshift(tag)
4585
bindtags(bindtags().unshift(tag))
4590
# freeze core modules
4596
#TkComm::Event.freeze
4601
RELEASE_DATE = '2007-01-26'.freeze
4603
autoload :AUTO_PATH, 'tk/variable'
4604
autoload :TCL_PACKAGE_PATH, 'tk/variable'
4605
autoload :PACKAGE_PATH, 'tk/variable'
4606
autoload :TCL_LIBRARY_PATH, 'tk/variable'
4607
autoload :LIBRARY_PATH, 'tk/variable'
4608
autoload :TCL_PRECISION, 'tk/variable'
4611
# call setup script for Tk extension libraries (base configuration)
4613
require 'tkextlib/version.rb'
4614
require 'tkextlib/setup.rb'