Skip to content

Commit f3a2871

Browse files
authored
Merge pull request #165 from 0dminnimda/improve-vpython.canvas.capture
Improve the `capture` implementation and fix its bugs
2 parents c47d45d + 2eb3511 commit f3a2871

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

vpython/vpython.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3138,17 +3138,15 @@ 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, *s):
3142-
if len(s) == 0:
3143-
raise AttributeError('scene.capture requires at least one argument.')
3144-
filename = s[0]
3145-
if not isinstance(filename, str): raise AttributeError('A capture file name must be a string.')
3146-
if '.png' not in filename: filename += '.png'
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)
3141+
def capture(self, filename, capture_labels=True):
3142+
if not isinstance(filename, str):
3143+
raise TypeError("'filename' for Capture must be a string.")
3144+
3145+
if filename.endswith(".png"):
3146+
filename += ".png"
3147+
3148+
include_labels = "T" if capture_labels else "F"
3149+
self.addmethod("capture", include_labels + filename)
31523150

31533151
@property
31543152
def objects(self):

0 commit comments

Comments
 (0)