Display Widgets =============== .. _widget-image: Image ----- Image display widget with optional interactive pointer/keyboard events. **Constructor:** ``new Widgets.Image({url, interactive, use_animation_frame})`` **Options:** - ``url`` -- initial image URL - ``interactive`` -- enable pointer and keyboard events - ``use_animation_frame`` -- throttle updates to animation frame rate **Methods:** .. list-table:: :header-rows: 1 :widths: 40 60 * - Method - Description * - ``set_image(url)`` - Set image from URL or data URI. * - ``set_binary_image(format, buffer)`` - Set image from a raw ``ArrayBuffer`` or ``Uint8Array`` received as a binary WebSocket frame. ``format`` is one of ``"jpeg"``, ``"png"``, ``"webp"``, or ``"gif"``; the buffer is wrapped in a ``Blob`` of the matching MIME type and rendered. Used by the Python-side ``Image.set_binary_image`` to skip base64 framing for streaming use cases. * - ``get_draw_context()`` - Return a 2D canvas drawing context for overlay drawing. * - ``update()`` - Flush pending draw operations. **Callbacks:** - ``pointer-down``, ``pointer-up``, ``pointer-move`` -- mouse/touch - ``enter``, ``leave`` -- pointer enters/leaves - ``click``, ``dblclick`` -- click events - ``scroll`` -- scroll wheel - ``key-down``, ``key-up``, ``key-press`` -- keyboard - ``focus-in``, ``focus-out`` -- focus changes - ``drop-start``, ``drop-end``, ``drop-progress``, ``drag-over`` -- file drag-and-drop - ``contextmenu`` -- right-click .. code-block:: javascript let img = new Widgets.Image({interactive: true}); img.set_image("photo.jpg"); img.add_callback('click', (w, ev) => { console.log("Clicked at:", ev.data_x, ev.data_y); }); .. _widget-canvas: Canvas ------ HTML5 canvas for custom drawing with interactive events. **Constructor:** ``new Widgets.Canvas({use_animation_frame, interactive})`` **Options:** - ``use_animation_frame`` -- throttle updates to animation frame rate - ``interactive`` -- enable pointer and keyboard events **Methods:** .. list-table:: :header-rows: 1 :widths: 40 60 * - Method - Description * - ``draw_image(imgInfo)`` - Draw an image onto the canvas. * - ``get_draw_context()`` - Return the 2D canvas drawing context. * - ``update()`` - Flush pending draw operations. **Callbacks:** - ``pointer-down``, ``pointer-up``, ``pointer-move`` -- mouse/touch - ``enter``, ``leave`` -- pointer enters/leaves - ``click``, ``dblclick`` -- click events - ``scroll`` -- scroll wheel - ``key-down``, ``key-up``, ``key-press`` -- keyboard - ``focus-in``, ``focus-out`` -- focus changes - ``drop-start``, ``drop-end``, ``drag-over`` -- file drag-and-drop - ``contextmenu`` -- right-click - ``activated`` -- general activation .. code-block:: javascript let canvas = new Widgets.Canvas({interactive: true}); canvas.resize(640, 480); let ctx = canvas.get_draw_context(); ctx.fillStyle = "red"; ctx.fillRect(10, 10, 100, 50); canvas.update(); .. _widget-colorwidget: ColorWidget ----------- Inline color swatch with optional picker. **Constructor:** ``new Widgets.ColorWidget({color})`` **Options:** - ``color`` -- initial color as hex string (e.g. ``"#ff0000"``) **Methods:** .. list-table:: :header-rows: 1 :widths: 40 60 * - Method - Description * - ``get_color()`` - Return current color as hex string. * - ``set_color(hex_string)`` - Set color. **Callbacks:** - ``pick`` -- fired when a color is selected. .. code-block:: javascript let cw = new Widgets.ColorWidget({color: "#3366cc"}); cw.add_callback('pick', (w) => { console.log("Color:", w.get_color()); }); .. _widget-videowidget: VideoWidget ----------- Video display widget with playback controls. Supports video files via URL and live streams via WebRTC or ``getUserMedia``. **Constructor:** ``new Widgets.VideoWidget({url, autoplay, controls, muted, loop})`` **Options:** - ``url`` -- initial video URL - ``autoplay`` -- start playback automatically - ``controls`` -- show native browser playback controls - ``muted`` -- start muted - ``loop`` -- loop playback **Methods:** .. list-table:: :header-rows: 1 :widths: 45 55 * - Method - Description * - ``set_url(url)`` - Set video source from a URL (mp4, webm, etc.). * - ``set_stream(stream)`` - Set a MediaStream as the source (WebRTC, getUserMedia). * - ``get_video_element()`` - Return the underlying ``