Question about 'configure' with tk

hello,
I am working on the way to let user choose options of the GUI.
The manual of Tk says that when ‘configure’ is called on a widget
without parameters, you get the full list of options-values pair (it
works under tcl). Under Ruby, it is not possible. I would like to know
if it is a Ruby limitation or if it is possible to add this feature.
(wich would be great I think)

thx by advance,
jf

···


/ do you play Go? \

http://jeanfrancois.menon.free.fr/rubygo |
\ /


    \   ^__^
     \  (oo)\_______
        (__)\       )\/\
            >>----w |
            >>     >>

works under tcl). Under Ruby, it is not possible. I would like to know
if it is a Ruby limitation or if it is possible to add this feature.

Try this

pigeon% ruby -rtk -e 'a = TkButton.new(nil, "text" => "a"); p a.configure({})'
"{-activebackground activeBackground Foreground #ececec #ececec} {-activeforeground activeForeground Background Black Black} {-anchor anchor Anchor center center} {-background background Background #d9d9d9 #FF00FE00FE00} {-bd -borderwidth} {-bg -background} {-bitmap bitmap Bitmap {} {}} {-borderwidth borderWidth BorderWidth 2 2} {-command command Command {} {}} {-cursor cursor Cursor {} {}} {-default default Default disabled disabled} {-disabledforeground disabledForeground DisabledForeground #a3a3a3 #a3a3a3} {-fg -foreground} {-font font Font {Helvetica -12 bold} {-dt-interface user-medium-r-normal-s*-*-*-*-*-*-*-*-*}} {-foreground foreground Foreground Black #000000000000} {-height height Height 0 0} {-highlightbackground highlightBackground HighlightBackground #d9d9d9 #d9d9d9} {-highlightcolor highlightColor HighlightColor Black Black} {-highlightthickness highlightThickness HighlightThickness 1 1} {-image image Image {} {}} {-justify justify Justify center center} {-padx!

padX Pad 3m 3m} {-pady padY Pad 1m 1m} {-relief relief Relief raised raised} {-state state State normal normal} {-takefocus takeFocus TakeFocus {} {}} {-text text Text {} a} {-textvariable textVariable Variable {} {}} {-underline underline Underline -1 -1} {-width width Width 0 0} {-wraplength wrapLength WrapLength 0 0}"
pigeon%

Guy Decoux

Hi,

Still my eye’s status is not so good.

But I’m back momentary, because no one describes proper explanation. :slight_smile:

···

From: ts decoux@moulon.inra.fr
Subject: Re: question about ‘configure’ with tk
Date: Fri, 30 Aug 2002 20:14:44 +0900
Message-ID: 200208301109.g7UB90p22031@moulon.inra.fr

works under tcl). Under Ruby, it is not possible. I would like to know
if it is a Ruby limitation or if it is possible to add this feature.
Try this
pigeon% ruby -rtk -e ‘a = TkButton.new(nil, “text” => “a”); p a.configure({})’

Use ‘configinfo’ method.
On Ruby/Tk, ‘configure’ method is the method for setting properties,
and ‘configinfo’ method for getting.
the followings are the way of getting configure informations.

(1) widget.property
(2) widget[‘property’]
(3) widget.cget(‘property’)
(4) widget.configinfo(‘property’)
(5) widget.configinfo

From (1) to (3) return current value of the property.
(4) returns an array [property, resource-name, resource-class,
default-value, current-value], and (5) returns an array of all properties.
For example,

b = TkButton.new
p b.padx #==> 12
p b[‘padx’] #==> 12
p b.cget(‘padx’) #==> 12
p b.configinfo(‘padx’)
#==> [“padx”, “padX”, “Pad”, “3m”, 12]
p b.cinfiginfo
#==> [[“activebackground”, “activeBackground”, “Foreground”, “#ececec”,
"#ececec"], [“activeforeground”, “activeForeground”, “Background”,
“Black”, “Black”], [“anchor”, “anchor”, “Anchor”, “center”,
“center”], [“background”, “background”, “Background”, “#d9d9d9”,
"#d9d9d9"], [“bd”, “borderWidth”], [“bg”, “background”], [“bitmap”,
“bitmap”, “Bitmap”, [], []], [“borderwidth”, “borderWidth”,
“BorderWidth”, 2, 2], [“command”, “command”, “Command”, [], []],
… (snip)

A known problem of configinfo method is that
it cannot distinguish a string and a value.
Tcl/Tk expresses a string with spaces and an array of strings
as a same string. It cannot be distinguished by Ruby.
Therefore, on the result of configinfo,
a null string is converted to a null array.

By the way, the followings are the way for setting properties.

(1) widget.property(value)
(2) widget[‘property’] = value
(3) widget.configure(‘property’, value)
(4) widget.configure(‘property’=>value, ‘property’=>value, …)

Each method calls Tcl interpreter once.
So, if you want to set some properties for one widget,
(4) is faster than others.

If there is a book such as O’REILLY’s “Perl/Tk Pocket Reference”,

how many people will want it ?


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