Module: TkComm
Overview
define TkComm module (step 2: event binding)
Constant Summary
collapse
- WidgetClassNames =
{}.taint
- TkExtlibAutoloadModule =
[].taint
- Tk_IDs =
Tk_CMDTBL = {} Tk_WINDOWS = {}
["00000".taint, "00000".taint].freeze
- Tk_CMDTBL =
for backward compatibility
Object.new
- Tk_WINDOWS =
Object.new
- GET_CONFIGINFO_AS_ARRAY =
GET_CONFIGINFO_AS_ARRAY = false => returns a Hash { opt =>val, … }
true => returns an Array [[opt,val], ... ]
val is a list which includes resource info.
true
- GET_CONFIGINFOwoRES_AS_ARRAY =
for configinfo without resource info; list of [opt, value] pair
false => returns a Hash { opt=>val, ... }
true => returns an Array [[opt,val], ... ]
true
- USE_TCLs_LIST_FUNCTIONS =
true
Constants included
from TkUtil
TkUtil::None, TkUtil::RELEASE_DATE
Class Method Summary
collapse
-
._at(x, y = nil) ⇒ Object
-
._callback_entry?(obj) ⇒ Boolean
-
._callback_entry_class?(cls) ⇒ Boolean
-
._curr_cmd_id ⇒ Object
### –> definition is moved to TkUtil module def _conv_args(args, enc_mode, *src_args) conv_args = [] src_args.each{|arg| conv_args << _get_eval_string(arg, enc_mode) unless arg == None # if arg.kind_of?(Hash) # arg.each{|k, v| # args << ‘-’ + k.to_s # args << _get_eval_string(v, enc_mode) # } # elsif arg != None # args << _get_eval_string(arg, enc_mode) # end } args + conv_args end private :_conv_args.
-
._fromUTF8(str, encoding = nil) ⇒ Object
-
._genobj_for_tkwidget(path) ⇒ Object
-
._next_cmd_id ⇒ Object
-
._toUTF8(str, encoding = nil) ⇒ Object
-
.array2tk_list(ary, enc = nil) ⇒ Object
-
.bool ⇒ Object
-
.image_obj(val) ⇒ Object
-
.install_cmd(cmd) ⇒ Object
-
.list(val, depth = 0, enc = true) ⇒ Object
### –> definition is moved to TkUtil module def bool(val) case val when “1”, 1, ‘yes’, ‘true’ true else false end end.
-
.num_or_str ⇒ Object
-
.number ⇒ Object
-
.procedure(val) ⇒ Object
-
.simplelist(val, src_enc = true, dst_enc = true) ⇒ Object
-
.string ⇒ Object
-
.tk_tcl2ruby(val, enc_mode = false, listobj = true) ⇒ Object
-
.uninstall_cmd(id) ⇒ Object
-
.window(val) ⇒ Object
Instance Method Summary
collapse
-
#bind(tagOrClass, context, *args) ⇒ Object
def bind(tagOrClass, context, cmd=Proc.new, *args) _bind([“bind”, tagOrClass], context, cmd, *args) tagOrClass end.
-
#bind_all(context, *args) ⇒ Object
def bind_all(context, cmd=Proc.new, *args) _bind([‘bind’, ‘all’], context, cmd, *args) TkBindTag::ALL end.
-
#bind_append(tagOrClass, context, *args) ⇒ Object
def bind_append(tagOrClass, context, cmd=Proc.new, *args) _bind_append([“bind”, tagOrClass], context, cmd, *args) tagOrClass end.
-
#bind_append_all(context, *args) ⇒ Object
def bind_append_all(context, cmd=Proc.new, *args) _bind_append([‘bind’, ‘all’], context, cmd, *args) TkBindTag::ALL end.
-
#bind_remove(tagOrClass, context) ⇒ Object
-
#bind_remove_all(context) ⇒ Object
-
#bindinfo(tagOrClass, context = nil) ⇒ Object
-
#bindinfo_all(context = nil) ⇒ Object
-
#subst(str, *opts) ⇒ Object
Methods included from TkUtil
_conv_args, _conv_args, _get_eval_enc_str, _get_eval_enc_str, _get_eval_string, _get_eval_string, _symbolkey2str, _symbolkey2str, callback, eval_cmd, hash_kv, hash_kv
Methods included from TkEvent
install_bind, install_bind_for_event_class
Class Method Details
._at(x, y = nil) ⇒ Object
183
184
185
186
187
188
189
|
# File 'lib/tk.rb', line 183
def _at(x,y=nil)
if y
"@#{Integer(x)},#{Integer(y)}"
else
"@#{Integer(x)}"
end
end
|
._callback_entry?(obj) ⇒ Boolean
652
653
654
|
# File 'lib/tk.rb', line 652
def _callback_entry?(obj)
obj.kind_of?(Proc) || obj.kind_of?(Method) || obj.kind_of?(TkCallbackEntry)
end
|
._callback_entry_class?(cls) ⇒ Boolean
646
647
648
|
# File 'lib/tk.rb', line 646
def _callback_entry_class?(cls)
cls <= Proc || cls <= Method || cls <= TkCallbackEntry
end
|
._curr_cmd_id ⇒ Object
### –> definition is moved to TkUtil module
def _conv_args(args, enc_mode, *src_args)
conv_args = []
src_args.each{|arg|
conv_args << _get_eval_string(arg, enc_mode) unless arg == None
}
args + conv_args
end
private :_conv_args
._fromUTF8(str, encoding = nil) ⇒ Object
640
641
642
|
# File 'lib/tk.rb', line 640
def _fromUTF8(str, encoding = nil)
TkCore::INTERP._fromUTF8(str, encoding)
end
|
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
# File 'lib/tk.rb', line 82
def _genobj_for_tkwidget(path)
return TkRoot.new if path == '.'
begin
tk_class = Tk.ip_invoke_without_enc('winfo', 'class', path)
rescue
return path
end
if ruby_class = WidgetClassNames[tk_class]
ruby_class_name = ruby_class.name
gen_class_name = ruby_class_name
classname_def = ''
else mods = TkExtlibAutoloadModule.find_all{|m| m.const_defined?(tk_class)}
mods.each{|mod|
begin
mod.const_get(tk_class) break if (ruby_class = WidgetClassNames[tk_class])
rescue LoadError
end
}
unless ruby_class
std_class = 'Tk' << tk_class
if Object.const_defined?(std_class)
Object.const_get(std_class) ruby_class = WidgetClassNames[tk_class]
end
end
if ruby_class
ruby_class_name = ruby_class.name
gen_class_name = ruby_class_name
classname_def = ''
else
ruby_class_name = 'TkWindow'
gen_class_name = 'TkWidget_' + tk_class
classname_def = "WidgetClassName = '#{tk_class}'.freeze"
end
end
=begin
if ruby_class = WidgetClassNames[tk_class]
ruby_class_name = ruby_class.name
# gen_class_name = ruby_class_name + 'GeneratedOnTk'
gen_class_name = ruby_class_name
classname_def = ''
else
mod = TkExtlibAutoloadModule.find{|m| m.const_defined?(tk_class)}
if mod
ruby_class_name = mod.name + '::' + tk_class
gen_class_name = ruby_class_name
classname_def = ''
elsif Object.const_defined?('Tk' + tk_class)
ruby_class_name = 'Tk' + tk_class
# gen_class_name = ruby_class_name + 'GeneratedOnTk'
gen_class_name = ruby_class_name
classname_def = ''
else
ruby_class_name = 'TkWindow'
# gen_class_name = ruby_class_name + tk_class + 'GeneratedOnTk'
gen_class_name = 'TkWidget_' + tk_class
classname_def = "WidgetClassName = '#{tk_class}'.freeze"
end
end
=end
=begin
unless Object.const_defined? gen_class_name
Object.class_eval "class #{gen_class_name}<#{ruby_class_name}
#{classname_def}
end"
end
Object.class_eval "#{gen_class_name}.new('widgetname'=>'#{path}',
'without_creating'=>true)"
=end
base = Object
gen_class_name.split('::').each{|klass|
next if klass == ''
if base.const_defined?(klass)
base = base.class_eval klass
else
base = base.class_eval "class #{klass}<#{ruby_class_name}
#{classname_def}
end
#{klass}"
end
}
base.class_eval "#{gen_class_name}.new('widgetname'=>'#{path}',
'without_creating'=>true)"
end
|
._next_cmd_id ⇒ Object
785
786
787
788
789
790
|
# File 'lib/tk.rb', line 785
def _next_cmd_id
id = _curr_cmd_id
TkComm::Tk_IDs[0].succ!
id
end
|
._toUTF8(str, encoding = nil) ⇒ Object
637
638
639
|
# File 'lib/tk.rb', line 637
def _toUTF8(str, encoding = nil)
TkCore::INTERP._toUTF8(str, encoding)
end
|
.array2tk_list(ary, enc = nil) ⇒ Object
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
|
# File 'lib/tk.rb', line 315
def array2tk_list(ary, enc=nil)
return "" if ary.size == 0
sys_enc = TkCore::INTERP.encoding
sys_enc = TclTkLib.encoding_system unless sys_enc
dst_enc = (enc == nil)? sys_enc: enc
dst = ary.collect{|e|
if e.kind_of? Array
s = array2tk_list(e, enc)
elsif e.kind_of? Hash
tmp_ary = []
e.each{|k,v| tmp_ary << "-#{_get_eval_string(k)}" << v }
s = array2tk_list(tmp_ary, enc)
else
s = _get_eval_string(e, enc)
end
if dst_enc != true && dst_enc != false
if (s_enc = s.instance_variable_get(:@encoding))
s_enc = s_enc.to_s
else
s_enc = sys_enc
end
dst_enc = true if s_enc != dst_enc
end
s
}
if sys_enc && dst_enc
dst.map!{|s| _toUTF8(s)}
ret = TkCore::INTERP._merge_tklist(*dst)
if dst_enc.kind_of?(String)
ret = _fromUTF8(ret, dst_enc)
ret.instance_variable_set(:@encoding, dst_enc)
else
ret.instance_variable_set(:@encoding, 'utf-8')
end
ret
else
TkCore::INTERP._merge_tklist(*dst)
end
end
|
.image_obj(val) ⇒ Object
602
603
604
605
606
607
608
|
# File 'lib/tk.rb', line 602
def image_obj(val)
if val =~ /^i(_\d+_)?\d+$/
TkImage::Tk_IMGTBL[val]? TkImage::Tk_IMGTBL[val] : val
else
val
end
end
|
.install_cmd(cmd) ⇒ Object
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
|
# File 'lib/tk.rb', line 794
def install_cmd(cmd)
return '' if cmd == ''
begin
ns = TkCore::INTERP._invoke_without_enc('namespace', 'current')
ns = nil if ns == '::' rescue
ns = nil
end
id = _next_cmd_id
if cmd.kind_of?(TkCallbackEntry)
TkCore::INTERP.tk_cmd_tbl[id] = cmd
else
TkCore::INTERP.tk_cmd_tbl[id] = TkCore::INTERP.get_cb_entry(cmd)
end
@cmdtbl = [] unless defined? @cmdtbl
@cmdtbl.taint unless @cmdtbl.tainted?
@cmdtbl.push id
if ns
'rb_out' << TkCore::INTERP._ip_id_ << ' ' << ns << ' ' << id
else
'rb_out' << TkCore::INTERP._ip_id_ << ' ' << id
end
end
|
.list(val, depth = 0, enc = true) ⇒ Object
### –> definition is moved to TkUtil module
def bool(val)
case val
when "1", 1, 'yes', 'true'
true
else
false
end
end
def number(val)
case val
when /^-?\d+$/
val.to_i
when /^-?\d+\.?\d*(e[-+]?\d+)?$/
val.to_f
else
fail(ArgumentError, "invalid value for Number:'#{val}'")
end
end
def string(val)
if val == "{}"
''
elsif val[0] == ?{ && val[-1] == ?}
val[1..-2]
else
val
end
end
def num_or_str(val)
begin
number(val)
rescue ArgumentError
string(val)
end
end
587
588
589
|
# File 'lib/tk.rb', line 587
def list(val, depth=0, enc=true)
tk_split_list(val, depth, enc, enc)
end
|
.procedure(val) ⇒ Object
609
610
611
612
613
614
615
616
617
618
619
620
621
622
|
# File 'lib/tk.rb', line 609
def procedure(val)
=begin
if val =~ /^rb_out\S* (c(_\d+_)?\d+)/
#Tk_CMDTBL[$1]
#TkCore::INTERP.tk_cmd_tbl[$1]
TkCore::INTERP.tk_cmd_tbl[$1].cmd
=end
if val =~ /rb_out\S*(?:\s+(::\S*|[{](::.*)[}]|["](::.*)["]))? (c(_\d+_)?(\d+))/
return TkCore::INTERP.tk_cmd_tbl[$4].cmd
else
val
end
end
|
.simplelist(val, src_enc = true, dst_enc = true) ⇒ Object
590
591
592
|
# File 'lib/tk.rb', line 590
def simplelist(val, src_enc=true, dst_enc=true)
tk_split_simplelist(val, src_enc, dst_enc)
end
|
.tk_tcl2ruby(val, enc_mode = false, listobj = true) ⇒ Object
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
|
# File 'lib/tk.rb', line 192
def tk_tcl2ruby(val, enc_mode = false, listobj = true)
=begin
if val =~ /^rb_out\S* (c(_\d+_)?\d+)/
#return Tk_CMDTBL[$1]
return TkCore::INTERP.tk_cmd_tbl[$1]
#cmd_obj = TkCore::INTERP.tk_cmd_tbl[$1]
#if cmd_obj.kind_of?(Proc) || cmd_obj.kind_of?(Method)
# cmd_obj
#else
# cmd_obj.cmd
#end
end
=end
if val =~ /rb_out\S*(?:\s+(::\S*|[{](::.*)[}]|["](::.*)["]))? (c(_\d+_)?(\d+))/
return TkCore::INTERP.tk_cmd_tbl[$4]
end
case val
when /\A@font\S+\z/
TkFont.get_obj(val)
when /\A-?\d+\z/
val.to_i
when /\A\.\S*\z/
TkCore::INTERP.tk_windows[val]?
TkCore::INTERP.tk_windows[val] : _genobj_for_tkwidget(val)
when /\Ai(_\d+_)?\d+\z/
TkImage::Tk_IMGTBL[val]? TkImage::Tk_IMGTBL[val] : val
when /\A-?\d+\.?\d*(e[-+]?\d+)?\z/
val.to_f
when /\\ /
val.gsub(/\\ /, ' ')
when /[^\\] /
if listobj
val = _toUTF8(val) unless enc_mode
tk_split_escstr(val, false, false).collect{|elt|
tk_tcl2ruby(elt, true, listobj)
}
elsif enc_mode
_fromUTF8(val)
else
val
end
else
if enc_mode
_fromUTF8(val)
else
val
end
end
end
|
.uninstall_cmd(id) ⇒ Object
820
821
822
823
824
825
|
# File 'lib/tk.rb', line 820
def uninstall_cmd(id)
id = $4 if id =~ /rb_out\S*(?:\s+(::\S*|[{](::.*)[}]|["](::.*)["]))? (c(_\d+_)?(\d+))/
TkCore::INTERP.tk_cmd_tbl.delete(id)
end
|
.window(val) ⇒ Object
593
594
595
596
597
598
599
600
601
|
# File 'lib/tk.rb', line 593
def window(val)
if val =~ /^\./
TkCore::INTERP.tk_windows[val]?
TkCore::INTERP.tk_windows[val] : _genobj_for_tkwidget(val)
else
nil
end
end
|
Instance Method Details
#bind(tagOrClass, context, *args) ⇒ Object
def bind(tagOrClass, context, cmd=Proc.new, *args)
_bind(["bind", tagOrClass], context, cmd, *args)
tagOrClass
end
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
|
# File 'lib/tk.rb', line 1005
def bind(tagOrClass, context, *args)
if TkComm._callback_entry?(args[0]) || !block_given?
cmd = args.shift
else
cmd = Proc.new
end
_bind(["bind", tagOrClass], context, cmd, *args)
tagOrClass
end
|
#bind_all(context, *args) ⇒ Object
def bind_all(context, cmd=Proc.new, *args)
_bind(['bind', 'all'], context, cmd, *args)
TkBindTag::ALL
end
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
|
# File 'lib/tk.rb', line 1044
def bind_all(context, *args)
if TkComm._callback_entry?(args[0]) || !block_given?
cmd = args.shift
else
cmd = Proc.new
end
_bind(['bind', 'all'], context, cmd, *args)
TkBindTag::ALL
end
|
#bind_append(tagOrClass, context, *args) ⇒ Object
def bind_append(tagOrClass, context, cmd=Proc.new, *args)
_bind_append(["bind", tagOrClass], context, cmd, *args)
tagOrClass
end
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
|
# File 'lib/tk.rb', line 1020
def bind_append(tagOrClass, context, *args)
if TkComm._callback_entry?(args[0]) || !block_given?
cmd = args.shift
else
cmd = Proc.new
end
_bind_append(["bind", tagOrClass], context, cmd, *args)
tagOrClass
end
|
#bind_append_all(context, *args) ⇒ Object
def bind_append_all(context, cmd=Proc.new, *args)
_bind_append(['bind', 'all'], context, cmd, *args)
TkBindTag::ALL
end
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
|
# File 'lib/tk.rb', line 1059
def bind_append_all(context, *args)
if TkComm._callback_entry?(args[0]) || !block_given?
cmd = args.shift
else
cmd = Proc.new
end
_bind_append(['bind', 'all'], context, cmd, *args)
TkBindTag::ALL
end
|
#bind_remove(tagOrClass, context) ⇒ Object
1031
1032
1033
1034
|
# File 'lib/tk.rb', line 1031
def bind_remove(tagOrClass, context)
_bind_remove(['bind', tagOrClass], context)
tagOrClass
end
|
#bind_remove_all(context) ⇒ Object
1070
1071
1072
1073
|
# File 'lib/tk.rb', line 1070
def bind_remove_all(context)
_bind_remove(['bind', 'all'], context)
TkBindTag::ALL
end
|
#bindinfo(tagOrClass, context = nil) ⇒ Object
1036
1037
1038
|
# File 'lib/tk.rb', line 1036
def bindinfo(tagOrClass, context=nil)
_bindinfo(['bind', tagOrClass], context)
end
|
#bindinfo_all(context = nil) ⇒ Object
1075
1076
1077
|
# File 'lib/tk.rb', line 1075
def bindinfo_all(context=nil)
_bindinfo(['bind', 'all'], context)
end
|
#subst(str, *opts) ⇒ Object
628
629
630
631
632
633
634
635
|
# File 'lib/tk.rb', line 628
def subst(str, *opts)
tk_call('subst',
*(opts.collect{|opt|
opt = opt.to_s
(opt[0] == ?-)? opt: '-' << opt
} << str))
end
|