Skip to content

Commit d66543c

Browse files
Merge pull request #83 from vpython/Update_to_match_GlowScript
Update to match GlowScript
2 parents ac3950c + 3ed4c95 commit d66543c

File tree

5 files changed

+53
-23
lines changed

5 files changed

+53
-23
lines changed

labextension/vpython/src/glowcommlab.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ var attrsb = {'a':'userzoom', 'b':'userspin', 'c':'range', 'd':'autoscale', 'e':
483483
'p':'left', 'q':'right', 'r':'top', 's':'bottom', 't':'_cloneid',
484484
'u':'logx', 'v':'logy', 'w':'dot', 'x':'dot_radius',
485485
'y':'markers', 'z':'legend', 'A':'label','B':'delta', 'C':'marker_color',
486-
'D':'size_units', 'E':'userpan', 'F':'scroll'}
486+
'D':'size_units', 'E':'userpan', 'F':'scroll', 'G':'choices'}
487487

488488
// methods are X in {'m': '23X....'}
489489
var methods = {'a':'select', 'b':'pos', 'c':'start', 'd':'stop', 'f':'clear', // unused eghijklmnopvxyzCDFAB
@@ -498,7 +498,7 @@ var vecattrs = ['pos', 'up', 'color', 'trail_color', 'axis', 'size', 'origin', '
498498
'marker_color']
499499

500500
var textattrs = ['text', 'align', 'caption', 'title', 'title_align', 'xtitle', 'ytitle', 'selected', 'capture',
501-
'label', 'append_to_caption', 'append_to_title', 'bind', 'unbind', 'pause', 'GSprint']
501+
'label', 'append_to_caption', 'append_to_title', 'bind', 'unbind', 'pause', 'GSprint', 'choices']
502502

503503
// patt gets idx and attr code; vpatt gets x,y,z of a vector
504504
var patt = /(\d+)(.)(.*)/
@@ -542,8 +542,12 @@ function decode(data) {
542542
vs = [Number(val[1]), Number(val[2]), Number(val[3]), Number(val[4])]
543543
}
544544
} else if (textattrs.indexOf(attr) > -1) {
545-
// '\n' doesn't survive JSON transmission, so in vpython.py we replace '\n' with '<br>'
546-
val = m[3].replace(/<br>/g, "\n")
545+
if (attr == 'choices') { // menu choices to be wrapped in a list
546+
val = m[3].split(' ')
547+
} else {
548+
// '\n' doesn't survive JSON transmission, so in vpython.py we replace '\n' with '<br>'
549+
val = m[3].replace(/<br>/g, "\n")
550+
}
547551
} else if (attr == 'rotate') { // angle,x,y,z,x,y,z
548552
var temp = m[3]
549553
val = []

vpython/vpython.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
'right':'q', 'top':'r', 'bottom':'s', '_cloneid':'t',
9898
'logx':'u', 'logy':'v', 'dot':'w', 'dot_radius':'x',
9999
'markers':'y', 'legend':'z', 'label':'A', 'delta':'B', 'marker_color':'C',
100-
'size_units':'D', 'userpan':'E', 'scroll':'F'}
100+
'size_units':'D', 'userpan':'E', 'scroll':'F', 'choices':'G'}
101101

102102
# methods are X in {'m': '23X....'}
103103
# pos is normally updated as an attribute, but for interval-based trails, it is updated (multiply) as a method
@@ -113,16 +113,22 @@
113113
'marker_color']
114114

115115
__textattrs = ['text', 'align', 'caption', 'title', 'xtitle', 'ytitle', 'selected', 'label', 'capture',
116-
'append_to_caption', 'append_to_title', 'bind', 'unbind', 'pause', 'GSprint']
116+
'append_to_caption', 'append_to_title', 'bind', 'unbind', 'pause', 'GSprint', 'choices']
117117

