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.

53 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. 'loadingIcon': 'loading_icon.gif',
  15. 'configIcon': 'config_icon.png',
  16. 'errorIcon': 'error_icon.png'
  17. }
  18. def loadImages(targetDir):
  19. defaultImages = resolvePaths(getResourcePath('images'), filenames)
  20. return {'images': merge(defaultImages, collectOverrides(targetDir, filenames))}
  21. def getImageDirectory(targetDir):
  22. return getResourcePath('images') \
  23. if targetDir == 'default' \
  24. else targetDir
  25. def collectOverrides(targetDir, filenames):
  26. if targetDir == '::gooey/default':
  27. return {}
  28. pathto = partial(os.path.join, targetDir)
  29. if not os.path.isdir(targetDir):
  30. raise IOError('Unable to find the user supplied directory {}'.format(
  31. targetDir))
  32. return {varname: pathto(filename)
  33. for varname, filename in filenames.items()
  34. if os.path.exists(pathto(filename))}
  35. def resolvePaths(dirname, filenames):
  36. return {key: os.path.join(dirname, filename)
  37. for key, filename in filenames.items()}