Skip to content

Commit

Permalink
Merge pull request #154 from vpython/Improve-scene.capture
Browse files Browse the repository at this point in the history
scene.capture handles label text
  • Loading branch information
BruceSherwood committed May 23, 2021
2 parents 9b73ec7 + caca878 commit 5fb1a65
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
4 changes: 3 additions & 1 deletion labextension/vpython/src/glowcommlab.js
Expand Up @@ -961,7 +961,9 @@ async function handle_methods(dmeth) {
if (val === null) obj.camera.follow(null)
else obj.camera.follow(glowObjs[val])
} else if (method === "capture") {
await obj.capture(val)
// val has the form "Tname.png" (display labels) or "Fname.png" (do not display labels)
let TF = (val[0] == 'T') ? true: false
await obj.capture(val.slice(1), TF)
} else if (method === 'waitfor') {
waitfor_canvas = idx
waitfor_options = val
Expand Down
13 changes: 10 additions & 3 deletions vpython/vpython.py
Expand Up @@ -120,7 +120,7 @@ def _encode_attr2(sendval, val, ismethods):
if sendval in __vecattrs: # it would be good to do some kind of compression of doubles
s += "{:.16G},{:.16G},{:.16G}".format(val[0], val[1], val[2])
elif sendval in __textattrs:
# '\n' doesn't survive JSON transmission, so we replace '\n' with '<br>' (and convert back in glowcomm)
# '\n' doesn't survive JSON transmission, so we replace '\n' with '<br>' (and convert back in glowcomm)
if not isinstance(val, str): val = print_to_string(val)
val = val.replace('\n', '<br>')
s += val
Expand Down Expand Up @@ -3138,10 +3138,17 @@ def pixel_to_world(self):
def pixel_to_world(self, value):
raise AttributeError('pixel_to_world is read-only')

def capture(self, filename):
def capture(self, *s):
if len(s) == 0:
raise AttributeError('scene.capture requires at least one argument.')
filename = s[0]
if not isinstance(filename, str): raise AttributeError('A capture file name must be a string.')
if '.png' not in filename: filename += '.png'
self.addmethod('capture', filename)
include_labels = "T"
if len(s) == 2:
if s[1] == True: include_labels = "T"
else: include_labels = "F"
self.addmethod('capture', include_labels+filename)

@property
def objects(self):
Expand Down
2 changes: 1 addition & 1 deletion vpython/vpython_libraries/glow.min.js

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion vpython/vpython_libraries/glowcomm.html
Expand Up @@ -540,6 +540,7 @@
}
*/


if (data.cmds !== undefined && data.cmds.length > 0) handle_cmds(data.cmds)
if (data.methods !== undefined && data.methods.length > 0) handle_methods(data.methods)
if (data.attrs !== undefined && data.attrs.length > 0) handle_attrs(data.attrs)
Expand Down Expand Up @@ -871,7 +872,9 @@
if (val === null) obj.camera.follow(null)
else obj.camera.follow(glowObjs[val])
} else if (method === "capture") {
await obj.capture(val)
// val has the form "Tname.png" (display labels) or "Fname.png" (do not display labels)
let TF = (val[0] == 'T') ? true: false
await obj.capture(val.slice(1), TF)
} else if (method === 'waitfor') {
waitfor_canvas = idx
waitfor_options = val
Expand Down
4 changes: 3 additions & 1 deletion vpython/vpython_libraries/glowcomm.js
Expand Up @@ -921,7 +921,9 @@ async function handle_methods(dmeth) {
if (val === null) obj.camera.follow(null)
else obj.camera.follow(glowObjs[val])
} else if (method === "capture") {
await obj.capture(val)
// val has the form "Tname.png" (display labels) or "Fname.png" (do not display labels)
let TF = (val[0] == 'T') ? true: false
await obj.capture(val.slice(1), TF)
} else if (method === 'waitfor') {
waitfor_canvas = idx
waitfor_options = val
Expand Down

0 comments on commit 5fb1a65

Please sign in to comment.