image.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import os
  2. from .. import constants, logger
  3. from . import base_classes, io, api
  4. class Image(base_classes.BaseNode):
  5. """Class the wraps an image node. This is the node that
  6. represent that actual file on disk.
  7. """
  8. def __init__(self, node, parent):
  9. logger.debug("Image().__init__(%s)", node)
  10. base_classes.BaseNode.__init__(self, node, parent, constants.IMAGE)
  11. self[constants.URL] = api.image.file_name(self.node)
  12. @property
  13. def destination(self):
  14. """
  15. :return: full destination path (when copied)
  16. """
  17. dirname = os.path.dirname(self.scene.filepath)
  18. return os.path.join(dirname, self[constants.URL])
  19. @property
  20. def filepath(self):
  21. """
  22. :return: source file path
  23. """
  24. return api.image.file_path(self.node)
  25. def copy_texture(self, func=io.copy):
  26. """Copy the texture.
  27. self.filepath > self.destination
  28. :param func: Optional function override (Default value = io.copy)
  29. arguments are (<source>, <destination>)
  30. :return: path the texture was copied to
  31. """
  32. logger.debug("Image().copy_texture()")
  33. func(self.filepath, self.destination)
  34. return self.destination