Skip to content

Commit d79a650

Browse files
authored
EHN: Add auto offscreen mode (#245)
1 parent 23c21b1 commit d79a650

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

surfer/viz.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,17 @@ def _make_viewer(figure, n_row, n_col, title, scene_size, offscreen,
200200
if figure is None:
201201
# spawn scenes
202202
h, w = scene_size
203-
if offscreen is True:
203+
if offscreen == 'auto':
204+
offscreen = mlab.options.offscreen
205+
if offscreen:
204206
orig_val = mlab.options.offscreen
205-
mlab.options.offscreen = True
206-
with warnings.catch_warnings(record=True): # traits
207-
figures = [[mlab.figure(size=(h / n_row, w / n_col))
208-
for _ in range(n_col)] for __ in range(n_row)]
209-
mlab.options.offscreen = orig_val
207+
try:
208+
mlab.options.offscreen = True
209+
with warnings.catch_warnings(record=True): # traits
210+
figures = [[mlab.figure(size=(h / n_row, w / n_col))
211+
for _ in range(n_col)] for __ in range(n_row)]
212+
finally:
213+
mlab.options.offscreen = orig_val
210214
_v = None
211215
else:
212216
# Triage: don't make TraitsUI if we don't have to
@@ -356,10 +360,11 @@ class Brain(object):
356360
surface where hemispheres typically overlap (Default: True)
357361
show_toolbar : bool
358362
If True, toolbars will be shown for each view.
359-
offscreen : bool
363+
offscreen : bool | str
360364
If True, rendering will be done offscreen (not shown). Useful
361365
mostly for generating images or screenshots, but can be buggy.
362-
Use at your own risk.
366+
Use at your own risk. Can be "auto" (default) to use
367+
``mlab.options.offscreen``.
363368
interaction : str
364369
Can be "trackball" (default) or "terrain", i.e. a turntable-style
365370
camera.
@@ -387,7 +392,7 @@ def __init__(self, subject_id, hemi, surf, title=None,
387392
cortex="classic", alpha=1.0, size=800, background="black",
388393
foreground=None, figure=None, subjects_dir=None,
389394
views=['lat'], offset=True, show_toolbar=False,
390-
offscreen=False, interaction='trackball', units='mm'):
395+
offscreen='auto', interaction='trackball', units='mm'):
391396

392397
if not isinstance(interaction, string_types) or \
393398
interaction not in ('trackball', 'terrain'):

0 commit comments

Comments
 (0)