118118
def _encode_attr2(sendval, val, ismethods):
119119
s = ''
120120
if sendval in __vecattrs: # it would be good to do some kind of compression of doubles
121121
s += "{:.16G},{:.16G},{:.16G}".format(val[0], val[1], val[2])
122122
elif sendval in __textattrs:
123-
# '\n' doesn't survive JSON transmission, so we replace '\n' with '<br>' (and convert back in glowcomm)
124-
if not isinstance(val, str): val = print_to_string(val)
125-
val = val.replace('\n', '<br>')
123+
if sendval == 'choices':
124+
s2 = ''
125+
for v in val:
126+
s2 += v+' '
127+
val = s2[0:-1]
128+
else:
129+
# '\n' doesn't survive JSON transmission, so we replace '\n' with '<br>' (and convert back in glowcomm)
130+
if not isinstance(val, str): val = print_to_string(val)
131+
val = val.replace('\n', '<br>')
126132
s += val
127133
elif sendval == 'rotate':
128134
for p in val:
@@ -556,7 +562,7 @@ class standardAttributes(baseObj):
556562
'extrusion':[ ['pos', 'color', 'start_face_color', 'end_face_color'],
557563
[ 'axis', 'size', 'up' ],
558564
['path', 'shape', 'visible', 'opacity','shininess', 'emissive',
559-
'show_start_face', 'show_end_face',
565+
'show_start_face', 'show_end_face', 'smooth',
560566
'make_trail', 'trail_type', 'interval', 'show_start_face', 'show_end_face',
561567
'retain', 'trail_color', 'trail_radius', 'texture', 'pickable' ],
562568
['red', 'green', 'blue','length', 'width', 'height'] ],
@@ -2702,7 +2708,7 @@ def rotate(self, angle=0, axis=None, origin=None):
27022708
c = self._canvas
27032709
if axis is None: axis = c.up
27042710
if origin is not None and origin != self.pos:
2705-
origin = self.pos + (self.pos-origin).rotate(angle=angle, axis=axis)
2711+
origin = origin + (self.pos-origin).rotate(angle=angle, axis=axis)
27062712
else:
27072713
origin = self.pos
27082714
if c._axis.diff_angle(axis) > 1e-6:
@@ -3098,7 +3104,6 @@ def handle_event(self, evt): ## events and scene info updates
30983104
# Set attribute_vector.value, which avoids nullifying the
30993105
# on_change functions that detect changes in e.g. obj.pos.y
31003106
obj._pos.value = list_to_vec(p)
3101-
obj._origin = obj._pos
31023107
s = evt['size']
31033108
obj._size.value = obj._size0 = list_to_vec(s)
31043109
obj._axis.value = obj._size._x*norm(obj._axis)
@@ -3543,7 +3548,10 @@ def choices(self):
35433548
return self._choices
35443549
@choices.setter
35453550
def choices(self, value):
3546-
raise AttributeError('choices cannot be modified after a menu is created')
3551+
self._choices = value
3552+
if not self._constructing:
3553+
self.addattr('choices')
3554+
#raise AttributeError('choices cannot be modified after a menu is created')
35473555

35483556
@property
35493557
def index(self):
@@ -3784,6 +3792,16 @@ def shape(self):
37843792
def shape(self, value):
37853793
raise AttributeError('shape cannot be changed after extrusion is created')
37863794

3795+
@property
3796+
def smooth(self):
3797+
if self._constructing:
3798+
return self._smooth
3799+
else:
3800+
return None
3801+
@smooth.setter
3802+
def smooth(self, value):
3803+
raise AttributeError('smooth cannot be changed after extrusion is created')
3804+
37873805
@property
37883806
def show_start_face(self):
37893807
if self._constructing:

vpython/vpython_libraries/glow.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vpython/vpython_libraries/glowcomm.html

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@
406406
'p':'left', 'q':'right', 'r':'top', 's':'bottom', 't':'_cloneid',
407407
'u':'logx', 'v':'logy', 'w':'dot', 'x':'dot_radius',
408408
'y':'markers', 'z':'legend', 'A':'label','B':'delta', 'C':'marker_color',
409-
'D':'size_units', 'E':'userpan', 'F':'scroll'}
409+
'D':'size_units', 'E':'userpan', 'F':'scroll', 'G':'choices'}
410410

