Explorar el Código

rename annotation_tool into interactive_image

Falko Schindler hace 3 años
padre
commit
45dfe5c527
Se han modificado 4 ficheros con 12 adiciones y 12 borrados
  1. 5 5
      main.py
  2. 1 1
      nicegui/elements/interactive_image.js
  3. 5 5
      nicegui/elements/interactive_image.py
  4. 1 1
      nicegui/ui.py

+ 5 - 5
main.py

@@ -130,17 +130,17 @@ with example(overlay):
             </svg>'''
             </svg>'''
         ui.svg(svg_content).style('background:transparent')
         ui.svg(svg_content).style('background:transparent')
 
 
-with example(ui.annotation_tool):
+with example(ui.interactive_image):
     from nicegui.events import MouseEventArguments
     from nicegui.events import MouseEventArguments
 
 
     def mouse_handler(e: MouseEventArguments):
     def mouse_handler(e: MouseEventArguments):
         color = 'green' if e.type == 'mousedown' else 'orange'
         color = 'green' if e.type == 'mousedown' else 'orange'
-        at.svg_content += f'<circle cx="{e.image_x}" cy="{e.image_y}" r="10" fill="{color}"/>'
+        ii.svg_content += f'<circle cx="{e.image_x}" cy="{e.image_y}" r="10" fill="{color}"/>'
         ui.notify(f'{e.type} at ({e.image_x:.1f}, {e.image_y:.1f})')
         ui.notify(f'{e.type} at ({e.image_x:.1f}, {e.image_y:.1f})')
 
 
-    at = ui.annotation_tool('http://placeimg.com/640/360/arch',
-                            on_mouse=mouse_handler,
-                            events=['mousedown', 'mouseup'], cross=True)
+    ii = ui.interactive_image('http://placeimg.com/640/360/arch',
+                              on_mouse=mouse_handler,
+                              events=['mousedown', 'mouseup'], cross=True)
 
 
 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).')

+ 1 - 1
nicegui/elements/annotation_tool.js → nicegui/elements/interactive_image.js

@@ -1,4 +1,4 @@
-Vue.component("annotation_tool", {
+Vue.component("interactive_image", {
   template: `
   template: `
     <div :id="jp_props.id" style="position:relative;display:inline-block" :style="jp_props.style" :class="jp_props.classes">
     <div :id="jp_props.id" style="position:relative;display:inline-block" :style="jp_props.style" :class="jp_props.classes">
       <img style="max-width:100%">
       <img style="max-width:100%">

+ 5 - 5
nicegui/elements/annotation_tool.py → nicegui/elements/interactive_image.py

@@ -8,17 +8,17 @@ from .element import Element
 
 
 CustomView.use(__file__)
 CustomView.use(__file__)
 
 
-class AnnotationToolView(CustomView):
+class InteractiveImageView(CustomView):
 
 
     def __init__(self, source: str, on_mouse: Callable, events: list[str], cross: bool):
     def __init__(self, source: str, on_mouse: Callable, events: list[str], cross: bool):
-        super().__init__('annotation_tool', source=source, events=events, cross=cross, svg_content='')
+        super().__init__('interactive_image', source=source, events=events, cross=cross, svg_content='')
         self.allowed_events = ['onMouse']
         self.allowed_events = ['onMouse']
         self.initialize(onMouse=on_mouse)
         self.initialize(onMouse=on_mouse)
 
 
-class AnnotationTool(Element):
+class InteractiveImage(Element):
 
 
     def __init__(self, source: str, *, on_mouse: Optional[Callable] = None, events: list[str] = ['click'], cross: bool = False):
     def __init__(self, source: str, *, on_mouse: Optional[Callable] = None, events: list[str] = ['click'], cross: bool = False):
-        """Annotation Tool
+        """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.
 
 
@@ -28,7 +28,7 @@ class AnnotationTool(Element):
         :param cross: whether to show crosshairs (default: `False`)
         :param cross: whether to show crosshairs (default: `False`)
         """
         """
         self.mouse_handler = on_mouse
         self.mouse_handler = on_mouse
-        super().__init__(AnnotationToolView(source, self.handle_mouse, events, cross))
+        super().__init__(InteractiveImageView(source, self.handle_mouse, events, cross))
 
 
     def handle_mouse(self, msg: Dict[str, Any]):
     def handle_mouse(self, msg: Dict[str, Any]):
         if self.mouse_handler is None:
         if self.mouse_handler is None:

+ 1 - 1
nicegui/ui.py

@@ -2,7 +2,6 @@ class Ui:
     from .config import config  # NOTE: before run
     from .config import config  # NOTE: before run
     from .run import run  # NOTE: before justpy
     from .run import run  # NOTE: before justpy
 
 
-    from .elements.annotation_tool import AnnotationTool as annotation_tool
     from .elements.button import Button as button
     from .elements.button import Button as button
     from .elements.chart import Chart as chart
     from .elements.chart import Chart as chart
     from .elements.checkbox import Checkbox as checkbox
     from .elements.checkbox import Checkbox as checkbox
@@ -12,6 +11,7 @@ class Ui:
     from .elements.icon import Icon as icon
     from .elements.icon import Icon as icon
     from .elements.image import Image as image
     from .elements.image import Image as image
     from .elements.input import Input as input
     from .elements.input import Input as input
+    from .elements.interactive_image import InteractiveImage as interactive_image
     from .elements.joystick import Joystick as joystick
     from .elements.joystick import Joystick as joystick
     from .elements.html import Html as html
     from .elements.html import Html as html
     from .elements.label import Label as label
     from .elements.label import Label as label