[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

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

email55555 email55555

12/17/2004 5:50:00 PM

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.


5 Answers

Ferenc Engard

12/19/2004 11:58:00 PM

0

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 <<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



Hidetoshi NAGAI

12/20/2004 2:32:00 AM

0

email55555 email55555

12/20/2004 7:43:00 PM

0

Thank you Hidetoshi.

I try your code, but got this error message:

c:/tools/ruby/lib/ruby/1.8/tk.rb:1434:in `_invoke_without_enc': bad argument "^"
: must be name of window (RuntimeError)
from c:/tools/ruby/lib/ruby/1.8/tk.rb:1434:in `_ip_invoke_core'
from c:/tools/ruby/lib/ruby/1.8/tk.rb:1470:in `_tk_call_core'
from c:/tools/ruby/lib/ruby/1.8/tk.rb:1498:in `tk_call_without_enc'
from c:/tools/ruby/lib/ruby/1.8/tk/grid.rb:45:in `configure'
from C:/tsh/ruby/tk/grid.rb:8
shell returned 1

Some information:

C:\tools\ruby>ruby -version
ruby 1.8.2 (2004-07-29) [i386-mswin32]
-e:1: undefined local variable or method `rsion' for main:Object (NameError)

C:\tools\ruby>ruby -rtk -e 'p Tk::TCL_VERSION'
"8.3"

C:\tools\ruby>ruby -rtk -e 'p Tk::TK_VERSION'
"8.3"
============================================

>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
>------------------------------------------------


email55555 email55555

12/20/2004 8:27:00 PM

0

re-install the last version of one-click install (ruby-1.8.2-RC10),
still got the same error message ...

C:\tools\ruby>ruby -v
ruby 1.8.2 (2004-11-06) [i386-mswin32]


Hidetoshi NAGAI

12/21/2004 3:26:00 AM

0