Exemplo n.º 1
0
  def __init__(self, context):
    super().__init__()
    self.on_move = util.QuietSet()
    self.on_click = util.QuietSet()
    self.on_double_click = util.QuietSet()
    self.on_scroll = util.QuietSet()
    self._double_click_detector = base.DoubleClickDetector()
    with context.make_current() as ctx:
      framebuffer_width, window_width = ctx.call(
          self._glfw_setup, context.window)

    self._scale = framebuffer_width * 1.0 / window_width
    self._last_mouse_pos = np.zeros(2, int)

    self._double_clicks = {}
Exemplo n.º 2
0
 def test_add_duplicate_listeners(self):
     subject = util.QuietSet()
     listener = object()
     subject += listener
     self.assertEqual(1, len(subject))
     subject += listener
     self.assertEqual(1, len(subject))
Exemplo n.º 3
0
  def __init__(self, width, height, title, context=None):
    """Instance initializer.

    Args:
      width: Initial window width, in pixels.
      height: Initial window height, in pixels.
      title: A string with a window title.
      context: (Optional) A `render.GLFWContext` instance.

    Raises:
      RuntimeError: If GLFW initialization or window initialization fails.
    """
    super().__init__()
    self._context = context or DoubleBufferedGlfwContext(width, height, title)

    if not self._context.window:
      raise RuntimeError('Failed to create window')

    self._oldsize = None

    with self._context.make_current() as ctx:
      self._fullscreen_quad = ctx.call(self._glfw_setup, self._context.window)
    self.on_files_drop = util.QuietSet()

    self._keyboard = GlfwKeyboard(self._context)
    self._mouse = GlfwMouse(self._context)
Exemplo n.º 4
0
 def test_add_duplicate_listeners(self):
     subject = util.QuietSet()
     listener = object()
     subject += listener
     self.assertLen(subject, 1)
     subject += listener
     self.assertLen(subject, 1)
Exemplo n.º 5
0
    def test_remove_unregistered_listener(self):
        subject = util.QuietSet()
        listeners = [object() for _ in range(3)]
        for listener in listeners:
            subject += listener

        subject -= object()
        self.assertEqual(3, len(subject))
Exemplo n.º 6
0
    def test_remove_listeners(self):
        subject = util.QuietSet()
        listeners = [object() for _ in range(3)]
        for listener in listeners:
            subject += listener

        subject -= listeners[1]
        self.assertEqual(2, len(subject))
Exemplo n.º 7
0
    def setUp(self):
        self.viewport = mock.MagicMock()
        self.mouse = mock.MagicMock()
        self.keyboard = mock.MagicMock()
        self.viewer = viewer.Viewer(self.viewport, self.mouse, self.keyboard)

        self.viewer._render_settings = mock.MagicMock()
        self.physics = mock.MagicMock()
        self.renderer = mock.MagicMock()
        self.renderer.priority_components = util.QuietSet()
Exemplo n.º 8
0
    def __init__(self, environment, policy=None):
        """Instance initializer.

    Args:
      environment: An instance of dm_control.rl.control.Environment.
      policy: Either a callable that accepts a `TimeStep` and returns a numpy
        array of actions conforming to `environment.action_spec()`, or None, in
        which case a default action will be generated for each environment step.
    """
        self.on_error = util.QuietSet()
        self.on_episode_begin = util.QuietSet()
        self.simulation_time_budget = _DEFAULT_MAX_SIM_STEP

        self._state = State.START
        self._simulation_timer = util.Timer()
        self._tracked_simulation_time = 0.0
        self._error_logger = util.ErrorLogger(self.on_error)

        self._env = environment
        self._policy = policy
        self._default_action = _get_default_action(environment.action_spec())
        self._time_step = None
        self._last_action = None
        self.on_physics_changed = util.QuietSet()
Exemplo n.º 9
0
 def test_add_collection_and_individual_listeners(self):
     subject = util.QuietSet()
     subject += object()
     subject += [object() for _ in range(5)]
     subject += object()
     self.assertEqual(7, len(subject))
Exemplo n.º 10
0
 def test_add_collection_of_listeners(self):
     subject = util.QuietSet()
     subject += [object() for _ in range(5)]
     self.assertEqual(5, len(subject))
Exemplo n.º 11
0
 def test_add_listeners(self):
     subject = util.QuietSet()
     listeners = [object() for _ in range(5)]
     for listener in listeners:
         subject += listener
     self.assertEqual(5, len(subject))
Exemplo n.º 12
0
 def __init__(self, context):
   super().__init__()
   with context.make_current() as ctx:
     ctx.call(glfw.set_key_callback, context.window, self._handle_key_event)
   self.on_key = util.QuietSet()
Exemplo n.º 13
0
 def __init__(self):
     """Instance initializer."""
     self.components = util.QuietSet()
     self.screen_capture_components = util.QuietSet()