image.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. texture_folder = self.scene.options.get(constants.TEXTURE_FOLDER, "")
  12. self[constants.URL] = os.path.join(texture_folder, api.image.file_name(self.node))
  13. @property
  14. def destination(self):
  15. """
  16. :return: full destination path (when copied)
  17. """
  18. dirname = os.path.dirname(self.scene.filepath)
  19. return os.path.join(dirname, self[constants.URL])
  20. @property
  21. def filepath(self):
  22. """
  23. :return: source file path
  24. """
  25. return api.image.file_path(self.node)
  26. def copy_texture(self, func=io.copy):
  27. """Copy the texture.
  28. self.filepath > self.destination
  29. :param func: Optional function override (Default value = io.copy)
  30. arguments are (<source>, <destination>)
  31. :return: path the texture was copied to
  32. """
  33. logger.debug("Image().copy_texture()")
  34. func(self.filepath, self.destination)
  35. return self.destination