[Ruby/TK] Widget Internal Layout

M

matt

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('<ListboxSelect>') { listbox_event['<ListboxSelect>'] }
self.bind('<ListboxSelect>') {}

@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
:)
 
H

Hidetoshi NAGAI

Hi,

From: (e-mail address removed) (matt)
Subject: [Ruby/TK] Widget Internal Layout
Date: Mon, 17 May 2004 22:38:52 +0900
Message-ID: said:
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
:)

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)
 

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,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top