[Pygui] Font Sizes on Windows XP + Standard Colour Suggestion

Alex Holland alex.holland at gmail.com
Tue Nov 2 10:02:48 CET 2010


Apologies if I'm teaching you to suck eggs here - got so excited with
my discoveries/testing that I failed to realise you're almost
certainly already handling the vagaries of Win32 Color types! Hope the
rest is useful.

Cheers,

Alex

On 2 November 2010 21:59, Alex Holland <alex.holland at gmail.com> wrote:
> Greg,
>
> On colours, I might have turned up what you need with a bit of
> Googling and experimentation.
>
> The relevant API hook is: win32api.GetSysColor(element_ref)
>
> element_ref is an integer which refers to a particular UI element -
> there's a list of elements and their values here:
> http://msdn.microsoft.com/en-us/library/ms724371(VS.85).aspx
>
> This returns a windows RGB value as an int, but it's really a 32-bit
> binary value. First 8 bits (Most Significant) are system reserved and
> set to 0*, next 8 are Blue, next 8 are Green and final 8 bits (Least
> Significant) are Red. So kind of BGR rather than RGB! As it returns as
> an int, some kind of binary padding may be needed if the values for A,
> G or B are zero.
>
> * these may be used for Alpha in newer, fancier (post XP) versions of
> Windows - not sure, MSDN is ambiguous.
>
> MSDN docs are a bit useless on this, as they want you to use built-in
> macros which aren't exposed to Python to get individual values, but
> this site has the skinny from the binary perspective:
> http://www.functionx.com/win32/Lesson12.htm
>
> Just gave this a test, pulling desktop colours - seems to work a
> charm, once you get past the weird encoding, and pulls colours direct
> from the system-wide settings in Display Properties. This means it
> should correctly grab custom colour-schemes, which is an accessibility
> win.
>
> Messy example - default Windows XP desktop background, best described
> as blueish:
>
>>>> import win32api as w
>>>> foo = w.GetSysColor(1)   # 1 for Desktop
>>>> foo
> 9981440
>>>> foo = bin(foo)
>>>> foo
> '0b100110000100111000000000'
>>>> rgbtuple = (int(foo[-8:],2), int(foo[-16:-8],2), int(foo[2:-16],2))   # (red, green, blue)
>>>> rgbtuple
> (0, 78, 152)
>
> So, Red = 0, Green = 78, Blue = 152. Plugging these values into
> mspaint gives a perfect match for the desktop.
>
> I'll do some more poking around tomorrow around fonts, but based on my
> brief research tonight, I'm not hopeful - might just need to detect
> Windows version with platform.win32_ver() and apply the appropriate
> defaults.
>
> Cheers,
>
> Alex
>
>
> On 2 November 2010 18:00, Randy Syring <rsyring at inteli-com.com> wrote:
>> Greg,
>>
>> FWIW, sounds like questions python-win32 list might be able to help you
>> with.
>>
>> --------------------------------------
>> Randy Syring
>> Intelicom
>> Direct: 502-276-0459
>> Office: 502-212-9913
>>
>> For the wages of sin is death, but the
>> free gift of God is eternal life in Christ Jesus our Lord (Rom 6:23)
>>
>>
>>
>> Greg Ewing wrote:
>>>
>>> Alex Holland wrote:
>>>
>>>> I noticed the system font on Windows XP looked too small, so had a
>>>> poke around in the sources. I see it's theoretically 8pt Tahoma, but
>>>> comparing it to renderings in WordPad, it seems to be 7pt.
>>>
>>> Fonts on Windows seem to be an endless source of mystery and
>>> confusion. My development system for Win PyGUI is currently
>>> 2000; maybe XP uses a different default font size.
>>>
>>> As you can see, I made several attempts at finding out the
>>> default font family and size, none of which seemed to work
>>> properly, and I ended up hard coding something that seemed
>>> to give the right results on my system.
>>>
>>> If anyone can tell me what the *right* way is to get the
>>> default font on Windows, I'd be glad to know!
>>>
>>>> Could I also suggest adding Windows XP's not-quite-grey to the
>>>> standard colour library? I make the RGB values (0.93, 0.91, 0.85) -
>>>> this matches the background that appears around RadioButtons on Win32.
>>>
>>> Maybe, but it's going to be different on other versions of
>>> Windows, and probably varies with the selected theme as
>>> well. Again, it would be better to ask the system, if there's
>>> a way to do that.
>>>
>> _______________________________________________
>> Pygui mailing list
>> Pygui at python.org
>> http://mail.python.org/mailman/listinfo/pygui
>>
>


More information about the Pygui mailing list