tk 0.1.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +2 -0
  3. data/MANUAL_tcltklib.eng +0 -2
  4. data/MANUAL_tcltklib.ja +0 -2
  5. data/README.ActiveTcl +1 -1
  6. data/README.md +53 -1
  7. data/ext/tk/extconf.rb +4 -2
  8. data/ext/tk/old-extconf.rb +0 -1
  9. data/ext/tk/tcltklib.c +47 -149
  10. data/ext/tk/tkutil/extconf.rb +0 -2
  11. data/ext/tk/tkutil/tkutil.c +6 -9
  12. data/lib/multi-tk.rb +99 -320
  13. data/lib/remote-tk.rb +8 -25
  14. data/lib/tk.rb +49 -130
  15. data/lib/tk/autoload.rb +3 -3
  16. data/lib/tk/bgerror.rb +2 -2
  17. data/lib/tk/bindtag.rb +1 -1
  18. data/lib/tk/canvas.rb +7 -15
  19. data/lib/tk/canvastag.rb +11 -19
  20. data/lib/tk/entry.rb +1 -1
  21. data/lib/tk/font.rb +1 -1
  22. data/lib/tk/fontchooser.rb +1 -1
  23. data/lib/tk/grid.rb +4 -4
  24. data/lib/tk/image.rb +1 -1
  25. data/lib/tk/itemconfig.rb +4 -4
  26. data/lib/tk/itemfont.rb +3 -3
  27. data/lib/tk/listbox.rb +1 -1
  28. data/lib/tk/menu.rb +4 -4
  29. data/lib/tk/menuspec.rb +0 -1
  30. data/lib/tk/msgcat.rb +5 -5
  31. data/lib/tk/namespace.rb +14 -34
  32. data/lib/tk/optiondb.rb +3 -74
  33. data/lib/tk/optionobj.rb +1 -1
  34. data/lib/tk/scale.rb +3 -3
  35. data/lib/tk/scrollable.rb +4 -2
  36. data/lib/tk/selection.rb +5 -4
  37. data/lib/tk/text.rb +9 -17
  38. data/lib/tk/textmark.rb +1 -1
  39. data/lib/tk/texttag.rb +7 -15
  40. data/lib/tk/timer.rb +2 -2
  41. data/lib/tk/tk_mac.rb +18 -18
  42. data/lib/tk/validation.rb +6 -37
  43. data/lib/tk/variable.rb +10 -8
  44. data/lib/tk/virtevent.rb +1 -1
  45. data/lib/tk/winfo.rb +1 -1
  46. data/lib/tkextlib/blt/barchart.rb +0 -17
  47. data/lib/tkextlib/blt/bitmap.rb +1 -1
  48. data/lib/tkextlib/blt/component.rb +40 -40
  49. data/lib/tkextlib/blt/dragdrop.rb +6 -6
  50. data/lib/tkextlib/blt/graph.rb +0 -17
  51. data/lib/tkextlib/blt/stripchart.rb +0 -17
  52. data/lib/tkextlib/blt/tabset.rb +16 -31
  53. data/lib/tkextlib/blt/tree.rb +6 -6
  54. data/lib/tkextlib/blt/treeview.rb +14 -14
  55. data/lib/tkextlib/blt/watch.rb +1 -1
  56. data/lib/tkextlib/bwidget/labelentry.rb +6 -14
  57. data/lib/tkextlib/bwidget/listbox.rb +13 -29
  58. data/lib/tkextlib/bwidget/notebook.rb +6 -14
  59. data/lib/tkextlib/bwidget/progressdlg.rb +2 -2
  60. data/lib/tkextlib/bwidget/spinbox.rb +6 -14
  61. data/lib/tkextlib/bwidget/tree.rb +19 -35
  62. data/lib/tkextlib/itcl/incr_tcl.rb +2 -2
  63. data/lib/tkextlib/itk/incr_tk.rb +7 -29
  64. data/lib/tkextlib/iwidgets/calendar.rb +0 -15
  65. data/lib/tkextlib/iwidgets/entryfield.rb +1 -22
  66. data/lib/tkextlib/iwidgets/notebook.rb +2 -2
  67. data/lib/tkextlib/iwidgets/promptdialog.rb +1 -1
  68. data/lib/tkextlib/iwidgets/scrolledcanvas.rb +6 -14
  69. data/lib/tkextlib/iwidgets/spinner.rb +1 -1
  70. data/lib/tkextlib/iwidgets/tabnotebook.rb +2 -2
  71. data/lib/tkextlib/iwidgets/tabset.rb +1 -1
  72. data/lib/tkextlib/pkg_checker.rb +1 -1
  73. data/lib/tkextlib/tcllib/crosshair.rb +2 -2
  74. data/lib/tkextlib/tcllib/ctext.rb +2 -2
  75. data/lib/tkextlib/tcllib/plotchart.rb +5 -5
  76. data/lib/tkextlib/tcllib/tablelist_core.rb +3 -3
  77. data/lib/tkextlib/tcllib/validator.rb +6 -6
  78. data/lib/tkextlib/tile.rb +1 -2
  79. data/lib/tkextlib/tile/style.rb +1 -1
  80. data/lib/tkextlib/tile/treeview.rb +15 -22
  81. data/lib/tkextlib/tkDND/tkdnd.rb +63 -24
  82. data/lib/tkextlib/tkHTML/htmlwidget.rb +1 -1
  83. data/lib/tkextlib/tktable/tktable.rb +2 -2
  84. data/lib/tkextlib/treectrl/tktreectrl.rb +13 -21
  85. data/lib/tkextlib/vu/pie.rb +1 -1
  86. data/sample/binding_sample.rb +2 -2
  87. data/sample/cmd_res_test.rb +1 -1
  88. data/sample/demos-en/widget +21 -21
  89. data/sample/demos-jp/widget +4 -4
  90. data/sample/multi-ip_sample.rb +0 -3
  91. data/sample/multi-ip_sample2.rb +1 -1
  92. data/sample/resource.en +3 -3
  93. data/sample/resource.ja +3 -3
  94. data/sample/tcltklib/sample1.rb +2 -2
  95. data/sample/tkballoonhelp.rb +2 -2
  96. data/sample/tkextlib/tkHTML/ss.rb +0 -6
  97. data/sample/tkmulticolumnlist.rb +2 -2
  98. data/sample/tkmultilistframe.rb +2 -2
  99. data/sample/tkoptdb.rb +14 -16
  100. data/tk.gemspec +7 -8
  101. metadata +13 -15
  102. data/ChangeLog.tkextlib +0 -949
  103. data/old-README.tcltklib.ja +0 -159
  104. data/sample/binstr_usage.rb +0 -46
  105. data/sample/remote-ip_sample2.rb +0 -57
  106. data/sample/safe-tk.rb +0 -132
  107. data/sample/tkoptdb-safeTk.rb +0 -74
  108. data/sample/tktree.rb +0 -104
  109. data/sample/tktree.tcl +0 -305
