Falko Schindler 2 anos atrás
pai
commit
38d813b82c

+ 2 - 2
README.md

@@ -41,7 +41,7 @@ NiceGUI is available as [PyPI package](https://pypi.org/project/nicegui/), [Dock
 - notifications, dialogs and menus to provide state of the art user interaction
 - notifications, dialogs and menus to provide state of the art user interaction
 - shared and individual web pages
 - shared and individual web pages
 - ability to add custom routes and data responses
 - ability to add custom routes and data responses
-- capture keyboard input for global shortcuts etc
+- capture keyboard input for global shortcuts etc.
 - customize look by defining primary, secondary and accent colors
 - customize look by defining primary, secondary and accent colors
 - live-cycle events and session data
 - live-cycle events and session data
 
 
@@ -82,7 +82,7 @@ You may also have a look at [our in-depth demonstrations](https://github.com/zau
 
 
 ## Why?
 ## Why?
 
 
-We, at [Zauberzeug](https://zauberzeug.com), like [Streamlit](https://streamlit.io/)
+We at [Zauberzeug](https://zauberzeug.com) like [Streamlit](https://streamlit.io/)
 but find it does [too much magic](https://github.com/zauberzeug/nicegui/issues/1#issuecomment-847413651) when it comes to state handling.
 but find it does [too much magic](https://github.com/zauberzeug/nicegui/issues/1#issuecomment-847413651) when it comes to state handling.
 In search for an alternative nice library to write simple graphical user interfaces in Python we discovered [JustPy](https://justpy.io/).
 In search for an alternative nice library to write simple graphical user interfaces in Python we discovered [JustPy](https://justpy.io/).
 Although we liked the approach, it is too "low-level HTML" for our daily usage.
 Although we liked the approach, it is too "low-level HTML" for our daily usage.

+ 3 - 3
examples/opencv_webcam/main.py

@@ -11,13 +11,13 @@ from nicegui import app, ui
 black_1px = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAA1JREFUGFdjYGBg+A8AAQQBAHAgZQsAAAAASUVORK5CYII='
 black_1px = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAA1JREFUGFdjYGBg+A8AAQQBAHAgZQsAAAAASUVORK5CYII='
 placeholder = Response(content=base64.b64decode(black_1px.encode('ascii')), media_type='image/png')
 placeholder = Response(content=base64.b64decode(black_1px.encode('ascii')), media_type='image/png')
 
 
-# openCV is used to accesss the webcam
+# OpenCV is used to access the webcam
 video_capture = cv2.VideoCapture(0)
 video_capture = cv2.VideoCapture(0)
 
 
 
 
 @app.get('/video/frame')
 @app.get('/video/frame')
 async def grab_video_frame() -> Response:
 async def grab_video_frame() -> Response:
-    # thanks to FastAPI it's easy to create a web route which always provides the latest image from openCV
+    # thanks to FastAPI it is easy to create a web route which always provides the latest image from OpenCV
     if not video_capture.isOpened():
     if not video_capture.isOpened():
         return placeholder
         return placeholder
     ret, frame = video_capture.read()
     ret, frame = video_capture.read()
@@ -27,7 +27,7 @@ async def grab_video_frame() -> Response:
     jpeg = imencode_image.tobytes()
     jpeg = imencode_image.tobytes()
     return Response(content=jpeg, media_type='image/jpeg')
     return Response(content=jpeg, media_type='image/jpeg')
 
 
-# For non-flickering image updates an interactive image is much better than ui.image()
+# For non-flickering image updates an interactive image is much better than ui.image().
 video_image = ui.interactive_image().classes('w-full h-full')
 video_image = ui.interactive_image().classes('w-full h-full')
 # A timer constantly updates the source of the image.
 # A timer constantly updates the source of the image.
 # But because the path is always the same, we must force an update by adding the current timestamp to the source.
 # But because the path is always the same, we must force an update by adding the current timestamp to the source.

+ 5 - 4
nicegui/elements/interactive_image.py

@@ -13,22 +13,23 @@ register_component('interactive_image', __file__, 'interactive_image.js')
 class InteractiveImage(SourceElement, ContentElement):
 class InteractiveImage(SourceElement, ContentElement):
 
 
     def __init__(self, source: str = '', *,
     def __init__(self, source: str = '', *,
+                 content: str = '',
                  on_mouse: Optional[Callable] = None, events: List[str] = ['click'], cross: bool = False) -> None:
                  on_mouse: Optional[Callable] = None, events: List[str] = ['click'], cross: bool = False) -> None:
         """Interactive Image
         """Interactive Image
 
 
         Create an image with an SVG overlay that handles mouse events and yields image coordinates.
         Create an image with an SVG overlay that handles mouse events and yields image coordinates.
-        It's also the best choice for non-flickering image updates.
-        If the url changes of source faster than images can be loaded by the browser, some images are simply skipped.
+        It is also the best choice for non-flickering image updates.
+        If the source URL changes faster than images can be loaded by the browser, some images are simply skipped.
         Thereby a stream of images automatically adapts to the available bandwidth.
         Thereby a stream of images automatically adapts to the available bandwidth.
         See `OpenCV Webcam <https://github.com/zauberzeug/nicegui/tree/main/examples/opencv_webcam/main.py>`_ for an example.
         See `OpenCV Webcam <https://github.com/zauberzeug/nicegui/tree/main/examples/opencv_webcam/main.py>`_ for an example.
 
 
         :param source: the source of the image; can be an URL or a base64 string
         :param source: the source of the image; can be an URL or a base64 string
-        :param content: svg content which should be overlayed; viewport has the same dimensions as the image
+        :param content: SVG content which should be overlayed; viewport has the same dimensions as the image
         :param on_mouse: callback for mouse events (yields `type`, `image_x` and `image_y`)
         :param on_mouse: callback for mouse events (yields `type`, `image_x` and `image_y`)
         :param events: list of JavaScript events to subscribe to (default: `['click']`)
         :param events: list of JavaScript events to subscribe to (default: `['click']`)
         :param cross: whether to show crosshairs (default: `False`)
         :param cross: whether to show crosshairs (default: `False`)
         """
         """
-        super().__init__(tag='interactive_image', source=source, content='')
+        super().__init__(tag='interactive_image', source=source, content=content)
         self._props['events'] = events
         self._props['events'] = events
         self._props['cross'] = cross
         self._props['cross'] = cross
 
 

+ 0 - 1
nicegui/elements/mixins/content_element.py

@@ -26,7 +26,6 @@ class ContentElement(Element):
         return self
         return self
 
 
     def set_content(self, content: str) -> None:
     def set_content(self, content: str) -> None:
-        '''changes the content'''
         self.content = content
         self.content = content
 
 
     def on_content_change(self, content: str) -> None:
     def on_content_change(self, content: str) -> None:

+ 0 - 1
nicegui/elements/mixins/source_element.py

@@ -26,7 +26,6 @@ class SourceElement(Element):
         return self
         return self
 
 
     def set_source(self, source: str) -> None:
     def set_source(self, source: str) -> None:
-        '''changes the image source'''
         self.source = source
         self.source = source
 
 
     def on_source_change(self, source: str) -> None:
     def on_source_change(self, source: str) -> None: