How to use the ipycanvas._frontend.module_version function in ipycanvas

To help you get started, we’ve selected a few ipycanvas examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github martinRenou / ipycanvas / ipycanvas / animation.py View on Github external
module = ast.parse(value, '', 'exec')

        func = module.body[0]

        return ';\n'.join([Py2JSVisitor().visit(node) for node in func.body])

    raise RuntimeError('py2js only supports a code string or function as input')


class Animation(Widget):
    """Custom Canvas animation."""

    _model_name = Unicode('AnimationModel').tag(sync=True)
    _model_module = Unicode(module_name).tag(sync=True)
    _model_module_version = Unicode(module_version).tag(sync=True)
    _view_name = Unicode('AnimationView').tag(sync=True)
    _view_module = Unicode(module_name).tag(sync=True)
    _view_module_version = Unicode(module_version).tag(sync=True)

    # TODO: Custom Functor trait
    #: (functor) The draw function that will be called for every animation frame. This function should
    #: take the ``Canvas`` as first argument, the elapsed time (in ms) since the beginning of the animation
    #: as second argument, and custom data as third argument.
    draw = Any(allow_none=False)

    _draw = Unicode().tag(sync=True)

    #: (float) The animation duration (in ms), if ``0`` the animation will run infinitely.
    duration = CFloat(0).tag(sync=True)

    #: (dict) Custom data to be passed to the draw function.
github martinRenou / ipycanvas / ipycanvas / animation.py View on Github external
func = module.body[0]

        return ';\n'.join([Py2JSVisitor().visit(node) for node in func.body])

    raise RuntimeError('py2js only supports a code string or function as input')


class Animation(Widget):
    """Custom Canvas animation."""

    _model_name = Unicode('AnimationModel').tag(sync=True)
    _model_module = Unicode(module_name).tag(sync=True)
    _model_module_version = Unicode(module_version).tag(sync=True)
    _view_name = Unicode('AnimationView').tag(sync=True)
    _view_module = Unicode(module_name).tag(sync=True)
    _view_module_version = Unicode(module_version).tag(sync=True)

    # TODO: Custom Functor trait
    #: (functor) The draw function that will be called for every animation frame. This function should
    #: take the ``Canvas`` as first argument, the elapsed time (in ms) since the beginning of the animation
    #: as second argument, and custom data as third argument.
    draw = Any(allow_none=False)

    _draw = Unicode().tag(sync=True)

    #: (float) The animation duration (in ms), if ``0`` the animation will run infinitely.
    duration = CFloat(0).tag(sync=True)

    #: (dict) Custom data to be passed to the draw function.
    data = Dict().tag(sync=True)

    @validate('draw')
github martinRenou / ipycanvas / ipycanvas / canvas.py View on Github external
import numpy as np

from traitlets import Bool, Bytes, CInt, Enum, Float, Instance, List, Unicode

from ipywidgets import CallbackDispatcher, Color, DOMWidget, Image, widget_serialization
from ipywidgets.widgets.trait_types import bytes_serialization

from ._frontend import module_name, module_version

from .utils import binary_image, populate_args, to_camel_case, image_bytes_to_array


class _CanvasBase(DOMWidget):
    _model_module = Unicode(module_name).tag(sync=True)
    _model_module_version = Unicode(module_version).tag(sync=True)
    _view_module = Unicode(module_name).tag(sync=True)
    _view_module_version = Unicode(module_version).tag(sync=True)

    width = CInt(700).tag(sync=True)
    height = CInt(500).tag(sync=True)

    #: (bool) Specifies if the image should be synchronized from front-end to Python back-end
    sync_image_data = Bool(False).tag(sync=True)

    #: (bytes) Current image data as bytes (PNG encoded). It is ``None`` by default and will not be
    #: updated if ``sync_image_data`` is ``False``.
    image_data = Bytes(default_value=None, allow_none=True, read_only=True).tag(sync=True, **bytes_serialization)

    def to_file(self, filename):
        """Save the current Canvas image to a PNG file.
github martinRenou / ipycanvas / ipycanvas / canvas.py View on Github external
from traitlets import Bool, Bytes, CInt, Enum, Float, Instance, List, Unicode

from ipywidgets import CallbackDispatcher, Color, DOMWidget, Image, widget_serialization
from ipywidgets.widgets.trait_types import bytes_serialization

from ._frontend import module_name, module_version

from .utils import binary_image, populate_args, to_camel_case, image_bytes_to_array


class _CanvasBase(DOMWidget):
    _model_module = Unicode(module_name).tag(sync=True)
    _model_module_version = Unicode(module_version).tag(sync=True)
    _view_module = Unicode(module_name).tag(sync=True)
    _view_module_version = Unicode(module_version).tag(sync=True)

    width = CInt(700).tag(sync=True)
    height = CInt(500).tag(sync=True)

    #: (bool) Specifies if the image should be synchronized from front-end to Python back-end
    sync_image_data = Bool(False).tag(sync=True)

    #: (bytes) Current image data as bytes (PNG encoded). It is ``None`` by default and will not be
    #: updated if ``sync_image_data`` is ``False``.
    image_data = Bytes(default_value=None, allow_none=True, read_only=True).tag(sync=True, **bytes_serialization)

    def to_file(self, filename):
        """Save the current Canvas image to a PNG file.

        This will raise an exception if there is no image to save (_e.g._ if ``image_data`` is ``None``).
        """