1# 2# tkextlib/bwidget/buttonbox.rb 3# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) 4# 5 6require 'tk' 7require 'tkextlib/bwidget.rb' 8require 'tkextlib/bwidget/button' 9 10module Tk 11 module BWidget 12 class ButtonBox < TkWindow 13 end 14 end 15end 16 17class Tk::BWidget::ButtonBox 18 TkCommandNames = ['ButtonBox'.freeze].freeze 19 WidgetClassName = 'ButtonBox'.freeze 20 WidgetClassNames[WidgetClassName] ||= self 21 22 include TkItemConfigMethod 23 24 def __boolval_optkeys 25 super() << 'homogeneous' 26 end 27 private :__boolval_optkeys 28 29 def tagid(tagOrId) 30 if tagOrId.kind_of?(Tk::BWidget::Button) 31 name = tagOrId[:name] 32 return index(name) unless name.empty? 33 end 34 if tagOrId.kind_of?(Tk::Button) 35 return index(tagOrId[:text]) 36 end 37 # index(tagOrId.to_s) 38 index(_get_eval_string(tagOrId)) 39 end 40 41 def add(keys={}, &b) 42 win = window(tk_send('add', *hash_kv(keys))) 43 if b 44 if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!! 45 win.instance_exec(self, &b) 46 else 47 win.instance_eval(&b) 48 end 49 end 50 win 51 end 52 53 def delete(idx) 54 tk_send('delete', tagid(idx)) 55 self 56 end 57 58 def index(idx) 59 if idx.kind_of?(Tk::BWidget::Button) 60 name = idx[:name] 61 idx = name unless name.empty? 62 end 63 if idx.kind_of?(Tk::Button) 64 idx = idx[:text] 65 end 66 number(tk_send('index', idx.to_s)) 67 end 68 69 def insert(idx, keys={}, &b) 70 win = window(tk_send('insert', tagid(idx), *hash_kv(keys))) 71 if b 72 if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!! 73 win.instance_exec(self, &b) 74 else 75 win.instance_eval(&b) 76 end 77 end 78 win 79 end 80 81 def invoke(idx) 82 tk_send('invoke', tagid(idx)) 83 self 84 end 85 86 def set_focus(idx) 87 tk_send('setfocus', tagid(idx)) 88 self 89 end 90end 91