瀏覽代碼

allow changing image source of annotation tool

Falko Schindler 3 年之前
父節點
當前提交
19c26af66b
共有 2 個文件被更改,包括 12 次插入0 次删除
  1. 6 0
      nicegui/elements/annotation_tool.js
  2. 6 0
      nicegui/elements/annotation_tool.py

+ 6 - 0
nicegui/elements/annotation_tool.js

@@ -12,6 +12,7 @@ Vue.component("annotation_tool", {
     </div>
   `,
   mounted() {
+    comp_dict[this.$props.jp_props.id] = this;
     const image = document.getElementById(this.$props.jp_props.id).firstChild;
     const svg = document.getElementById(this.$props.jp_props.id).lastChild;
     const cross = svg.firstChild;
@@ -54,6 +55,11 @@ Vue.component("annotation_tool", {
       });
     }
   },
+  methods: {
+    set_source(source) {
+      document.getElementById(this.$props.jp_props.id).firstChild.src = source;
+    },
+  },
   props: {
     jp_props: Object,
   },

+ 6 - 0
nicegui/elements/annotation_tool.py

@@ -1,4 +1,5 @@
 from __future__ import annotations
+from justpy import WebPage
 from typing import Any, Callable, Dict, Optional
 import traceback
 from ..events import MouseEventArguments, handle_event
@@ -44,6 +45,11 @@ class AnnotationTool(Element):
         except:
             traceback.print_exc()
 
+    async def set_source(self, source: str):
+        self.view.options.source = source
+        for socket in WebPage.sockets.get(self.page.page_id, {}).values():
+            await self.view.run_method(f'set_source("{source}")', socket)
+
     @property
     def svg_content(self) -> str:
         return self.view.options.svg_content