Skip to content

Commit 5fb1a65

Browse files
Merge pull request #154 from vpython/Improve-scene.capture
scene.capture handles label text
2 parents 9b73ec7 + caca878 commit 5fb1a65

File tree

5 files changed

+21
-7
lines changed

5 files changed

+21
-7
lines changed

labextension/vpython/src/glowcommlab.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,9 @@ async function handle_methods(dmeth) {
961961
if (val === null) obj.camera.follow(null)
962962
else obj.camera.follow(glowObjs[val])
963963
} else if (method === "capture") {
964-
await obj.capture(val)
964+
// val has the form "Tname.png" (display labels) or "Fname.png" (do not display labels)
965+
let TF = (val[0] == 'T') ? true: false
966+
await obj.capture(val.slice(1), TF)
965967
} else if (method === 'waitfor') {
966968
waitfor_canvas = idx
967969
waitfor_options = val

vpython/vpython.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def _encode_attr2(sendval, val, ismethods):
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)
123+
# '\n' doesn't survive JSON transmission, so we replace '\n' with '<br>' (and convert back in glowcomm)
124124
if not isinstance(val, str): val = print_to_string(val)
125125
val = val.replace('\n', '<br>')
126126
s += val
@@ -3138,10 +3138,17 @@ def pixel_to_world(self):
31383138
def pixel_to_world(self, value):
31393139
raise AttributeError('pixel_to_world is read-only')
31403140

3141-
def capture(self, filename):
3141+
def capture(self, *s):
3142+
if len(s) == 0:
3143+
raise AttributeError('scene.capture requires at least one argument.')
3144+
filename = s[0]
31423145
if not isinstance(filename, str): raise AttributeError('A capture file name must be a string.')
31433146
if '.png' not in filename: filename += '.png'
3144-
self.addmethod('capture', filename)
3147+
include_labels = "T"
3148+
if len(s) == 2:
3149+
if s[1] == True: include_labels = "T"
3150+
else: include_labels = "F"
3151+
self.addmethod('capture', include_labels+filename)
31453152

31463153
@property
31473154
def objects(self):

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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,7 @@
540540
}
541541
*/
542542

543+
543544
if (data.cmds !== undefined && data.cmds.length > 0) handle_cmds(data.cmds)
544545
if (data.methods !== undefined && data.methods.length > 0) handle_methods(data.methods)
545546
if (data.attrs !== undefined && data.attrs.length > 0) handle_attrs(data.attrs)
@@ -871,7 +872,9 @@
871872
if (val === null) obj.camera.follow(null)
872873
else obj.camera.follow(glowObjs[val])
873874
} else if (method === "capture") {
874-
await obj.capture(val)
875+
// val has the form "Tname.png" (display labels) or "Fname.png" (do not display labels)
876+
let TF = (val[0] == 'T') ? true: false
877+
await obj.capture(val.slice(1), TF)
875878
} else if (method === 'waitfor') {
876879
waitfor_canvas = idx
877880
waitfor_options = val

vpython/vpython_libraries/glowcomm.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,9 @@ async function handle_methods(dmeth) {
921921
if (val === null) obj.camera.follow(null)
922922
else obj.camera.follow(glowObjs[val])
923923
} else if (method === "capture") {
924-
await obj.capture(val)
924+
// val has the form "Tname.png" (display labels) or "Fname.png" (do not display labels)
925+
let TF = (val[0] == 'T') ? true: false
926+
await obj.capture(val.slice(1), TF)
925927
} else if (method === 'waitfor') {
926928
waitfor_canvas = idx
927929
waitfor_options = val

0 commit comments

Comments
 (0)