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.

59 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. from functools import partial
  7. import os
  8. from gooey.gui.util.freeze import get_resource_path
  9. _image_details = (
  10. ('program_icon', 'program_icon.ico'),
  11. ('success_icon', 'success_icon.png'),
  12. ('running_icon', 'running_icon.png'),
  13. ('loading_icon', 'loading_icon.gif'),
  14. ('config_icon', 'config_icon.png'),
  15. ('error_icon', 'error_icon.png')
  16. )
  17. def init(image_dir):
  18. ''' initalize the images from the default directory path '''
  19. defaults = {variable_name: os.path.join(image_dir, filename)
  20. for variable_name, filename in _image_details}
  21. globals().update(defaults)
  22. def patch_images(new_image_dir):
  23. '''
  24. Loads custom images from the user supplied directory
  25. '''
  26. pathto = partial(os.path.join, new_image_dir)
  27. if new_image_dir != 'default':
  28. if not os.path.isdir(new_image_dir):
  29. raise IOError('Unable to find the user supplied directory {}'.format(new_image_dir))
  30. new_images = ((varname, pathto(filename))
  31. for varname, filename in _image_details
  32. if os.path.exists(pathto(filename)))
  33. # push the changes into module scope
  34. globals().update(new_images)
  35. default_dir = get_resource_path('images')
  36. init(default_dir)