当前位置: 首页>>代码示例>>Python>>正文


Python JS.toString方法代码示例

本文整理汇总了Python中__pyjamas__.JS.toString方法的典型用法代码示例。如果您正苦于以下问题:Python JS.toString方法的具体用法?Python JS.toString怎么用?Python JS.toString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在__pyjamas__.JS的用法示例。


在下文中一共展示了JS.toString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from __pyjamas__ import JS [as 别名]
# 或者: from __pyjamas__.JS import toString [as 别名]
class PyTypedArray:

    """
    PyTypedArray is the base class that wraps the JavaScript TypedArray objects.
    The derived objects provides an interface to the JavaScript array objects:
        PyUint8ClampedArray     [Uint8ClampedArray]
        PyUint8Array            [Uint8Array]
        PyUint16Array           [Uint16Array]
        PyUint32Array           [Uint32Array]
        PyInt8Array             [Int8Array]
        PyInt16Array            [Int16Array]
        PyInt32Array            [Int32Array]
        PyFloat32Array          [Float32Array]
        PyFloat64Array          [Float64Array]
     The PyTypedArray interface include index syntax, iteration, and math operations.
     The module contains an Ndarray class to instantiate N-dimensional arrays, and PyImageData and PyImageMatrix classes that provide an interface to canvas ImageData.
    """

    def __init__(self, data=None, offset=None, length=None, typedarray=None):
        """
        The PyTypedArray is instantiated with either the array size, an array of the TypedArray or Python type, or an existing ArrayBuffer to view, which creates a new TypedArray of size and included data as the specified type. Optional arguments include offset index at which ArrayBuffer data is inserted and length of an ArrayBuffer.
        """
        if data:
            if isinstance(data, int):
                if pyjs_mode.optimized:
                    self.__data = JS("""new @{{typedarray}}(@{{data}})""")
                else:
                    self.__data = JS("""new @{{typedarray}}(@{{data}}['valueOf']())""")
            elif isinstance(data, (list,tuple)):
                if pyjs_mode.optimized:
                    self.__data = JS("""new @{{typedarray}}(@{{data}}['getArray']())""")
                else:
                    data = [dat.valueOf() for dat in data]
                    self.__data = JS("""new @{{typedarray}}(@{{data}}['getArray']())""")
            elif isinstance(data, PyTypedArray):
                self.__data = JS("""new @{{typedarray}}(@{{data}}['__data'])""")
            else:   #TypedArray or ArrayBuffer
                if offset is None and length is None:
                    self.__data = JS("""new @{{typedarray}}(@{{data}})""")
                else:
                    if offset is None:
                        offset = 0
                    if length is None:
                        self.__data = JS("""new @{{typedarray}}(@{{data}}, @{{offset}})""")
                    else:
                        self.__data = JS("""new @{{typedarray}}(@{{data}}, @{{offset}}, @{{length}})""")
        else:
            self.__data = None

    def __str__(self):
        """
        Return string representation of PyTypedArray object.
        """
        return self.__data.toString()

    def __iter__(self):
        """
        Iterate over PyTypedArray object.
        """
        index = 0
        while index < self.__data.length:
            yield self[index]
            index += 1

    def __getitem__(self, index):
        """
        Get TypedArray element by index.
        """
        return JS("""@{{int}}(@{{self}}['__data'][@{{index}}]);""")

    def __setitem__(self, index, value):
        """
        Set TypedArray element by index.
        """
        if pyjs_mode.optimized:
            JS("""@{{self}}['__data'][@{{index}}][email protected]{{value}};""")
        else:
            value = value.valueOf()
            JS("""@{{self}}['__data'][@{{index}}][email protected]{{value}};""")
        return None

    def __len__(self):
        """
        Get TypedArray array length.
        """
        return self.__data.length

    def set(self, data, offset=0):
        """
        Set data to the array. Arguments: data is a list of either the TypedArray or Python type, offset is the start index where data will be set (defaults to 0).
        """
        if isinstance(data, (list,tuple)):
            if pyjs_mode.optimized:
                self.__data.set(data.getArray(), offset)
            else:
                data = [dat.valueOf() for dat in data]
                self.__data.set(data.getArray(), offset)
        elif isinstance(data, PyTypedArray):
            self.__data.set(data.__data, offset)

#.........这里部分代码省略.........
开发者ID:Lucytheanimefan,项目名称:Center-for-Advanced-HindSight-Games,代码行数:103,代码来源:pyjsarray.py


注:本文中的__pyjamas__.JS.toString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。