image.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import justpy as jp
  2. from ..binding import bind_from, bind_to, BindableProperty
  3. from .group import Group
  4. class Image(Group):
  5. source = BindableProperty
  6. def __init__(self,
  7. source: str = '',
  8. ):
  9. """Image Element
  10. Displays an image.
  11. :param source: the source of the image; can be an url or a base64 string
  12. """
  13. view = jp.QImg(src=source)
  14. super().__init__(view)
  15. self.source = source
  16. self.bind_source_to(self.view, 'src')
  17. def set_source(self, source: str):
  18. self.source = source
  19. def bind_source_to(self, target_object, target_name, forward=lambda x: x):
  20. bind_to(self, 'source', target_object, target_name, forward=forward)
  21. return self
  22. def bind_source_from(self, target_object, target_name, backward=lambda x: x):
  23. bind_from(self, 'source', target_object, target_name, backward=backward)
  24. return self
  25. def bind_source(self, target_object, target_name, forward=lambda x: x, backward=lambda x: x):
  26. bind_from(self, 'source', target_object, target_name, backward=backward)
  27. bind_to(self, 'source', target_object, target_name, forward=forward)
  28. return self