[Ruby/TK] Widget Internal Layout

Given the following code:

···

require ‘ext/tkscrollinglistbox’

root = TkRoot.new
text = TkEntry.new(root, ‘width’=>100)
list = TkScrollingListbox.new(root, ‘width’=>50, ‘label’=>‘Meow’)

list.instance_eval { @frame.configure(‘background’=>‘blue’) }
root.configure(‘background’=>‘yellow’)

text.pack(‘side’=>‘top’, ‘fill’=>‘x’, ‘expand’=>true)
list.pack(‘side’=>‘top’, ‘fill’=>‘both’, ‘expand’=>true)

Tk.mainloop

and ext/tkscrollinglistbox being (method_configure basically calls a
method with a given value when used in TkComposite.configure - the
version in CVS has something like this, I just haven’t updated…)


require ‘tk’

class TkScrollingListbox < TkWindow
include TkComposite

def initialize_composite(keys={})
keys = _symbolkey2str(keys)

@label   = TkLabel.new(@frame)
@list    = TkListbox.new(@frame)
@x       = TkScrollbar.new(@frame)
@y       = TkScrollbar.new(@frame)

delegate('DEFAULT', @list)
@path    = @list.path

method_configure(:scrollbars, :label, :labelspot)

@list.yscrollbar(@y)
@list.xscrollbar(@x)

@list.grid('row'=>1, 'column'=>0, 'sticky'=>'nsew')

listbox_event = Proc.new {|e| $stderr.puts "HERE!";

self.event_generate(e)}
@list.bind(’’) { listbox_event[’’] }
self.bind(’’) {}

@lblWhere  = 'top'
@lblPlaced = false

configure keys unless keys.empty?

end

def scrollbars(scroll)
case scroll.to_s.downcase
when ‘both’ then @x.grid(‘row’=>2, ‘column’=>0, ‘sticky’=>‘ew’)
@y.grid(‘row’=>1, ‘column’=>1, ‘sticky’=>‘ns’)
when ‘x’ then @x.grid(‘row’=>2, ‘column’=>0, ‘sticky’=>‘ew’)
@y.ungrid
when ‘y’ then @y.grid(‘row’=>1, ‘column’=>1, ‘sticky’=>‘ns’)
@x.ungrid
when ‘none’ then @x.ungrid
@y.ungrid
end
end

def label(text)
if text.nil? then
@lblPlaced = false
@label.ungrid
else
@label.text text
@lblPlaced = true
@label.grid(‘row’=>(@lblWhere == ‘top’ ? 0 : 3), ‘column’=>0,
‘columnspan’=>2)
end
end

def labelspot(value)
unless value.nil? then
@lblWhere = value
label(@label.text) if @lblPlaced
end
@lblWhere
end

def method_missing(sym, *args)
if @list.respond_to?(sym) then
@list.send(sym, *args)
else
super(sym, *args)
end
end

alias old_respond_to respond_to?
def respond_to?(sym)
return true if old_respond_to(sym)
return true if @list.respond_to?(sym)
return false
end

end

My question is why doesn’t the listbox in the TkScrollingListbox
expand and fill the frame when the frame gets more space – I made it
sticky(news)… do I have a misunderstanding of the grid layout
manager? Is the world completely topsy turvy? Please help! Thanks
:slight_smile:

Hi,

···

From: mhm26@drexel.edu (matt)
Subject: [Ruby/TK] Widget Internal Layout
Date: Mon, 17 May 2004 22:38:52 +0900
Message-ID: 13383d7a.0405170535.3faea337@posting.google.com

My question is why doesn’t the listbox in the TkScrollingListbox
expand and fill the frame when the frame gets more space – I made it
sticky(news)… do I have a misunderstanding of the grid layout
manager? Is the world completely topsy turvy? Please help! Thanks
:slight_smile:

You’ll forget to configure ‘weight’ option for ‘grid’ geometry manager.
Please see the example ‘ext/tk/sample/tktextframe.rb’.

@list.yscrollbar(@y)
@list.xscrollbar(@x)
  TkGrid.rowconfigure(@frame, 1, 'weight'=>1, 'minsize'=>0)
  TkGrid.columnconfigure(@frame, 0, 'weight'=>1, 'minsize'=>0)
@list.grid('row'=>1, 'column'=>0, 'sticky'=>'nsew')

And I think you should set ‘expand’ option for packing the entry
widget to false.

list.instance_eval { @frame.configure(‘background’=>‘blue’) }
root.configure(‘background’=>‘yellow’)

text.pack(‘side’=>‘top’, ‘fill’=>‘x’, ‘expand’=>true)
^^^^
false
list.pack(‘side’=>‘top’, ‘fill’=>‘both’, ‘expand’=>true)

Tk.mainloop



Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)