Skip to content

Commit a1607b6

Browse files
committed
Fix bug in moidyfing menu choices
1 parent 8a8c389 commit a1607b6

File tree

3 files changed

+11
-57
lines changed

3 files changed

+11
-57
lines changed

labextension/vpython/src/glowcommlab.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -536,14 +536,12 @@ function decode(data) {
536536
vs = [Number(val[1]), Number(val[2]), Number(val[3]), Number(val[4])]
537537
}
538538
} else if (textattrs.indexOf(attr) > -1) {
539-
if (attr == 'choices') { // menu choices to be wrapped in a list
539+
if (attr == 'choices') { // menu choices are wrapped in a list
540540
val = m[3].slice(2,-2)
541541
val = val.replace(/'/g, '') // remove quotes
542-
val = val.replace(/,/g, '') // remove commas
543-
let s = val.split(' ')
542+
let s = val.split(',')
544543
val = []
545-
let a
546-
for (a of s) {val.push(a)}
544+
for (let a of s) {val.push(a)}
547545
} else {
548546
// '\n' doesn't survive JSON transmission, so in vpython.py we replace '\n' with '<br>'
549547
val = m[3].replace(/<br>/g, "\n")

vpython/vpython_libraries/glowcomm.html

Lines changed: 5 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -454,14 +454,12 @@
454454
vs = [Number(val[1]), Number(val[2]), Number(val[3]), Number(val[4])]
455455
}
456456
} else if (textattrs.indexOf(attr) > -1) {
457-
if (attr == 'choices') { // menu choices to be wrapped in a list
457+
if (attr == 'choices') { // menu choices are wrapped in a list
458458
val = m[3].slice(2,-2)
459459
val = val.replace(/'/g, '') // remove quotes
460-
val = val.replace(/,/g, '') // remove commas
461-
let s = val.split(' ')
460+
let s = val.split(',')
462461
val = []
463-
let a
464-
for (a of s) {val.push(a)}
462+
for (let a of s) {val.push(a)}
465463
} else {
466464
// '\n' doesn't survive JSON transmission, so in vpython.py we replace '\n' with '<br>'
467465
val = m[3].replace(/<br>/g, "\n")
@@ -541,7 +539,6 @@
541539
for (var i in data[d]) console.log(i, JSON.stringify(data[d][i]))
542540
}
543541
*/
544-
545542

546543
if (data.cmds !== undefined && data.cmds.length > 0) handle_cmds(data.cmds)
547544
if (data.methods !== undefined && data.methods.length > 0) handle_methods(data.methods)
@@ -800,6 +797,7 @@
800797
cfg.objName = obj
801798
cfg.bind = control_handler
802799
cfg = fix_location(cfg)
800+
console.log('menu cfg', cfg)
803801
glowObjs[idx] = menu(cfg)
804802
if (cfg['selected'] === 'None') {
805803
cfg['selected'] = null
@@ -809,47 +807,6 @@
809807
default:
810808
console.log("Unable to create object")
811809
}
812-
813-
/*
814-
if (obj === 'redisplay') {
815-
var c = document.getElementById(cmd.sceneId)
816-
if (c !== null) {
817-
var scn = "#" + cmd.sceneId
818-
glowObjs[idx].sceneclone = $(scn).clone(true,true)
819-
//document.getElementById('glowscript2').appendChild(c)
820-
//document.getElementById('glowscript2').replaceWith(c)
821-
$('#glowscript2').replaceWith(c)
822-
c = document.getElementById(cmd.sceneId)
823-
var cont = scn + " .glowscript"
824-
window.__context = { glowscript_container: $(cont) }
825-
} else {
826-
window.__context = { glowscript_container: $("#glowscript").removeAttr("id") }
827-
var newcnvs = canvas()
828-
for (var obj in glowObjs[idx].objects) {
829-
var o = glowObjs[idx].objects[obj]
830-
if ((o.constructor.name !== 'curve') && (o.constructor.name !== 'points')) {
831-
glowObjs[o.gidx] = o.clone({canvas: newcnvs})
832-
var olen = newcnvs.objects.length
833-
if (olen > 0) {
834-
newcnvs.objects[olen - 1].gidx = o.gidx
835-
}
836-
}
837-
}
838-
glowObjs[idx] = newcnvs
839-
$("#glowscript2").attr("id",cmd.sceneId)
840-
}
841-
} else if (obj === 'delete') {
842-
b = glowObjs[idx]
843-
if ((b !== null) || (b.visible !== undefined)) {
844-
b.visible = false
845-
}
846-
glowObjs[idx] = null
847-
} else if (obj === 'heartbeat') {
848-
//console.log("heartbeat")
849-
} else if (obj === 'debug') {
850-
console.log("debug : ", cmd)
851-
}
852-
*/
853810
} // end of cmds (constructors and special data)
854811
}
855812

@@ -931,6 +888,7 @@
931888
var obj = glowObjs[idx]
932889
var attr = cmd['attr']
933890
var val = cmd['val']
891+
console.log(obj, attr, val)
934892
var triangle_quad = ['v0', 'v1', 'v2', 'v3']
935893
// vector attrs in attach_arrow have arbitrary names, so check for length 3 array instead
936894
if (val instanceof vec) {

vpython/vpython_libraries/glowcomm.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -504,14 +504,12 @@ function decode(data) {
504504
vs = [Number(val[1]), Number(val[2]), Number(val[3]), Number(val[4])]
505505
}
506506
} else if (textattrs.indexOf(attr) > -1) {
507-
if (attr == 'choices') { // menu choices to be wrapped in a list
507+
if (attr == 'choices') { // menu choices are wrapped in a list
508508
val = m[3].slice(2,-2)
509509
val = val.replace(/'/g, '') // remove quotes
510-
val = val.replace(/,/g, '') // remove commas
511-
let s = val.split(' ')
510+
let s = val.split(',')
512511
val = []
513-
let a
514-
for (a of s) {val.push(a)}
512+
for (let a of s) {val.push(a)}
515513
} else {
516514
// '\n' doesn't survive JSON transmission, so in vpython.py we replace '\n' with '<br>'
517515
val = m[3].replace(/<br>/g, "\n")

0 commit comments

Comments
 (0)