1 # 2 # tk/pack.rb : control pack geometry manager 3 # 4 require 'tk' 5 6 module TkPack 7 include Tk 8 extend Tk 9 10 TkCommandNames = ['pack'.freeze].freeze 11 12 =begin 13 def configure(win, *args) 14 if args[-1].kind_of?(Hash) 15 opts = args.pop 16 else 17 opts = {} 18 end 19 params = [] 20 # params.push((win.kind_of?(TkObject))? win.epath: win) 21 params.push(_epath(win)) 22 args.each{|win| 23 # params.push((win.kind_of?(TkObject))? win.epath: win) 24 params.push(_epath(win)) 25 } 26 opts.each{|k, v| 27 params.push("-#{k}") 28 # params.push((v.kind_of?(TkObject))? v.epath: v) 29 params.push(_epath(v)) 30 } 31 tk_call_without_enc("pack", 'configure', *params) 32 end 33 =end 34 def configure(*args) 35 if args[-1].kind_of?(Hash) 36 opts = args.pop 37 else 38 opts = {} 39 end 40 fail ArgumentError, 'no widget is given' if args.empty? 41 params = [] 42 args.flatten(1).each{|win| params.push(_epath(win))} 43 opts.each{|k, v| 44 params.push("-#{k}") 45 params.push(_epath(v)) # have to use 'epath' (hash_kv() is unavailable) 46 } 47 tk_call_without_enc("pack", 'configure', *params) 48 end 49 alias pack configure 50 51 def forget(*args) 52 return '' if args.size == 0 53 wins = args.collect{|win| 54 # (win.kind_of?(TkObject))? win.epath: win 55 _epath(win) 56 } 57 tk_call_without_enc('pack', 'forget', *wins) 58 end 59 60 def info(slave) 61 # slave = slave.epath if slave.kind_of?(TkObject) 62 slave = _epath(slave) 63 ilist = list(tk_call_without_enc('pack', 'info', slave)) 64 info = {} 65 while key = ilist.shift 66 info[key[1..-1]] = ilist.shift 67 end 68 return info 69 end 70 71 def propagate(master, mode=None) 72 # master = master.epath if master.kind_of?(TkObject) 73 master = _epath(master) 74 if mode == None 75 bool(tk_call_without_enc('pack', 'propagate', master)) 76 else 77 tk_call_without_enc('pack', 'propagate', master, mode) 78 end 79 end 80 81 def slaves(master) 82 # master = master.epath if master.kind_of?(TkObject) 83 master = _epath(master) 84 list(tk_call_without_enc('pack', 'slaves', master)) 85 end 86 87 module_function :pack, :configure, :forget, :info, :propagate, :slaves 88 end 89 =begin 90 def TkPack(win, *args) 91 if args[-1].kind_of?(Hash) 92 opts = args.pop 93 else 94 opts = {} 95 end 96 params = [] 97 params.push((win.kind_of?(TkObject))? win.epath: win) 98 args.each{|win| 99 params.push((win.kind_of?(TkObject))? win.epath: win) 100 } 101 opts.each{|k, v| 102 params.push("-#{k}") 103 params.push((v.kind_of?(TkObject))? v.epath: v) 104 } 105 tk_call_without_enc("pack", *params) 106 end 107 =end