From: Ferenc Engard Date: 2004-12-20T08:57:36+09:00 Subject: Re: [Tk] grid manager with '-', 'x', '^' Hi! email55555 email55555 wrote: > > Just curious about special char with grid manager: > > On Tcl/Tk: > grid .a - - > grid ^ .b x [...] > So, grid manager with relative placement on Ruby/Tk works only when > the "first" is *win*. > > Is this right or do we have other trick for it ? I do not know, but I use a wrapper function for building grids: # Building a GUI with the Grid Geometry Manager. # widgets: Array of Arrays of widgets (and sticky info) (arrays are the rows, # widgets in the arrays are the cells) # widgethash: if nil, then <> contain TkWindow objects. If not nil, # then <> is a hash of widgets, and <> contains the keys in widgethash. # common: hash of common options to every widgets. def buildSimpleGrid(widgets,widgethash=nil,common={}) rowspan={} # A '^' widgetek rowspan-t jelentenek, mint a tk grid parancsn�l widgets.each_with_index {|row,i| colspan=[nil,1] # A '-' widgetek colspan-t jelentenek, mint a tk grid parancsn�l row.each_with_index {|cell,j| if cell.respond_to? :shift widget=cell.shift; sticky=cell.shift; sticky='nw' if sticky.nil? # default opts=cell.shift else widget=cell; sticky='nw' # default end if widget=='-' colspan[1]+=1 colspan[0].grid_config('columnspan',colspan[1]) #~ debug "colspan: widget #{colspan[0].to_eval}, colspan #{colspan[1]}" next elsif widget=='^' # rowspan raise "buildSimpleGrid problem!" if !rowspan[j] || !rowspan[j][0] rowspan[j][1]+=1 rowspan[j][0].grid_config('rowspan',rowspan[j][1]) next elsif widget=='x' next else widget=widgethash[widget] if !widgethash.nil? end h=common.dup.update({"row"=>i,"column"=>j,"sticky"=>sticky}) h.update(opts) if !opts.nil? widget.grid(h) colspan[0]=widget; colspan[1]=1 rowspan[j]=[]; rowspan[j] << widget; rowspan[j] << 1 } } end And you can use it like this: tmpgrid=[ [[widget_1_1,'e'], [widget_1_2,'ew'],'-'], [[widget_23_1,'e'], [widget_2_23,'ew']], ['^',[widget_3_2,'w'],[widget_3_3,'w']] ] buildSimpleGrid(tmpgrid,nil,{'in'=>parentFrame}) I wrote the example by hand; I hope it is understandable. The numbers in the end of the widget names mean the rows and columns where the given widget will appear. Hereby I place this piece of code in public domain. Just do not patent it! ;-) Bye: Ferenc