def test_unfocus(self, _init_pygame, default_ui_manager):
        text_entry = UITextEntryLine(relative_rect=pygame.Rect(
            100, 100, 200, 30),
                                     manager=default_ui_manager)

        text_entry.unfocus()

        assert text_entry.image is not None
예제 #2
0
 def move(self, squares: Squares, win: pygame.Surface, board):
     if not isinstance(squares, list):
         raise TypeError("The squares arguement must be a list(), not " +
                         str(type(squares))[8:-1] + "().")
     limiting_pos = [[self.min_x, max_x], [self.min_y, self.max_y]]
     max_length = 1
     selected = False
     direction = 0
     max_direction = 8
     direction_offset = 0
     pygame.font.init()
     while (self.x in limiting_pos[0] and self.y in limiting_pos[1]):
         if len(self.pieces) > max_length:
             font = pygame.font.SysFont("comicsans", 40)
             text = font.render(
                 "You can't select that piece because you have already selected a piece. You must either move the already selected piece or unselect it."
             )
             win.blit(txt, ((self.max_x - txt.get_width()) / 2,
                            (self.max_y - txt.get_height()) / 2))
         for event in pygame.event.get():
             if event.type == pygame.K_SPACE or event.type == pygame.K_RETURN:
                 if (self.x, self.y, self.name) in pieces:
                     selected = False
                     self.pieces.pop()
                 else:
                     selected = True
                     self.pieces.append((self.x, self.y, self.name))
         keys = pygame.key.get_pressed()
         if ((keys[pygame.K_RALT] and keys[pygame.K_k]) or
             (keys[pygame.K_LALT] and keys[pygame.K_k])) and not (
                 (keys[pygame.K_RALT] and keys[pygame.K_k]) and
                 (keys[pygame.K_LALT] and keys[pygame.K_k])):
             active = False
             text_input_line = UITextEntryLine(pygame.pygame.Rect(
                 self.x, self.y, self.square_width, self.square_height),
                                               manager=MANAGER)
             text_input_line.disable()
             text_input_line.set_allowed_characters(
                 [d for d in string.digits[1:9]] +
                 [l for l in string.ascii_lowercase[:8]])
             text_input_line.set_text_length_limit(2)
             if active:
                 text_input_line.enable()
                 text_input_line.focus()
                 if keys[pygame.K_RETURN]:
                     text = text_input_line.get_text()
                     file = text[0]
                     rank = int(text[1])
                     move_set = self.get_possible_positions(
                         text[0] + str(text[1]), squares)
                     piece = self.find_piece_from_move_set(
                         move_set, squares)
                     if piece:
                         self.x, self.y = get_window_pos(
                             self.file, self.rank, self.possible_files)
                         original_x, original_y = self.x, self.y
                     else:
                         text = font.render(
                             "You can't move there. There is no knight nearby."
                         )
                         win.blit(text, (self.x, self.y))
             else:
                 text_input_line.disable()
                 text_input_line.unfocus()
         while direction < max_direction:
             self.attacked_pieces = self._update_attacked_pieces(
                 self.x, self.y, self.square_width, self.square_height,
                 squares)
             direction += 1
         direction = 0
     return self.attacked_pieces, (self.piece_x,
                                   self.piece_y), (original_x,
                                                   original_y), self