本文整理汇总了Python中__pyjamas__.JS.set方法的典型用法代码示例。如果您正苦于以下问题:Python JS.set方法的具体用法?Python JS.set怎么用?Python JS.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类__pyjamas__.JS
的用法示例。
在下文中一共展示了JS.set方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from __pyjamas__ import JS [as 别名]
# 或者: from __pyjamas__.JS import set [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)
#.........这里部分代码省略.........