image.py 1.0 KB

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