[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] How the get a font size
I'm also sure that "not working" is hardly a serious issue. =P
-Thiago
On Tue, Jan 13, 2009 at 2:04 AM, James Paige <Bob@xxxxxxxxxxxxxxxxxxx> wrote:
> The only bad thing I can say about it is that it simply doesn't work :(
>
>>>> f = pygame.font.Font(None, 12)
>>>> f.size = 12
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> AttributeError: 'pygame.font.Font' object attribute 'size' is read-only
>
> And that is not just because Font already has a method named .size()
>
>>>> f.pointsize = 12
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> AttributeError: 'pygame.font.Font' object has no attribute 'pointsize'
>
> I'm guessing that since pygame.font.Font is impelmented in C, it doesn't
> allow new members to be added as it would if it was implemented in
> python (Correct me if I am wrong)
>
> ---
> James Paige
>
> On Tue, Jan 13, 2009 at 01:54:30AM +0200, Thiago Chaves wrote:
>> You can also just violate the object by giving it an extra attribute:
>>
>> f = pygame.font.Font(filename, size)
>> f.new_attribute = size
>>
>> I'm pretty sure any OO enthusiast would applaud this method. There is
>> certainly nothing bad that can be said about my method. No sir. =D
>>
>> -Thiago
>>
>> On Tue, Jan 13, 2009 at 12:48 AM, James Paige <Bob@xxxxxxxxxxxxxxxxxxx> wrote:
>> > Seems to me like this should work:
>> >
>> > class SizeFont(pygame.font.Font):
>> >
>> > def __init__(self, filename, size):
>> > pygame.font.Font.__init__(self, filename, size)
>> > self.size = size
>> >
>> > ---
>> > James Paige
>> >
>> > On Mon, Jan 12, 2009 at 04:07:11PM -0600, Jake b wrote:
>> >> Create a basic Font() wrapper. When you create the font, save the size.
>> >> On Mon, Jan 12, 2009 at 2:02 AM, Luca <lucafbb@xxxxxxxxx> wrote:
>> >>
>> >> On Sun, Jan 11, 2009 at 10:36 PM, Noah Kantrowitz <noah@xxxxxxxxxxxxxx>
>> >> wrote:
>> >>
>> >> >> As far as I know, there's no way to get the size of the font that
>> >> way.
>> >> >> What I do is name the font names in an intuitive way:
>> >> >> Font12 = pygame.font.Font("....", 12)
>> >> >> Font18 = pygame.font.Font("....", 18)
>> >> >> Font36 = pygame.font.Font("....", 36)
>> >>
>> >> Thanks all, but in this way is impossible to get the size on an unknow
>> >> font? I'm making a library for developer that need to know what is the
>> >> font size that the developer can have choosen...
>> >>
>> >> --
>> >> -- luca
>> >>
>> >> --
>> >> Jake
>> >
>>
>>
>