[Tk] grid manager with '-', 'x', '^'

  • Thread starter email55555 email55555
  • Start date
E

email55555 email55555

Just curious about special char with grid manager:

On Tcl/Tk:
grid .a - -
grid ^ .b x

This first line of TCL could translate on Ruby/Tk as:
Tk.grid a, '-', '-' # a.path == '.a'

There is no way to tranlate the second line without using any
:row, :column, :rowspan, coloumnspan.
Because TkGrid.configure want the first parameter is *win*.

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 ?

Thanks.
 
F

Ferenc Engard

Hi!

email55555 said:
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 <<widgets>> contain TkWindow objects. If
not nil,
# then <<widgethash>> is a hash of widgets, and <<widgets>> 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
 
H

Hidetoshi NAGAI

Hi,

From: email55555 email55555 <[email protected]>
Subject: [Tk] grid manager with '-', 'x', '^'
Date: Sat, 18 Dec 2004 02:50:23 +0900
Message-ID: said:
Is this right or do we have other trick for it ?

No. TkGrid supports them. Please try the following.
------------------------------------------------
require 'tk'

a = TkButton.new:)text=>'a')
b = TkButton.new:)text=>'b')
c = TkButton.new:)text=>'c')

TkGrid.configure( a , '-', :sticky=>'news') # or Tk.grid
TkGrid.configure('^', '^', b , :sticky=>'news') # or Tk.grid
TkGrid.configure( c , 'x', '^', :sticky=>'news') # or Tk.grid

TkGrid.columnconfigure(Tk.root, [0,1,2], :weight=>1) # or Tk.grid_columnconfig
TkGrid.rowconfigure(Tk.root, [0,1,2], :weight=>1) # or Tk.grid_rowconfig

Tk.root.geometry('250x250')

Tk.mainloop
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top