Right, done some more poking this morning, and I believe I may have
cracked the system font issue. It's a bit of a mess, though.

The approved method of getting the system fonts seems to be to use
SystemParametersInfo to fetch SPI_GETNONCLIENTMETRICS, which returns a
struct full of various display details as defined by the user in
Display Properties - so again, this should take anyone's personal
settings/accessibility needs into account. As such, it's preferred
over GetStockObject, which only seems to get bog-standard defaults for
backwards compatibility.

http://msdn.microsoft.com/en-us/library/ff729175(v=VS.85).aspx <---
Non-Client Metrics

Note that there's not one system font in there per-se, but separate
entries for Menu Font, Caption Font, MessageBox Font, etc.

This is exposed to Python by pywin32 through the following function:

win32gui.SystemParametersInfo(int Action, obj Param,int WinIni)

We can safely ignore Param and WinIni, as they're irrelevant for this
lookup - we just need the int that relates to SPI_NONCLIENTMETRICS. A
quick grep shows it's 41, but you can just import win32con and use the
constant name. For SPI metric, it returns a Dict with keys the same as
the struct on the MSDN site.

>>> import win32gui
>>> from win32con import *
>>> dict = win32gui.SystemParametersInfo(SPI_GETNONCLIENTMETRICS)
>>> dict
{'lfSmCaptionFont': <PyLOGFONT object at 0x00B85E68>, 'iScrollWidth':
17, 'lfStatusFont': <PyLOGFONT object at 0x00AD1078>, 'lfCaptionFont':
<PyLOGFONT object at 0x00B2BFD0>, 'iMenuHeight': 19, 'iCaptionHeight':
25, 'iSmCaptionHeight': 17, 'iBorderWidth': 1, 'iCaptionWidth': 25,
'lfMessageFont': <PyLOGFONT object at 0x00B2FFB8>, 'iSmCaptionWidth':
17, 'iScrollHeight': 17, 'iMenuWidth': 18, 'lfMenuFont': <PyLOGFONT
object at 0x00B1D550>}
>>> system_font = dict['lfMenuFont']     # Default menu font is definitely 8pt 
>>> Tahoma on Win XP
>>> system_font
<PyLOGFONT object at 0x00B1D550>

I haven't the faintest how to plumb this back into PyGUI, though! I
can see the commented out remains of a Font-from-win-logfont function
in there, so I'm guessing you should be able to use the objects this
returns?

Hope this helps,

Alex

On 2 November 2010 17:41, Greg Ewing <[email protected]> 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.
>
> --
> Greg
>
_______________________________________________
Pygui mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pygui

Reply via email to