Skip to content

Commit

Permalink
make ui.interactive_image.source bindable
Browse files Browse the repository at this point in the history
  • Loading branch information
falkoschindler committed Oct 11, 2022
1 parent bdc8ec1 commit 63cdab8
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions nicegui/elements/interactive_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from justpy import WebPage

from ..binding import BindableProperty, BindSourceMixin
from ..events import MouseEventArguments, handle_event
from ..routes import add_dependencies
from .custom_view import CustomView
Expand All @@ -30,9 +31,15 @@ def prune_sockets(self):
self.sockets = [s for s in self.sockets if s in page_sockets]


class InteractiveImage(Element):
def _handle_source_change(sender: Element, source: str) -> None:
sender.view.options.source = source
sender.update()

def __init__(self, source: str, *,

class InteractiveImage(Element, BindSourceMixin):
source = BindableProperty(on_change=_handle_source_change)

def __init__(self, source: str = '', *,
on_mouse: Optional[Callable] = None, events: List[str] = ['click'], cross: bool = False):
"""Interactive Image
Expand All @@ -46,6 +53,8 @@ def __init__(self, source: str, *,
self.mouse_handler = on_mouse
super().__init__(InteractiveImageView(source, self.handle_mouse, events, cross))

self.source = source

def handle_mouse(self, msg: Dict[str, Any]) -> Optional[bool]:
if self.mouse_handler is None:
return False
Expand Down

0 comments on commit 63cdab8

Please sign in to comment.