411411
// methods are X in {'m': '23X....'}
412412
var methods = {'a':'select', 'b':'pos', 'c':'start', 'd':'stop', 'f':'clear', // unused eghijklmnopvxyzCDFAB
@@ -421,7 +421,7 @@
421421
'marker_color']
422422

423423
var textattrs = ['text', 'align', 'caption', 'title', 'title_align', 'xtitle', 'ytitle', 'selected', 'capture',
424-
'label', 'append_to_caption', 'append_to_title', 'bind', 'unbind', 'pause', 'GSprint']
424+
'label', 'append_to_caption', 'append_to_title', 'bind', 'unbind', 'pause', 'GSprint', 'choices']
425425

426426
// patt gets idx and attr code; vpatt gets x,y,z of a vector
427427
var patt = /(\d+)(.)(.*)/
@@ -465,8 +465,12 @@
465465
vs = [Number(val[1]), Number(val[2]), Number(val[3]), Number(val[4])]
466466
}
467467
} else if (textattrs.indexOf(attr) > -1) {
468-
// '\n' doesn't survive JSON transmission, so in vpython.py we replace '\n' with '<br>'
469-
val = m[3].replace(/<br>/g, "\n")
468+
if (attr == 'choices') { // menu choices to be wrapped in a list
469+
val = m[3].split(' ')
470+
} else {
471+
// '\n' doesn't survive JSON transmission, so in vpython.py we replace '\n' with '<br>'
472+
val = m[3].replace(/<br>/g, "\n")
473+
}
470474
} else if (attr == 'rotate') { // angle,x,y,z,x,y,z
471475
var temp = m[3]
472476
val = []
@@ -954,4 +958,4 @@
954958

955959
</script>
956960
</div>
957-
</body>
961+
</body>

vpython/vpython_libraries/glowcomm.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ var attrsb = {'a':'userzoom', 'b':'userspin', 'c':'range', 'd':'autoscale', 'e':
456456
'p':'left', 'q':'right', 'r':'top', 's':'bottom', 't':'_cloneid',
457457
'u':'logx', 'v':'logy', 'w':'dot', 'x':'dot_radius',
458458
'y':'markers', 'z':'legend', 'A':'label','B':'delta', 'C':'marker_color',
459-
'D':'size_units', 'E':'userpan', 'F':'scroll'}
459+
'D':'size_units', 'E':'userpan', 'F':'scroll', 'G':'choices'}
460460

461461
// methods are X in {'m': '23X....'}
462462
var methods = {'a':'select', 'b':'pos', 'c':'start', 'd':'stop', 'f':'clear', // unused eghijklmnopvxyzCDFAB
@@ -471,7 +471,7 @@ var vecattrs = ['pos', 'up', 'color', 'trail_color', 'axis', 'size', 'origin', '
471471
'marker_color']
472472

473473
var textattrs = ['text', 'align', 'caption', 'title', 'title_align', 'xtitle', 'ytitle', 'selected', 'capture',
474-
'label', 'append_to_caption', 'append_to_title', 'bind', 'unbind', 'pause', 'GSprint']
474+
'label', 'append_to_caption', 'append_to_title', 'bind', 'unbind', 'pause', 'GSprint', 'choices']
475475

476476
// patt gets idx and attr code; vpatt gets x,y,z of a vector
477477
var patt = /(\d+)(.)(.*)/
@@ -515,8 +515,12 @@ function decode(data) {
515515
vs = [Number(val[1]), Number(val[2]), Number(val[3]), Number(val[4])]
516516
}
517517
} else if (textattrs.indexOf(attr) > -1) {
518-
// '\n' doesn't survive JSON transmission, so in vpython.py we replace '\n' with '<br>'
519-
val = m[3].replace(/<br>/g, "\n")
518+
if (attr == 'choices') { // menu choices to be wrapped in a list
519+
val = m[3].split(' ')
520+
} else {
521+
// '\n' doesn't survive JSON transmission, so in vpython.py we replace '\n' with '<br>'
522+
val = m[3].replace(/<br>/g, "\n")
523+
}
520524
} else if (attr == 'rotate') { // angle,x,y,z,x,y,z
521525
var temp = m[3]
522526
val = []

0 commit comments

Comments
 (0)