f



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

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.


0
email555551 (103)
12/17/2004 5:50:23 PM
comp.lang.ruby 48886 articles. 0 followers. Post Follow

5 Replies
619 Views

Similar Articles

[PageSpeed] 55

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



0
ferenc (127)
12/19/2004 11:57:36 PM
Hi, 

From: email55555 email55555 <email55555@gmail.com>
Subject: [Tk] grid manager with '-', 'x', '^'
Date: Sat, 18 Dec 2004 02:50:23 +0900
Message-ID: <91b08b8a04121709501a9ab49d@mail.gmail.com>
> 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
------------------------------------------------
-- 
Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)


0
nagai (573)
12/20/2004 2:32:26 AM
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
>------------------------------------------------


0
email555551 (103)
12/20/2004 7:43:04 PM
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]


0
email555551 (103)
12/20/2004 8:27:08 PM
Hi, 

From: Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
Subject: Re: [Tk] grid manager with '-', 'x', '^'
Date: Tue, 21 Dec 2004 10:26:06 +0900
Message-ID: <20041221.102605.41653851.nagai@ai.kyutech.ac.jp>
> I'll make patch for Tcl/Tk8.3 later. Please wait for it.

I'd applied the following patch. But I cannot rescue the bug on 
"TkGrid.configure( c , 'x', '^', :sticky=>'news')", 
because Tcl/Tk8.3 cannot accept both of "grid .c x ^ " and 
"grid configure .c x ^ ".
That is a bug on Tcl/Tk8.3.
The cost to rescue the bugs is probably too large. 
Please take that is a constraint of using Tcl/Tk8.3.

-------------------------------------------------------------
Index: ext/tk/lib/tk/grid.rb
===================================================================
RCS file: /var/cvs/src/ruby/ext/tk/lib/tk/grid.rb,v
retrieving revision 1.1.2.4
diff -u -r1.1.2.4 grid.rb
--- ext/tk/lib/tk/grid.rb	11 Oct 2004 04:51:07 -0000	1.1.2.4
+++ ext/tk/lib/tk/grid.rb	21 Dec 2004 03:07:47 -0000
@@ -42,7 +42,16 @@
       params.push("-#{k}")
       params.push((v.kind_of?(TkObject))? v.epath: v)
     }
-    tk_call_without_enc("grid", 'configure', *params)
+    if Tk::TCL_MAJOR_VERSION < 8 ||
+        (Tk::TCL_MAJOR_VERSION == 8 && Tk::TCL_MINOR_VERSION <= 3)
+      if params[0] == '-' || params[0] == 'x' || params[0] == '^'
+        tk_call_without_enc('grid', *params)
+      else
+        tk_call_without_enc('grid', 'configure', *params)
+      end
+    else
+      tk_call_without_enc('grid', 'configure', *params)
+    end
   end
   alias grid configure
 
-------------------------------------------------------------
-- 
Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)


0
nagai (573)
12/21/2004 3:26:17 AM
Reply: