Exemple #1
0
 def __stack_windows(self) -> ndarray:
     final = self.__windows[0].current_matrix.copy()
     for k in range(1, len(self.__windows)):
         window_coords = self.__windows[k].relative_coordinates
         MatrixUtils.blit_image_inplace(final, self.__windows[k].current_matrix,
                                        window_coords[0], window_coords[1])
     return final
Exemple #2
0
 def test_blit_image_inplace(self):
     MatrixUtils.blit_image_inplace(self.destination_image, self.source_image, 1, 1)
     result_single_channel = np.array([[0, 0, 0, 0],
                                       [0, 1, 1, 0],
                                       [0, 1, 1, 0],
                                       [0, 0, 0, 0]])
     result = np.dstack((result_single_channel, result_single_channel, result_single_channel))
     self.assertTrue(np.array_equal(result, self.destination_image))
Exemple #3
0
    def click(self,
              click_coordinates: ndarray,
              parent_coordinates: ndarray = None
              ) -> (int, bool, ndarray, ndarray):
        click_on_window = False
        if self.visible:
            if MatrixUtils.includes_point(click_coordinates,
                                          self.relative_coordinates,
                                          self.width, self.height):
                click_on_window = True
                for child in self.children:
                    reward, click_on_child, matrix, coords = child.click(
                        click_coordinates, self.relative_coordinates)
                    if click_on_child:
                        MatrixUtils.blit_image_inplace(self.__current_matrix,
                                                       matrix, coords[0],
                                                       coords[1])
                        return reward, click_on_window, matrix, coords + self.relative_coordinates

        return 0, click_on_window, None, None
Exemple #4
0
    def step(self, action: ndarray) -> (ndarray, int, bool):
        reward = 0
        number_of_windows_to_be_removed = 0

        # Click on windows starting with the topmost window down to the window at the bottom
        # Continue clicking only while the current window was not clicked AND
        # the current window is not modal
        for i in range(-1, -len(self.__windows) - 1, -1):
            index = i + number_of_windows_to_be_removed
            reward, window_includes_point, clicked_child_component_matrix, clicked_child_component_coords = \
                self.__windows[index].click(action)
            if window_includes_point:
                if clicked_child_component_matrix is not None:
                    # Blit the changed component directly on the frame buffer, only if the clicked component is
                    # in the topmost window
                    if not self.__should_re_stack:
                        MatrixUtils.blit_image_inplace(self.__frame_buffer,
                                                       clicked_child_component_matrix,
                                                       clicked_child_component_coords[0],
                                                       clicked_child_component_coords[1])
                break
            else:
                if self.__windows[index].modal:
                    break
                elif self.__windows[index].auto_close:
                    # Save the removed window for future reference and continue with the loop
                    removed_window = self.__remove_window()
                    self.__windows_to_be_removed.append(removed_window)
                    number_of_windows_to_be_removed += 1

        # Redraw all windows by stacking them up from the bottom to the top, if needed
        if self.__should_re_stack:
            self.__frame_buffer = self.__stack_windows()

        # Reset internal state
        self.__should_re_stack = False
        self.__windows_to_be_removed.clear()
        return self.__frame_buffer, reward, self.__done, None
Exemple #5
0
 def __add_window(self, window: Window):
     self.__windows.append(window)
     MatrixUtils.blit_image_inplace(self.__frame_buffer,
                                    window.current_matrix,
                                    window.relative_coordinates[0], window.relative_coordinates[1])
Exemple #6
0
 def draw_self(self, parent_matrix: ndarray):
     if self.visible:
         return MatrixUtils.blit_image_inplace(parent_matrix,
                                               self._select_matrix(),
                                               self.relative_coordinates[0],
                                               self.relative_coordinates[1])