示例#1
0
    def show(self):
        if self.__window is not None:
            raise RuntimeError("Window is already shown.")

        frames = PreviewFrame.load_all(self.path)
        if len(frames) == 0:
            logger.warning(
                "No frames where found. Therefore, the preview is not shown.")
            return

        frame_index = 0

        def on_key(window, key, _scancode, action, _mods):
            nonlocal frame_index

            # Respond only to key press
            if action == glfw.GLFW_RELEASE:
                return

            if key == glfw.GLFW_KEY_LEFT and frame_index > 0:
                frame_index -= 1
                PreviewWindow._draw_frame(window, self.path, frames,
                                          frame_index, False)
            elif key == glfw.GLFW_KEY_RIGHT and frame_index < len(frames) - 1:
                frame_index += 1
                PreviewWindow._draw_frame(window, self.path, frames,
                                          frame_index, False)

        def on_close(_window):
            self.parent.notify_all(
                {"subject": Preview.NOTIFICATION_PREVIEW_CLOSE})

        # TODO: The code assumes for simplicity that both eye images run with the same resolution.
        first_frame = frames[0][0].load(self.path)
        with PreviewWindow.WindowContextManager() as active_window:
            glfw.glfwWindowHint(glfw.GLFW_RESIZABLE, False)
            glfw.glfwWindowHint(glfw.GLFW_ICONIFIED, False)
            glfw.glfwWindowHint(GLFW_FLOATING, True)

            self.__window = glfw.glfwCreateWindow(
                first_frame.shape[1] * len(frames[0]),
                first_frame.shape[0],
                PreviewWindow.WINDOW_NAME,
                monitor=None,
                share=active_window,
            )

            # Reset default
            glfw.glfwWindowHint(glfw.GLFW_RESIZABLE, True)
            glfw.glfwWindowHint(glfw.GLFW_ICONIFIED, True)
            glfw.glfwWindowHint(GLFW_FLOATING, False)

            glfw.glfwSetKeyCallback(self.__window, on_key)
            glfw.glfwSetWindowCloseCallback(self.__window, on_close)
            glfw.glfwMakeContextCurrent(self.__window)
            basic_gl_setup()
            glfw.glfwSwapInterval(0)

        PreviewWindow._draw_frame(self.__window, self.path, frames, 0, True)
示例#2
0
 def _register_callbacks(self, window):
     glfw.glfwSetWindowSizeCallback(window, self._on_set_window_size)
     glfw.glfwSetWindowPosCallback(window, self._on_set_window_pos)
     glfw.glfwSetFramebufferSizeCallback(window, self._on_set_frame_buffer_size)
     glfw.glfwSetMouseButtonCallback(window, self._on_set_mouse_button)
     glfw.glfwSetCursorPosCallback(window, self._on_set_cursor_pos)
     glfw.glfwSetScrollCallback(window, self._on_set_scroll)
     glfw.glfwSetWindowCloseCallback(window, self._on_set_window_close)
示例#3
0
 def _register_callbacks(self, window):
     glfw.glfwSetWindowSizeCallback(window, self._on_set_window_size)
     glfw.glfwSetWindowPosCallback(window, self._on_set_window_pos)
     glfw.glfwSetFramebufferSizeCallback(window, self._on_set_frame_buffer_size)
     glfw.glfwSetMouseButtonCallback(window, self._on_set_mouse_button)
     glfw.glfwSetCursorPosCallback(window, self._on_set_cursor_pos)
     glfw.glfwSetScrollCallback(window, self._on_set_scroll)
     glfw.glfwSetWindowCloseCallback(window, self._on_set_window_close)
示例#4
0
文件: gui.py 项目: zcyroot/pupil
    def open_window(self):
        if not self._window:

            monitor = None
            # open with same aspect ratio as surface
            surface_aspect_ratio = (self.surface.real_world_size["x"] /
                                    self.surface.real_world_size["y"])
            win_h = 640
            win_w = int(win_h / surface_aspect_ratio)

            self._window = glfw.glfwCreateWindow(
                win_h,
                win_w,
                "Reference Surface: " + self.surface.name,
                monitor=monitor,
                share=glfw.glfwGetCurrentContext(),
            )

            glfw.glfwSetWindowPos(
                self._window,
                self.window_position_default[0],
                self.window_position_default[1],
            )

            self.trackball = gl_utils.trackball.Trackball()
            self.input = {"down": False, "mouse": (0, 0)}

            # Register callbacks
            glfw.glfwSetFramebufferSizeCallback(self._window, self.on_resize)
            glfw.glfwSetKeyCallback(self._window, self.on_window_key)
            glfw.glfwSetWindowCloseCallback(self._window, self.on_close)
            glfw.glfwSetMouseButtonCallback(self._window,
                                            self.on_window_mouse_button)
            glfw.glfwSetCursorPosCallback(self._window, self.on_pos)
            glfw.glfwSetScrollCallback(self._window, self.on_scroll)

            self.on_resize(self._window,
                           *glfw.glfwGetFramebufferSize(self._window))

            # gl_state settings
            active_window = glfw.glfwGetCurrentContext()
            glfw.glfwMakeContextCurrent(self._window)
            gl_utils.basic_gl_setup()
            gl_utils.make_coord_system_norm_based()

            # refresh speed settings
            glfw.glfwSwapInterval(0)

            glfw.glfwMakeContextCurrent(active_window)
示例#5
0
文件: gui.py 项目: pupil-labs/pupil
    def open_window(self):
        if not self._window:

            monitor = None
            # open with same aspect ratio as surface
            surface_aspect_ratio = (
                self.surface.real_world_size["x"] / self.surface.real_world_size["y"]
            )
            win_h = 640
            win_w = int(win_h / surface_aspect_ratio)

            self._window = glfw.glfwCreateWindow(
                win_h,
                win_w,
                "Reference Surface: " + self.surface.name,
                monitor=monitor,
                share=glfw.glfwGetCurrentContext(),
            )

            glfw.glfwSetWindowPos(
                self._window,
                self.window_position_default[0],
                self.window_position_default[1],
            )

            self.trackball = gl_utils.trackball.Trackball()
            self.input = {"down": False, "mouse": (0, 0)}

            # Register callbacks
            glfw.glfwSetFramebufferSizeCallback(self._window, self.on_resize)
            glfw.glfwSetKeyCallback(self._window, self.on_window_key)
            glfw.glfwSetWindowCloseCallback(self._window, self.on_close)
            glfw.glfwSetMouseButtonCallback(self._window, self.on_window_mouse_button)
            glfw.glfwSetCursorPosCallback(self._window, self.on_pos)
            glfw.glfwSetScrollCallback(self._window, self.on_scroll)

            self.on_resize(self._window, *glfw.glfwGetFramebufferSize(self._window))

            # gl_state settings
            active_window = glfw.glfwGetCurrentContext()
            glfw.glfwMakeContextCurrent(self._window)
            gl_utils.basic_gl_setup()
            gl_utils.make_coord_system_norm_based()

            # refresh speed settings
            glfw.glfwSwapInterval(0)

            glfw.glfwMakeContextCurrent(active_window)