resource_provider.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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._resource_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(self.get_icon_path(name)))
  31. self._icons[name] = icon
  32. return icon
  33. def get_best_icon(self, label):
  34. icon_name = GooeyResources.label_to_name.get(label)
  35. return self.get_icon(icon_name)
  36. def get_icon_path(self, name):
  37. return self.get_resource_path('icons') / f'{name}.svg'
  38. def get_resource_path(self, category):
  39. return self._resource_path / category
  40. gooey_resources = GooeyResources()