resource_provider.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. from pathlib import Path
  2. from PySide6.QtGui import QIcon
  3. class GooeyResources:
  4. # mapping of arbitrary labels to actual icon filenames
  5. label_to_name = {
  6. 'dataset': 'dataset-closed',
  7. 'directory': 'directory-closed',
  8. 'path': 'file-or-directory',
  9. 'file': 'file',
  10. 'file-annex': 'file-annex',
  11. 'file-git': 'file-git',
  12. # opportunistic guess?
  13. 'symlink': 'file-annex',
  14. 'untracked': 'untracked',
  15. 'clean': 'clean',
  16. 'modified': 'modified',
  17. 'deleted': 'untracked',
  18. 'unknown': 'untracked',
  19. 'added': 'modified',
  20. }
  21. def __init__(self):
  22. self._icons = {}
  23. self._ressource_path = Path(__file__).resolve().parent / 'resources'
  24. def get_icon(self, name):
  25. if name is None:
  26. # a NULL icon, like an icon, but without the icon
  27. return QIcon()
  28. icon = self._icons.get(name)
  29. if icon is None:
  30. icon = QIcon(str(
  31. self._ressource_path / 'icons' / f'{name}.svg'))
  32. self._icons[name] = icon
  33. return icon
  34. def get_best_icon(self, label):
  35. icon_name = GooeyResources.label_to_name.get(label)
  36. return self.get_icon(icon_name)
  37. gooey_resources = GooeyResources()