You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.4 KiB

  1. '''
  2. Collection of the image paths.
  3. The module is meant to act as a singleton, hence the globals() abuse.
  4. Image credit: kidcomic.net
  5. '''
  6. import os
  7. from functools import partial
  8. from gooey.gui.util.freeze import getResourcePath
  9. from gooey.util.functional import merge
  10. filenames = {
  11. 'programIcon': 'program_icon.png',
  12. 'successIcon': 'success_icon.png',
  13. 'runningIcon': 'running_icon.png',
  14. 'configIcon': 'config_icon.png',
  15. 'errorIcon': 'error_icon.png'
  16. }
  17. def loadImages(targetDir):
  18. defaultImages = resolvePaths(getResourcePath('images'), filenames)
  19. return {'images': merge(defaultImages, collectOverrides(targetDir, filenames))}
  20. def getImageDirectory(targetDir):
  21. return getResourcePath('images') \
  22. if targetDir == 'default' \
  23. else targetDir
  24. def collectOverrides(targetDir, filenames):
  25. if targetDir == '::gooey/default':
  26. return {}
  27. pathto = partial(os.path.join, targetDir)
  28. if not os.path.isdir(targetDir):
  29. raise IOError('Unable to find the user supplied directory {}'.format(
  30. targetDir))
  31. return {varname: pathto(filename)
  32. for varname, filename in filenames.items()
  33. if os.path.exists(pathto(filename))}
  34. def resolvePaths(dirname, filenames):
  35. return {key: os.path.join(dirname, filename)
  36. for key, filename in filenames.items()}