resource_provider.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. 'kaboom': 'kaboom',
  21. }
  22. def __init__(self):
  23. self._icons = {}
  24. self._resource_path = Path(__file__).resolve().parent / 'resources'
  25. def get_icon(self, name):
  26. if name is None:
  27. # a NULL icon, like an icon, but without the icon
  28. return QIcon()
  29. icon = self._icons.get(name)
  30. if icon is None:
  31. icon = QIcon(str(self.get_icon_path(name)))
  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. def get_icon_path(self, name):
  38. return self.get_resource_path('icons') / f'{name}.svg'
  39. def get_resource_path(self, category):
  40. return self._resource_path / category
  41. gooey_resources = GooeyResources()