data/lib/tk/autoload.rb CHANGED
@@ -452,7 +452,7 @@ class << Tk
452
452
 
453
453
  reg = /^#{Regexp.quote(auto)}(\.rb|\.so|)$/
454
454
  @TOPLEVEL_ALIAS_TABLE.each_key{|set|
455
- if @TOPLEVEL_ALIAS_TABLE[set][sym] =~ reg
455
+ if reg =~ @TOPLEVEL_ALIAS_TABLE[set][sym].to_s
456
456
  @TOPLEVEL_ALIAS_TABLE[set][sym] = obj
457
457
  if @TOPLEVEL_ALIAS_OWNER[sym].nil? || @TOPLEVEL_ALIAS_OWNER[sym] == set
458
458
  replace_topalias(sym, obj)
@@ -460,10 +460,10 @@ class << Tk
460
460
  end
461
461
  end
462
462
  }
463
- if (f = Object.autoload?(sym)) && f =~ reg
463
+ if (f = Object.autoload?(sym)) && reg =~ f.to_s
464
464
  replace_topobj(sym, obj)
465
465
  end
466
- if (f = Tk::TOPLEVEL_ALIASES.autoload?(sym)) && f =~ reg
466
+ if (f = Tk::TOPLEVEL_ALIASES.autoload?(sym)) && reg =~ f.to_s
467
467
  replace_topalias(sym, obj)
468
468
  end
469
469
  end
data/lib/tk/bgerror.rb CHANGED
@@ -17,8 +17,8 @@ module TkBgError
17
17
  alias show bgerror
18
18
  module_function :bgerror, :tkerror, :show
19
19
 
