Skip to content

Commit 13ee7c4

Browse files
committed
Improved radio button
1 parent aa5765d commit 13ee7c4

File tree

5 files changed

+38
-17
lines changed

5 files changed

+38
-17
lines changed

labextension/vpython/src/glowcommlab.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,8 @@ var attrsb = {'a':'userzoom', 'b':'userspin', 'c':'range', 'd':'autoscale', 'e':
477477
'p':'left', 'q':'right', 'r':'top', 's':'bottom', 't':'_cloneid',
478478
'u':'logx', 'v':'logy', 'w':'dot', 'x':'dot_radius',
479479
'y':'markers', 'z':'legend', 'A':'label','B':'delta', 'C':'marker_color',
480-
'D':'size_units', 'E':'userpan', 'F':'scroll', 'G':'choices', 'H':'depth', 'I':'round'}
480+
'D':'size_units', 'E':'userpan', 'F':'scroll', 'G':'choices', 'H':'depth',
481+
'I':'round', 'J':'name'}
481482

482483
// methods are X in {'m': '23X....'} available: u
483484
var methods = {'a':'select', 'b':'pos', 'c':'start', 'd':'stop', 'f':'clear', // unused eghijklmnopvxyzCDFAB
@@ -491,7 +492,7 @@ var vecattrs = ['pos', 'up', 'color', 'trail_color', 'axis', 'size', 'origin',
491492
'foreground', 'background', 'ray', 'ambient', 'center', 'forward', 'normal',
492493
'marker_color']
493494

494-
var textattrs = ['text', 'align', 'caption', 'title', 'title_align', 'xtitle', 'ytitle', 'selected', 'capture',
495+
var textattrs = ['text', 'align', 'caption', 'title', 'title_align', 'xtitle', 'ytitle', 'selected', 'capture', 'name',
495496
'label', 'append_to_caption', 'append_to_title', 'bind', 'unbind', 'pause', 'GSprint', 'choices']
496497

497498
// patt gets idx and attr code; vpatt gets x,y,z of a vector
@@ -613,7 +614,6 @@ function o2vec3(p) {
613614
}
614615

615616
function handler(data) {
616-
"use strict";
617617
"use strict";
618618

619619
/*
@@ -622,8 +622,8 @@ function handler(data) {
622622
for (var i in data[d]) console.log(i, JSON.stringify(data[d][i]))
623623
}
624624
*/
625-
626625

626+
627627
if (data.cmds !== undefined && data.cmds.length > 0) handle_cmds(data.cmds)
628628
if (data.methods !== undefined && data.methods.length > 0) handle_methods(data.methods)
629629
if (data.attrs !== undefined && data.attrs.length > 0) handle_attrs(data.attrs)
@@ -862,10 +862,13 @@ function handle_cmds(dcmds) {
862862
break
863863
}
864864
case 'radio': {
865+
cfg.canvas = canvas.get_selected()
866+
cfg = fix_location(cfg)
867+
delete cfg.canvas
865868
cfg.objName = obj
866869
cfg.bind = control_handler
867-
cfg = fix_location(cfg)
868870
glowObjs[idx] = radio(cfg)
871+
// glowObjs[idx].canvas = canvas.get_selected()
869872
break
870873
}
871874
case 'button': {

vpython/vpython.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@
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', 'choices':'G', 'depth':'H', 'round':'I'}
100+
'size_units':'D', 'userpan':'E', 'scroll':'F', 'choices':'G', 'depth':'H',
101+
'round':'I', 'name':'J'}
101102

102103
# methods are X in {'m': '23X....'}
103104
# pos is normally updated as an attribute, but for interval-based trails, it is updated (multiply) as a method
@@ -112,7 +113,7 @@
112113
'foreground', 'background', 'ray', 'ambient', 'center', 'forward', 'normal',
113114
'marker_color']
114115

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

118119
def _encode_attr2(sendval, val, ismethods):
@@ -3399,7 +3400,7 @@ def text(self, value):
33993400
class controls(baseObj):
34003401
attrlists = { 'button': ['text', 'color', 'textcolor', 'background', 'disabled'],
34013402
'checkbox':['checked', 'text', 'disabled'],
3402-
'radio':['checked', 'text', 'disabled'],
3403+
'radio':['checked', 'text', 'disabled', 'name'],
34033404
'menu':['selected', 'choices', 'index', 'disabled'],
34043405
'slider':['vertical', 'min', 'max', 'step', 'value', 'length',
34053406
'width', 'left', 'right', 'top', 'bottom', 'align', 'disabled'],
@@ -3586,6 +3587,14 @@ def checked(self, value):
35863587
if not self._constructing:
35873588
self.addattr('checked')
35883589

3590+
@property
3591+
def name(self):
3592+
return self._name
3593+
@name.setter
3594+
def name(self, value):
3595+
if not self._constructing:
3596+
raise AttributeError('Cannot change the name attribute of a radio widget.')
3597+
35893598
class winput(controls):
35903599
def __init__(self, **args):
35913600
args['_objName'] = 'winput'

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: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,8 @@
395395
'p':'left', 'q':'right', 'r':'top', 's':'bottom', 't':'_cloneid',
396396
'u':'logx', 'v':'logy', 'w':'dot', 'x':'dot_radius',
397397
'y':'markers', 'z':'legend', 'A':'label','B':'delta', 'C':'marker_color',
398-
'D':'size_units', 'E':'userpan', 'F':'scroll', 'G':'choices', 'H':'depth', 'I':'round'}
398+
'D':'size_units', 'E':'userpan', 'F':'scroll', 'G':'choices', 'H':'depth',
399+
'I':'round', 'J':'name'}
399400

400401
// methods are X in {'m': '23X....'} available: u
401402
var methods = {'a':'select', 'b':'pos', 'c':'start', 'd':'stop', 'f':'clear', // unused eghijklmnopvxyzCDFAB
@@ -409,7 +410,7 @@
409410
'foreground', 'background', 'ray', 'ambient', 'center', 'forward', 'normal',
410411
'marker_color']
411412

412-
var textattrs = ['text', 'align', 'caption', 'title', 'title_align', 'xtitle', 'ytitle', 'selected', 'capture',
413+
var textattrs = ['text', 'align', 'caption', 'title', 'title_align', 'xtitle', 'ytitle', 'selected', 'capture', 'name',
413414
'label', 'append_to_caption', 'append_to_title', 'bind', 'unbind', 'pause', 'GSprint', 'choices']
414415

415416
// patt gets idx and attr code; vpatt gets x,y,z of a vector
@@ -539,8 +540,8 @@
539540
for (var i in data[d]) console.log(i, JSON.stringify(data[d][i]))
540541
}
541542
*/
542-
543543

544+
544545
if (data.cmds !== undefined && data.cmds.length > 0) handle_cmds(data.cmds)
545546
if (data.methods !== undefined && data.methods.length > 0) handle_methods(data.methods)
546547
if (data.attrs !== undefined && data.attrs.length > 0) handle_attrs(data.attrs)
@@ -779,10 +780,13 @@
779780
break
780781
}
781782
case 'radio': {
783+
cfg.canvas = canvas.get_selected()
784+
cfg = fix_location(cfg)
785+
delete cfg.canvas
782786
cfg.objName = obj
783787
cfg.bind = control_handler
784-
cfg = fix_location(cfg)
785788
glowObjs[idx] = radio(cfg)
789+
// glowObjs[idx].canvas = canvas.get_selected()
786790
break
787791
}
788792
case 'button': {

vpython/vpython_libraries/glowcomm.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ function send() { // periodically send events and update_canvas and request obje
166166

167167
// Should eventually have glowcomm.html, glowcom.js, and glowcommlab.js all import this common component.
168168

169-
window.__GSlang = "vpython"
169+
window.__GSlang = "vpython"
170170

171171
function msclock() {
172172
"use strict";
@@ -445,7 +445,8 @@ var attrsb = {'a':'userzoom', 'b':'userspin', 'c':'range', 'd':'autoscale', 'e':
445445
'p':'left', 'q':'right', 'r':'top', 's':'bottom', 't':'_cloneid',
446446
'u':'logx', 'v':'logy', 'w':'dot', 'x':'dot_radius',
447447
'y':'markers', 'z':'legend', 'A':'label','B':'delta', 'C':'marker_color',
448-
'D':'size_units', 'E':'userpan', 'F':'scroll', 'G':'choices', 'H':'depth', 'I':'round'}
448+
'D':'size_units', 'E':'userpan', 'F':'scroll', 'G':'choices', 'H':'depth',
449+
'I':'round', 'J':'name'}
449450

450451
// methods are X in {'m': '23X....'} available: u
451452
var methods = {'a':'select', 'b':'pos', 'c':'start', 'd':'stop', 'f':'clear', // unused eghijklmnopvxyzCDFAB
@@ -459,7 +460,7 @@ var vecattrs = ['pos', 'up', 'color', 'trail_color', 'axis', 'size', 'origin',
459460
'foreground', 'background', 'ray', 'ambient', 'center', 'forward', 'normal',
460461
'marker_color']
461462

462-
var textattrs = ['text', 'align', 'caption', 'title', 'title_align', 'xtitle', 'ytitle', 'selected', 'capture',
463+
var textattrs = ['text', 'align', 'caption', 'title', 'title_align', 'xtitle', 'ytitle', 'selected', 'capture', 'name',
463464
'label', 'append_to_caption', 'append_to_title', 'bind', 'unbind', 'pause', 'GSprint', 'choices']
464465

465466
// patt gets idx and attr code; vpatt gets x,y,z of a vector
@@ -830,10 +831,14 @@ function handle_cmds(dcmds) {
830831
break
831832
}
832833
case 'radio': {
834+
cfg.canvas = canvas.get_selected()
835+
cfg = fix_location(cfg)
836+
delete cfg.canvas
833837
cfg.objName = obj
834838
cfg.bind = control_handler
835-
cfg = fix_location(cfg)
839+
836840
glowObjs[idx] = radio(cfg)
841+
// glowObjs[idx].canvas = canvas.get_selected()
837842
break
838843
}
839844
case 'button': {

0 commit comments

Comments
 (0)