Skip to content

Commit b772e3b

Browse files
author
hartsantler
committed
fixed typo and added warning about using the same decorator.setter more than once in a class.
1 parent 88f4ec1 commit b772e3b

3 files changed

Lines changed: 22 additions & 4 deletions

File tree

bindings/three.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def y(self, value):
2828
def z(self):
2929
vec = self._vec
3030
return JS('vec.z')
31-
@x.setter
31+
@z.setter
3232
def z(self, value):
3333
vec = self._vec
3434
JS('vec.z=value')

pythonscript/python_to_pythonjs.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ def visit_ClassDef(self, node):
190190
if self._catch_attributes:
191191
self._inline_classes[ name ] = self._catch_attributes
192192

193+
writer.write('#decorators#')
194+
writer.write('#%s' %self._decorator_properties)
195+
writer.write('#--------------------------------')
193196
self._catch_attributes = None
194197
self._decorator_properties = None
195198
self._instances.pop('self')
@@ -368,7 +371,8 @@ def visit_Assign(self, node):
368371
if klass in self._decorator_class_props and target.attr in self._decorator_class_props[klass]:
369372
setter = self._decorator_class_props[klass][target.attr].get( 'set', None )
370373
if setter:
371-
writer.write( '''JS('%s( [%s, %s] )')''' %(setter, name, self.visit(node.value)) )
374+
#writer.write( '''JS('%s( [%s, %s] )')''' %(setter, name, self.visit(node.value)) ) ## can not nest have nested JS() calls
375+
writer.write( '%s( [%s, %s] )' %(setter, name, self.visit(node.value)) )
372376
fallback = False
373377

374378

@@ -379,10 +383,10 @@ def visit_Assign(self, node):
379383
self.visit(node.value)
380384
)
381385
writer.write(code)
386+
382387
elif isinstance(target, Name):
383388

384389
if isinstance(node.value, Call) and hasattr(node.value.func, 'id') and node.value.func.id in self._classes:
385-
writer.write('## creating class: %s ' %node.value.func.id)
386390
self._instances[ target.id ] = node.value.func.id ## keep track of instances
387391
elif target.id in self._instances:
388392
self._instances.pop( target.id )
@@ -463,11 +467,13 @@ def visit_FunctionDef(self, node):
463467
if isinstance(decorator, Name) and decorator.id == 'property':
464468
property_decorator = decorator
465469
n = node.name + '__getprop__'
466-
self._decorator_properties[ node.original_name ] = dict( get=n )
470+
self._decorator_properties[ node.original_name ] = dict( get=n, set=None )
467471
node.name = n
468472

469473
elif isinstance(decorator, Attribute) and isinstance(decorator.value, Name) and decorator.value.id in self._decorator_properties:
470474
if decorator.attr == 'setter':
475+
if self._decorator_properties[ decorator.value.id ]['set']:
476+
raise SyntaxError('user error - the same decorator.setter is used more than once!')
471477
n = node.name + '__setprop__'
472478
self._decorator_properties[ decorator.value.id ]['set'] = n
473479
node.name = n

tests/threejs_vector3.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@
1616
print( v1.y )
1717
print( v1.z )
1818

19+
v1.x = v2.x
20+
v1.y = v2.y
21+
v1.z = v2.z
22+
print( v1.x )
23+
print( v1.y )
24+
print( v1.z )
25+
26+
v1.copy( Vector3(9,9,9) )
27+
print( v1.x )
28+
print( v1.y )
29+
print( v1.z )
30+
1931
</script>
2032
</head>
2133

0 commit comments

Comments
 (0)