فهرست منبع

introducing image element

Rodja Trappe 3 سال پیش
والد
کامیت
47b33612b4
3فایلهای تغییر یافته به همراه51 افزوده شده و 0 حذف شده
  1. 3 0
      main.py
  2. 47 0
      nicegui/elements/image.py
  3. 1 0
      nicegui/ui.py

+ 3 - 0
main.py

@@ -141,6 +141,9 @@ with example(ui.label):
 
 
     ui.label('some label')
     ui.label('some label')
 
 
+with example(ui.image):
+    ui.image('http://placeimg.com/640/360/tech')
+
 with example(ui.markdown):
 with example(ui.markdown):
 
 
     ui.markdown('### Headline\nWith hyperlink to [GitHub](https://github.com/zauberzeug/nicegui).')
     ui.markdown('### Headline\nWith hyperlink to [GitHub](https://github.com/zauberzeug/nicegui).')

+ 47 - 0
nicegui/elements/image.py

@@ -0,0 +1,47 @@
+import justpy as jp
+from .element import Element
+
+class Image(Element):
+
+    def __init__(self,
+                 source: str = '',
+                 ):
+        """Image Element
+
+        Displays an image.
+
+        :param source: the source of the image (can be an url or byte array)
+        """
+
+        view = jp.Img(src=source)
+
+        super().__init__(view)
+
+    @property
+    def src(self):
+
+        return self.view.src
+
+    @src.setter
+    def source(self, source: any):
+
+        self.view.src = source
+
+    def set_source(self, source: str):
+
+        self.source = source
+
+    def bind_source_to(self, target, forward=lambda x: x):
+
+        self.source.bind_to(target, forward=forward, nesting=1)
+        return self
+
+    def bind_source_from(self, target, backward=lambda x: x):
+
+        self.source.bind_from(target, backward=backward, nesting=1)
+        return self
+
+    def bind_source(self, target, forward=lambda x: x, backward=lambda x: x):
+
+        self.source.bind(target, forward=forward, backward=backward, nesting=1)
+        return self

+ 1 - 0
nicegui/ui.py

@@ -10,6 +10,7 @@ class Ui:
     from .elements.input import Input as input
     from .elements.input import Input as input
     from .elements.joystick import Joystick as joystick
     from .elements.joystick import Joystick as joystick
     from .elements.label import Label as label
     from .elements.label import Label as label
+    from .elements.image import Image as image
     from .elements.html import Html as html
     from .elements.html import Html as html
     from .elements.markdown import Markdown as markdown
     from .elements.markdown import Markdown as markdown
     from .elements.link import Link as link
     from .elements.link import Link as link