소스 검색

update ui.image

Falko Schindler 2 년 전
부모
커밋
9f80271fad
5개의 변경된 파일31개의 추가작업 그리고 26개의 파일을 삭제
  1. 7 0
      nicegui/binding.py
  2. 20 0
      nicegui/elements/image.py
  3. 0 24
      nicegui/elements/old/image.py
  4. 3 2
      nicegui/elements/text_element.py
  5. 1 0
      nicegui/ui.py

+ 7 - 0
nicegui/binding.py

@@ -173,6 +173,7 @@ class BindSourceMixin:
     """
     """
     Mixin providing bind methods for attribute source.
     Mixin providing bind methods for attribute source.
     """
     """
+    source = BindableProperty(on_change=lambda sender, source: sender.on_source_change(source))
 
 
     def bind_source_to(self, target_object: Any, target_name: str, forward: Callable = lambda x: x):
     def bind_source_to(self, target_object: Any, target_name: str, forward: Callable = lambda x: x):
         bind_to(self, 'source', target_object, target_name, forward)
         bind_to(self, 'source', target_object, target_name, forward)
@@ -186,3 +187,9 @@ class BindSourceMixin:
                     forward: Callable = lambda x: x, backward: Callable = lambda x: x):
                     forward: Callable = lambda x: x, backward: Callable = lambda x: x):
         bind(self, 'source', target_object, target_name, forward=forward, backward=backward)
         bind(self, 'source', target_object, target_name, forward=forward, backward=backward)
         return self
         return self
+
+    def set_source(self, source: str) -> None:
+        self.source = source
+
+    def on_source_change(self, source: str) -> None:
+        pass

+ 20 - 0
nicegui/elements/image.py

@@ -0,0 +1,20 @@
+from ..binding import BindSourceMixin
+from ..element import Element
+
+
+class Image(Element, BindSourceMixin):
+
+    def __init__(self, source: str = '') -> None:
+        """Image
+
+        Displays an image.
+
+        :param source: the source of the image; can be a URL or a base64 string
+        """
+        super().__init__('q-img')
+        self.source = source
+        self._props['src'] = source
+
+    def on_source_change(self, source: str) -> None:
+        self._props['src'] = source
+        self.update()

+ 0 - 24
nicegui/elements/old/image.py

@@ -1,24 +0,0 @@
-import justpy as jp
-
-from ..binding import BindableProperty, BindSourceMixin
-from .group import Group
-
-
-class Image(Group, BindSourceMixin):
-    source = BindableProperty()
-
-    def __init__(self, source: str = ''):
-        """Image
-
-        Displays an image.
-
-        :param source: the source of the image; can be an URL or a base64 string
-        """
-        view = jp.QImg(src=source, temp=False)
-        super().__init__(view)
-
-        self.source = source
-        self.bind_source_to(self.view, 'src')
-
-    def set_source(self, source: str):
-        self.source = source

+ 3 - 2
nicegui/elements/text_element.py

@@ -8,7 +8,8 @@ class TextElement(Element, BindTextMixin):
     def __init__(self, tag: str, text: str) -> None:
     def __init__(self, tag: str, text: str) -> None:
         super().__init__(tag)
         super().__init__(tag)
         self.text = text
         self.text = text
-        self.bind_text_to(self, '_text')
+        self._text = text
 
 
-    def on_text_change(self, _) -> None:
+    def on_text_change(self, text: str) -> None:
+        self._text = text
         self.update()
         self.update()

+ 1 - 0
nicegui/ui.py

@@ -5,6 +5,7 @@ from .elements.card import CardActions as card_actions
 from .elements.card import CardSection as card_section
 from .elements.card import CardSection as card_section
 from .elements.column import Column as column
 from .elements.column import Column as column
 from .elements.icon import Icon as icon
 from .elements.icon import Icon as icon
+from .elements.image import Image as image
 from .elements.label import Label as label
 from .elements.label import Label as label
 from .elements.row import Row as row
 from .elements.row import Row as row
 from .elements.separator import Separator as separator
 from .elements.separator import Separator as separator