icon_pool.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # -*- coding: utf-8 -*-
  2. import pygame
  3. from pygame.locals import *
  4. from sys import exit
  5. import os
  6. import sys
  7. from util_funcs import SkinMap
  8. ##pool only store surfaces
  9. class IconPool(object):
  10. _GameShellIconPath = SkinMap("gameshell/icons/")
  11. _Icons = {}
  12. _Sizes = {}
  13. def __init__(self):
  14. self._Icons= {}
  15. def Init(self):
  16. files = os.listdir(self._GameShellIconPath)
  17. for i in files:
  18. if os.path.isfile(self._GameShellIconPath+"/"+i) and i.endswith(".png"):
  19. keyname = i.split(".")[0]
  20. self._Icons[keyname] = pygame.image.load(self._GameShellIconPath+"/"+i).convert_alpha()
  21. self._Sizes[keyname] = self._Icons[keyname].get_size()
  22. def Width(self,keyname):
  23. if keyname in self._Sizes:
  24. return self._Sizes[keyname][0]
  25. def Height(self,keyname):
  26. if keyname in self._Sizes:
  27. return self._Sizes[keyname][1]
  28. ##global Handler
  29. MyIconPool = None
  30. def InitMyIconPool():
  31. global MyIconPool
  32. if MyIconPool == None:
  33. MyIconPool = IconPool()
  34. InitMyIconPool()