20
- def set_handler(hdlr = Proc.new) #==> handler :: proc{|msg| ...body... }
21
- tk_call('proc', 'bgerror', 'msg', install_cmd(hdlr) + ' $msg')
20
+ def set_handler(hdlr = nil, &block) #==> handler :: proc{|msg| ...body... }
21
+ tk_call('proc', 'bgerror', 'msg', install_cmd(hdlr || block) + ' $msg')
22
22
  end
23
23
  def set_default
24
24
  begin
data/lib/tk/bindtag.rb CHANGED
@@ -10,7 +10,7 @@ class TkBindTag
10
10
  #BTagID_TBL = {}
11
11
  BTagID_TBL = TkCore::INTERP.create_table
12
12
 
13
- (Tk_BINDTAG_ID = ["btag".freeze, TkUtil.untrust("00000")]).instance_eval{
13
+ (Tk_BINDTAG_ID = ["btag".freeze, "00000"]).instance_eval{
14
14
  @mutex = Mutex.new
15
15
  def mutex; @mutex; end
16
16
  freeze
data/lib/tk/canvas.rb CHANGED
@@ -131,31 +131,23 @@ class Tk::Canvas<TkWindow
131
131
  *tags.collect{|t| tagid(t)}))
132
132
  end
133
133
 
134
- #def itembind(tag, context, cmd=Proc.new, *args)
135
- # _bind([path, "bind", tagid(tag)], context, cmd, *args)
136
- # self
137
- #end
138
- def itembind(tag, context, *args)
134
+ def itembind(tag, context, *args, &block)
139
135
  # if args[0].kind_of?(Proc) || args[0].kind_of?(Method)
140
- if TkComm._callback_entry?(args[0]) || !block_given?
136
+ if TkComm._callback_entry?(args[0]) || !block
141
137
  cmd = args.shift
142
138
  else
143
- cmd = Proc.new
139
+ cmd = block
144
140
  end
145
141
  _bind([path, "bind", tagid(tag)], context, cmd, *args)
146
142
  self
147
143
  end
148
144
 
149
- #def itembind_append(tag, context, cmd=Proc.new, *args)
150
- # _bind_append([path, "bind", tagid(tag)], context, cmd, *args)
151
- # self
152
- #end
153
- def itembind_append(tag, context, *args)
145
+ def itembind_append(tag, context, *args, &block)
154
146
  # if args[0].kind_of?(Proc) || args[0].kind_of?(Method)
155
- if TkComm._callback_entry?(args[0]) || !block_given?
147
+ if TkComm._callback_entry?(args[0]) || !block
156
148
  cmd = args.shift
157
149
  else
158
- cmd = Proc.new
150
+ cmd = block
159
151
  end
160
152
  _bind_append([path, "bind", tagid(tag)], context, cmd, *args)
161
153
  self
@@ -566,7 +558,7 @@ class Tk::Canvas<TkWindow
566
558
 
567
559
  def rchars(tag, first, last, str_or_coords)
568
560
  # Tcl/Tk 8.6 or later
569
- str_or_coords = str_or_coords.flatten if str_or_coords.kinad_of? Array
561
+ str_or_coords = str_or_coords.flatten if str_or_coords.kind_of? Array
570
562
  tk_send_without_enc('rchars', tagid(tag), first, last, str_or_coords)
571
563
  self
572
564
  end
data/lib/tk/canvastag.rb CHANGED
@@ -22,31 +22,23 @@ module TkcTagAccess
22
22
  @c.bbox(@id)
23
23
  end
24
24
 
25
- #def bind(seq, cmd=Proc.new, *args)
26
- # @c.itembind(@id, seq, cmd, *args)
27
- # self
28
- #end
29
- def bind(seq, *args)
25
+ def bind(seq, *args, &block)
30
26
  # if args[0].kind_of?(Proc) || args[0].kind_of?(Method)
31
- if TkComm._callback_entry?(args[0]) || !block_given?
27
+ if TkComm._callback_entry?(args[0]) || !block
32
28
  cmd = args.shift
33
29
  else
34
- cmd = Proc.new
30
+ cmd = block
35
31
  end
36
32
  @c.itembind(@id, seq, cmd, *args)
37
33
  self
38
34
  end
39
35
 
40
- #def bind_append(seq, cmd=Proc.new, *args)
41
- # @c.itembind_append(@id, seq, cmd, *args)
42
- # self
43
- #end
44
- def bind_append(seq, *args)
36
+ def bind_append(seq, *args, &block)
45
37
  # if args[0].kind_of?(Proc) || args[0].kind_of?(Method)
