[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Problems loading fonts on Windows
If you want to have a quick fix.
Get ctypes (from python starship) and use the following function
_specialdirs={'windows': 0x24,'my documents': 0x5 }
def GetSpecialDirectoryPath(dirname):
   from ctypes import oledll,cast,c_buffer,c_wchar_p
   shell32dll=oledll.shell32
   MAX_PATH=256
   location=cast(c_buffer(MAX_PATH*2),c_wchar_p)
   CSIDL_WINDOWS=0x24
   SHGFP_TYPE_CURRENT=0
   
shell32dll.SHGetFolderPathW(0,_specialdirs[dirname.lower()],0,SHGFP_TYPE_CURRENT,location)
   if not location:
       raise Exception("special dir %s was not found"%dirname)
   return unicode(location.value)
that you will call at the init of your game with
if sys.platform == 'win32' and not os.environ.has_key('WINDIR'):
	os.environ['WINDIR']=GetSpecialDirectoryPath("Windows")
	
Regards,
Guillaume
Will Newton wrote:
Hi, I'm deploying a cross platform pygame script. On windows I have had a 
report of an error thrown loading fonts because WINDIR is not defined in the 
env. Has anyone else seen this?
self.default_font = pygame.font.SysFont("courier", 12, False, False)
File "C:\Python23\Lib\site-packages\pygame\sysfont.py", line 230, in SysFont
initsysfonts()
File "C:\Python23\Lib\site-packages\pygame\sysfont.py", line 195, in 
initsysfonts
fonts = initsysfonts_win32()
File "C:\Python23\Lib\site-packages\pygame\sysfont.py", line 48, in 
initsysfonts_win32
fontdir = os.path.join(os.environ['WINDIR'], "Fonts")
File "C:\Python23\lib\os.py", line 417, in __getitem__
return self.data[key.upper()]
KeyError: 'WINDIR'