MCPcopy Create free account
hub / github.com/vispy/vispy / TestingCanvas

Function TestingCanvas

vispy/testing/_testing.py:307–350  ·  view source on GitHub ↗

Avoid importing scene until necessary.

(bgcolor='black', size=(100, 100), dpi=None, decorate=None,
                  **kwargs)

Source from the content-addressed store, hash-verified

305
306@nottest
307def TestingCanvas(bgcolor='black', size=(100, 100), dpi=None, decorate=None,
308 **kwargs):
309 """Avoid importing scene until necessary."""
310 # On Windows decorations can force windows to be an incorrect size
311 # (e.g., instead of 100x100 they will be 100x248), having no
312 # decorations works around this
313 from ..scene import SceneCanvas
314
315 class TestingCanvas(SceneCanvas):
316 def __init__(self, bgcolor, size, dpi, decorate, **kwargs):
317 self._entered = False
318 self._wanted_vp = None
319 if decorate is None:
320 # deal with GLFW's problems
321 from vispy.app import use_app
322 app = use_app()
323 if _bad_glfw_decorate(app):
324 decorate = True
325 else:
326 decorate = False
327 SceneCanvas.__init__(self, bgcolor=bgcolor, size=size,
328 dpi=dpi, decorate=decorate,
329 **kwargs)
330
331 def __enter__(self):
332 SceneCanvas.__enter__(self)
333 # sometimes our window can be larger than our requsted draw
334 # area (e.g. on Windows), and this messes up our tests that
335 # typically use very small windows. Here we "fix" it.
336 scale = np.array(self.physical_size) / np.array(self.size, float)
337 scale = int(np.round(np.mean(scale)))
338 self._wanted_vp = 0, 0, size[0] * scale, size[1] * scale
339 self.context.set_state(clear_color=self._bgcolor)
340 self.context.set_viewport(*self._wanted_vp)
341 self._entered = True
342 return self
343
344 def draw_visual(self, visual, event=None):
345 if not self._entered:
346 return
347 SceneCanvas.draw_visual(self, visual, event)
348 self.context.finish()
349
350 return TestingCanvas(bgcolor, size, dpi, decorate, **kwargs)
351
352
353@nottest

Callers 15

test_perspective_renderFunction · 0.90
test_panzoom_centerFunction · 0.90
test_canvas_renderFunction · 0.90
test_picking_basicFunction · 0.90
test_blend_presetsFunction · 0.90
test_topologyFunction · 0.90
test_colorbar_widgetFunction · 0.90
test_image_complexFunction · 0.90
test_histogramFunction · 0.90
test_windbarb_drawFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…