46
- if TkComm._callback_entry?(args[0]) || !block_given?
38
+ if TkComm._callback_entry?(args[0]) || !block
47
39
  cmd = args.shift
48
40
  else
49
- cmd = Proc.new
41
+ cmd = block
50
42
  end
51
43
  @c.itembind_append(@id, seq, cmd, *args)
52
44
  self
@@ -195,7 +187,7 @@ module TkcTagAccess
195
187
  # ltag = tag1 | tag2; ltag.path => "(t1)||(t2)"
196
188
  # ltag = tag1 ^ tag2; ltag.path => "(t1)^(t2)"
197
189
  # ltag = - tag1; ltag.path => "!(t1)"
198
- def & (tag)
190
+ def &(tag)
199
191
  if tag.kind_of? TkObject
200
192
  TkcTagString.new(@c, '(' + @id + ')&&(' + tag.path + ')')
201
193
  else
@@ -203,7 +195,7 @@ module TkcTagAccess
203
195
  end
204
196
  end
205
197
 
206
- def | (tag)
198
+ def |(tag)
207
199
  if tag.kind_of? TkObject
208
200
  TkcTagString.new(@c, '(' + @id + ')||(' + tag.path + ')')
209
201
  else
@@ -211,7 +203,7 @@ module TkcTagAccess
211
203
  end
212
204
  end
213
205
 
214
- def ^ (tag)
206
+ def ^(tag)
215
207
  if tag.kind_of? TkObject
216
208
  TkcTagString.new(@c, '(' + @id + ')^(' + tag.path + ')')
217
209
  else
@@ -229,7 +221,7 @@ class TkcTag<TkObject
229
221
 
230
222
  CTagID_TBL = TkCore::INTERP.create_table
231
223
 
