Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _platform_init(self, max_width, max_height):
"""Initializes this context.
Args:
max_width: Integer specifying the maximum framebuffer width in pixels.
max_height: Integer specifying the maximum framebuffer height in pixels.
"""
glfw.window_hint(glfw.VISIBLE, 0)
glfw.window_hint(glfw.DOUBLEBUFFER, 0)
self._context = glfw.create_window(width=max_width, height=max_height,
title='Invisible window', monitor=None,
share=None)
# This reference prevents `glfw.destroy_window` from being garbage-collected
# before the last window is destroyed, otherwise we may get
# `AttributeError`s when the `__del__` method is later called.
self._destroy_window = glfw.destroy_window
def _platform_init(self, width, height):
glfw.window_hint(glfw.SAMPLES, 4)
glfw.window_hint(glfw.VISIBLE, 1)
glfw.window_hint(glfw.DOUBLEBUFFER, 1)
self._context = glfw.create_window(width, height, self._title, None, None)
self._destroy_window = glfw.destroy_window
def sample_sawyer_reach_push_pick_place():
env = SawyerReachPushPickPlaceEnv()
for i in range(100):
if i % 100 == 0:
env.reset()
env.step(np.array([0, 1, 1]))
env.render()
glfw.destroy_window(env.viewer.window)
def sample_sawyer_pick_and_place():
env = SawyerPickAndPlaceEnv()
env.reset()
for _ in range(200):
env.render()
env.step(env.action_space.sample())
time.sleep(0.05)
glfw.destroy_window(env.viewer.window)
def close(self):
"""Close the window and uninitialize the resources
"""
# Test if the window has already been closed
if glfw.window_should_close(self.winHandle):
return
_hw_handle = None
try:
self.setMouseVisibility(True)
glfw.set_window_should_close(self.winHandle, 1)
glfw.destroy_window(self.winHandle)
except Exception:
pass
# If iohub is running, inform it to stop looking for this win id
# when filtering kb and mouse events (if the filter is enabled of
# course)
try:
if IOHUB_ACTIVE and _hw_handle:
from psychopy.iohub.client import ioHubConnection
conn = ioHubConnection.ACTIVE_CONNECTION
conn.unregisterWindowHandles(_hw_handle)
except Exception:
pass
def sample_sawyer_sweep():
env = SawyerSweepEnv(fix_goal=True)
for i in range(200):
if i % 100 == 0:
env.reset()
env.step(env.action_space.sample())
env.render()
glfw.destroy_window(env.viewer.window)
def close(self):
if self.viewer is not None:
glfw.destroy_window(self.viewer.window)
self.viewer = None
def teardown(self):
if self.m:
self.m.teardown()
self.m = None
if self.window:
glfw.destroy_window(self.window)
self.window = None
def stop(self):
if self.viewer is not None:
v = self.viewer
self.viewer = None
glfw.destroy_window(v.window)
del v