Incorrect return of the TkFont configure instance method when no value

Hello,

I already posted this question to the ruby-core mailing-list, but as I received no answer, I suppose that it was not the right place :slight_smile:

I would like to get the size of a TkFont.
It could be done with something like ...

require 'tk'
font = TkFont.new...
...
size = font.configure :size

... as it is descibed in the Tk documentation (configure with an attribute without a value get the value of this attribute).

Unfortunately, this code returns the font object instead of the size attribute.
It is confirmed in the configure_core_tk8x method in ext/tk/lib/tk/font.rb file (line 1328) :

def configure_core_tk8x(font, slot, value=None)
...
self
end

So my question : is it a bug or there is another (specific ruby) way to get the font attributes ?

Thanks and regards,
Lionel Maiaux

Try

聽聽聽聽聽聽require 'tk'
聽聽聽聽聽聽font = TkFont.new
聽聽聽聽聽聽size = font.size #=> 12 (on my system)

Regards, Morton

路路路

On Aug 31, 2006, at 4:09 AM, Lionel MAIAUX wrote:

Hello,

I already posted this question to the ruby-core mailing-list, but as I received no answer, I suppose that it was not the right place :slight_smile:

I would like to get the size of a TkFont.
It could be done with something like ...

require 'tk'
font = TkFont.new...
...
size = font.configure :size

... as it is descibed in the Tk documentation (configure with an attribute without a value get the value of this attribute).

Unfortunately, this code returns the font object instead of the size attribute.
It is confirmed in the configure_core_tk8x method in ext/tk/lib/tk/font.rb file (line 1328) :

def configure_core_tk8x(font, slot, value=None)
...
self
end

So my question : is it a bug or there is another (specific ruby) way to get the font attributes ?

Message-ID: <44F6990D.1010002@st.com>

I would like to get the size of a TkFont.
It could be done with something like ...

require 'tk'
font = TkFont.new...
...
size = font.configure :size

... as it is descibed in the Tk documentation (configure with an
attribute without a value get the value of this attribute).

On Ruby/Tk, you can use 'configure' methods only to set attibutes.
When you want the attibute value of the font,
please use one of the followings.

聽聽font.configinfo(:size) or font.configinfo('size')
聽聽font[:size] or font['size']
聽聽font.size

And when you want to set a value,

聽聽font.configure(:size, value) or font.configure('size', value) # pair
聽聽font.configure(:size=>value) or font.configure('size'=>value) # Hash
聽聽font[:size] = value or font['size'] = value
聽聽font.size(value) or font.size = value

So, for example, you can control the buttons' font size
by something like as the following. :wink:

聽聽b1 = TkButton.new(:text=>'FOO').pack
聽聽f = b1.font
聽聽b2 = TkButton.new(:text=>'BAR', :font=>f).pack
聽聽lbl = TkButton.new(:text=>'Label', :font=>f).pack
聽聽p f.size # e.g. fontsize == 9
聽聽f.size -= 3 # fontsize == 6 on the label and both buttons
聽聽f.size *= 2 # fontsize == 12 on the label and both buttons

路路路

From: Lionel MAIAUX <lionel.maiaux@st.com>
Subject: Incorrect return of the TkFont configure instance method when no value
Date: Thu, 31 Aug 2006 17:09:14 +0900

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