232
- (Tk_CanvasTag_ID = ['ctag'.freeze, TkUtil.untrust('00000')]).instance_eval{
224
+ (Tk_CanvasTag_ID = ['ctag'.freeze, '00000']).instance_eval{
233
225
  @mutex = Mutex.new
234
226
  def mutex; @mutex; end
235
227
  freeze
@@ -415,7 +407,7 @@ class TkcTagCurrent<TkcTagString
415
407
  end
416
408
 
417
409
  class TkcGroup<TkcTag
418
- (Tk_cGroup_ID = ['tkcg'.freeze, TkUtil.untrust('00000')]).instance_eval{
410
+ (Tk_cGroup_ID = ['tkcg'.freeze, '00000']).instance_eval{
419
411
  @mutex = Mutex.new
420
412
  def mutex; @mutex; end
421
413
  freeze
data/lib/tk/entry.rb CHANGED
@@ -96,7 +96,7 @@ class Tk::Entry<Tk::Label
96
96
  def value
97
97
  _fromUTF8(tk_send_without_enc('get'))
98
98
  end
99
- def value= (val)
99
+ def value=(val)
100
100
  tk_send_without_enc('delete', 0, 'end')
101
101
  tk_send_without_enc('insert', 0, _get_eval_enc_str(val))
102
102
  val
data/lib/tk/font.rb CHANGED
@@ -12,7 +12,7 @@ class TkFont
12
12
 
13
13
  TkCommandNames = ['font'.freeze].freeze
14
14
 
15
- (Tk_FontID = ["@font".freeze, TkUtil.untrust("00000")]).instance_eval{
15
+ (Tk_FontID = ["@font".freeze, "00000"]).instance_eval{
16
16
  @mutex = Mutex.new
17
17
  def mutex; @mutex; end
18
18
  freeze
@@ -109,7 +109,7 @@ class << TkFont::Chooser
109
109
  if cmd
110
110
  configure_cmd('command', cmd)
111
111
  elsif b
112
- configure_cmd('command', Proc.new(&b))
112
+ configure_cmd('command', b)
113
113
  else
114
114
  cget('command')
115
115
  end
data/lib/tk/grid.rb CHANGED
@@ -66,15 +66,15 @@ module TkGrid
66
66
  params = []
67
67
  args.flatten(1).each{|win|
68
68
  case win
69
- when '-', ?- # RELATIVE PLACEMENT (increase columnspan)
69
+ when '-', ?-.ord # RELATIVE PLACEMENT (increase columnspan)
70
70
  params.push('-')
71
71
  when /^-+$/ # RELATIVE PLACEMENT (increase columnspan)
72
72
  params.concat(win.to_s.split(//))
73
- when '^', ?^ # RELATIVE PLACEMENT (increase rowspan)
73
+ when '^', ?^.ord # RELATIVE PLACEMENT (increase rowspan)
74
74
  params.push('^')
75
75
  when /^\^+$/ # RELATIVE PLACEMENT (increase rowspan)
76
76
  params.concat(win.to_s.split(//))
77
- when 'x', :x, ?x, nil, '' # RELATIVE PLACEMENT (empty column)
77
+ when 'x', :x, ?x.ord, nil, '' # RELATIVE PLACEMENT (empty column)
78
78
  params.push('x')
79
79
  when /^x+$/ # RELATIVE PLACEMENT (empty column)
80
80
  params.concat(win.to_s.split(//))
@@ -243,7 +243,7 @@ module TkGrid
243
243
  list(tk_call_without_enc('grid', 'size', master))
244
244
  end
245
245
 
246
- def slaves(master, keys=nil)
246
+ def slaves(master, args=nil)
247
247
  # master = master.epath if master.kind_of?(TkObject)
248
248
  master = _epath(master)
249
249
  list(tk_call_without_enc('grid', 'slaves', master, *hash_kv(args)))
data/lib/tk/image.rb CHANGED
@@ -12,7 +12,7 @@ class TkImage<TkObject
12
12
 
13
13
  Tk_IMGTBL = TkCore::INTERP.create_table
14
14
 
15
- (Tk_Image_ID = ['i'.freeze, TkUtil.untrust('00000')]).instance_eval{
15
+ (Tk_Image_ID = ['i'.freeze, '00000']).instance_eval{
16
16
  @mutex = Mutex.new
17
17
  def mutex; @mutex; end
18
18
  freeze
data/lib/tk/itemconfig.rb CHANGED
@@ -177,7 +177,7 @@ module TkItemConfigMethod
177
177
  fail ArgumentError, "Invalid option `#{orig_opt.inspect}'"
178
178
  end
179
179
 
180
- alias_name, real_name = __item_optkey_aliases(tagid(tagOrId)).find{|k, v| k.to_s == option}
180
+ _, real_name = __item_optkey_aliases(tagid(tagOrId)).find{|k, v| k.to_s == option}
181
181
  if real_name
182
182
  option = real_name.to_s
183
183
  end
@@ -324,7 +324,7 @@ module TkItemConfigMethod
324
324
  fail ArgumentError, "Invalid option `#{orig_slot.inspect}'"
325
325
  end
326
326
 
327
- alias_name, real_name = __item_optkey_aliases(tagid(tagOrId)).find{|k, v| k.to_s == slot}
327
+ _, real_name = __item_optkey_aliases(tagid(tagOrId)).find{|k, v| k.to_s == slot}
328
328
  if real_name
329
329
  slot = real_name.to_s
330
330
  end
@@ -429,7 +429,7 @@ module TkItemConfigMethod
429
429
  if slot
430
430
  slot = slot.to_s
431
431
 
432
- alias_name, real_name = __item_optkey_aliases(tagid(tagOrId)).find{|k, v| k.to_s == slot}
432
+ _, real_name = __item_optkey_aliases(tagid(tagOrId)).find{|k, v| k.to_s == slot}
433
433
  if real_name
434
434
  slot = real_name.to_s
435
435
  end
@@ -806,7 +806,7 @@ module TkItemConfigMethod
806
806
  if slot
807
807
  slot = slot.to_s
808
808
 
809
- alias_name, real_name = __item_optkey_aliases(tagid(tagOrId)).find{|k, v| k.to_s == slot}
809
+ _, real_name = __item_optkey_aliases(tagid(tagOrId)).find{|k, v| k.to_s == slot}
810
810
  if real_name
811
811
  slot = real_name.to_s
812
812
  end
data/lib/tk/itemfont.rb CHANGED
@@ -101,7 +101,7 @@ module TkTreatItemFont
101
101
  else
102
102
  begin
103
103
  tk_call(*(__item_config_cmd(tagid(tagOrId)) << "-#{optkey}" << fnt))
104
- rescue => e
104
+ rescue
105
105
  # ignore
106
106
  end
107
107
  end
@@ -163,7 +163,7 @@ module TkTreatItemFont
163
163
  else
164
164
  begin
165
165
  tk_call(*(__item_config_cmd(tagid(tagOrId)) << "-#{optkey}" << ltn))
166
- rescue => e
166
+ rescue
167
167
  # ignore
168
168
  end
169
169
  end
@@ -223,7 +223,7 @@ module TkTreatItemFont
223
223
  else
224
224
  begin
225
225
  tk_call(*(__item_config_cmd(tagid(tagOrId)) << "-#{optkey}" << knj))
226
- rescue => e
226
+ rescue
227
227
  # ignore
228
228
  end
229
229
  end
data/lib/tk/listbox.rb CHANGED
@@ -88,7 +88,7 @@ class Tk::Listbox<TkTextWin
88
88
  get('0', 'end')
89
89
  end
90
90
 
91
- def value= (vals)
91
+ def value=(vals)
92
92
  unless vals.kind_of?(Array)
93
93
  fail ArgumentError, 'an Array is expected'
94
94
  end
data/lib/tk/menu.rb CHANGED
@@ -186,16 +186,16 @@ class Tk::Menu<TkWindow
186
186
  tk_send_without_enc('postcascade', _get_eval_enc_str(index))
187
187
  self
188
188
  end
189
- def postcommand(cmd=Proc.new)
190
- configure_cmd 'postcommand', cmd
189
+ def postcommand(cmd=nil, &block)
190
+ configure_cmd('postcommand', cmd || block)
191
191
  self
192
192
  end
193
193
  def set_focus
194
194
  tk_call_without_enc('tk_menuSetFocus', path)
195
195
  self
196
196
  end
197
- def tearoffcommand(cmd=Proc.new)
198
- configure_cmd 'tearoffcommand', cmd
197
+ def tearoffcommand(cmd=nil, &block)
198
+ configure_cmd('tearoffcommand', cmd || block)
199
199
  self
200
200
  end
201
201
  def menutype(index)
data/lib/tk/menuspec.rb CHANGED
@@ -210,7 +210,6 @@ module TkMenuSpec
210
210
  private :_create_menu
211
211
 
212
212
  def _use_menubar?(parent)
213
- use_menubar = false
214
213
  if parent.kind_of?(Tk::Root) || parent.kind_of?(Tk::Toplevel)
215
214
  true
216
215
  elsif parent.current_configinfo.has_key?('menu')
data/lib/tk/msgcat.rb CHANGED
@@ -37,7 +37,7 @@ class TkMsgCatalog < TkObject
37
37
 
38
38
  MSGCAT_EXT = '.msg'
39
39
 
40
- UNKNOWN_CBTBL = TkUtil.untrust(Hash.new{|hash,key| hash[key] = {}})
40
+ UNKNOWN_CBTBL = Hash.new{|hash,key| hash[key] = {}}
41
41
 
42
42
  TkCore::INTERP.add_tk_procs('::msgcat::mcunknown', 'args', <<-'EOL')
43
43
  if {[set st [catch {eval {ruby_cmd TkMsgCatalog callback} [namespace current] $args} ret]] != 0} {
@@ -289,11 +289,11 @@ class TkMsgCatalog < TkObject
289
289
  })
290
290
  end
291
291
 
292
- def self.def_unknown_proc(cmd=Proc.new)
293
- TkMsgCatalog::UNKNOWN_CBTBL[TkCore::INTERP.__getip]['::'] = cmd
292
+ def self.def_unknown_proc(cmd=nil, &block)
293
+ TkMsgCatalog::UNKNOWN_CBTBL[TkCore::INTERP.__getip]['::'] = cmd || block
294
294
  end
295
- def def_unknown_proc(cmd=Proc.new)
296
- TkMsgCatalog::UNKNOWN_CBTBL[TkCore::INTERP.__getip][@namespace.path] = cmd
295
+ def def_unknown_proc(cmd=nil, &block)
296
+ TkMsgCatalog::UNKNOWN_CBTBL[TkCore::INTERP.__getip][@namespace.path] = cmd || block
297
297
  end
298
298
  end
299
299
 
data/lib/tk/namespace.rb CHANGED
@@ -14,7 +14,7 @@ class TkNamespace < TkObject
14
14
 
15
15
  Tk_Namespace_ID_TBL = TkCore::INTERP.create_table
16
16
 
17
- (Tk_Namespace_ID = ["ns".freeze, TkUtil.untrust("00000")]).instance_eval{
17
+ (Tk_Namespace_ID = ["ns".freeze, "00000"]).instance_eval{
18
18
  @mutex = Mutex.new
19
19
  def mutex; @mutex; end
20
20
  freeze
@@ -257,7 +257,7 @@ class TkNamespace < TkObject
257
257
  if name =~ /^::/
258
258
  @fullname = parent + name
259
259
  else
260
- @fullname = parent +'::'+ name
260
+ @fullname = parent + '::' + name
261
261
  end
262
262
  else
263
263
  ancestor = __tk_call('namespace', 'current')
@@ -265,7 +265,7 @@ class TkNamespace < TkObject
265
265
  if name =~ /^::/
266
266
  @fullname = ancestor + '::' + parent + name
267
267
  else
268
- @fullname = ancestor + '::'+ parent +'::'+ name
268
+ @fullname = ancestor + '::' + parent + '::' + name
269
269
  end
270
270
  end
271
271
  else # parent == nil
@@ -307,23 +307,12 @@ class TkNamespace < TkObject
307
307
  TkNamespace.children(@fullname, pattern)
308
308
  end
309
309
 
310
- def self.code(script = Proc.new)
311
- TkNamespace.new('').code(script)
310
+ def self.code(script = nil, &block)
311
+ TkNamespace.new('').code(script || block)
312
312
  end
313
- =begin
314
- def code(script = Proc.new)
315
- if script.kind_of?(String)
316
- cmd = proc{|*args| ScopeArgs.new(@fullname,*args).instance_eval(script)}
317
- elsif script.kind_of?(Proc)
318
- cmd = proc{|*args| ScopeArgs.new(@fullname,*args).instance_eval(&script)}
319
- else
320
- fail ArgumentError, "String or Proc is expected"
321
- end
322
- TkNamespace::NsCode.new(tk_call_without_enc('namespace', 'code',
323
- _get_eval_string(cmd, false)))
324
- end
325
- =end
326
- def code(script = Proc.new)
313
+
314
+ def code(script = nil, &block)
315
+ script ||= block
327
316
  if script.kind_of?(String)
328
317
  cmd = proc{|*args|
329
318
  ret = ScopeArgs.new(@fullname,*args).instance_eval(script)
@@ -414,22 +403,13 @@ class TkNamespace < TkObject
414
403
  bool(tk_call('namespace', 'ensemble', 'exists', cmd))
415
404
  end
416
405
 
417
- def self.eval(namespace, cmd = Proc.new, *args)
406
+ def self.eval(namespace, cmd = nil, *args, &block)
407
+ cmd ||= block
418
408
  #tk_call('namespace', 'eval', namespace, cmd, *args)
419
409
  TkNamespace.new(namespace).eval(cmd, *args)
420
410
  end
421
- =begin
422
- def eval(cmd = Proc.new, *args)
423
- #TkNamespace.eval(@fullname, cmd, *args)
424
- #ns_tk_call(cmd, *args)
425
- code_obj = code(cmd)
426
- ret = code_obj.call(*args)
427
- # uninstall_cmd(TkCore::INTERP._split_tklist(code_obj.path)[-1])
428
- uninstall_cmd(_fromUTF8(TkCore::INTERP._split_tklist(_toUTF8(code_obj.path))[-1]))
429
- tk_tcl2ruby(ret)
430
- end
431
- =end
432
- def eval(cmd = Proc.new, *args)
411
+ def eval(cmd = nil, *args, &block)
412
+ cmd ||= block
433
413
  code_obj = code(cmd)
434
414
  ret = code_obj.call(*args)
435
415
  uninstall_cmd(_fromUTF8(TkCore::INTERP._split_tklist(_toUTF8(code_obj.path))[-1]))
@@ -529,8 +509,8 @@ class TkNamespace < TkObject
529
509
  def self.get_unknown_handler
530
510
  tk_tcl2ruby(tk_call('namespace', 'unknown'))
531
511
  end
532
- def self.set_unknown_handler(cmd = Proc.new)
533
- tk_call('namespace', 'unknown', cmd)
512
+ def self.set_unknown_handler(cmd = nil, &block)
513
+ tk_call('namespace', 'unknown', cmd || block)
534
514
  end
535
515
 
536
516
  def self.which(name)