from queue import Queue import pygame from common.colors import FONT_DARK, ORANGE, WHITE from common.constants import COLUMNS, GRID_CELL_PADDING, GRID_CELL_SIZE, BORDER_WIDTH, BORDER_RADIUS from common.helpers import draw_text class Logs: def __init__(self, screen): self.log_queue = Queue(maxsize=7) self.screen = screen def draw(self): x = (GRID_CELL_PADDING + GRID_CELL_SIZE) * COLUMNS + BORDER_WIDTH + 15 y = 470 # background pygame.draw.rect(self.screen, WHITE, pygame.Rect(x, y, 340, 323), 0, BORDER_RADIUS) # title draw_text('LOGS', FONT_DARK, self.screen, x + 120, y + 10, 36) pygame.draw.rect(self.screen, ORANGE, pygame.Rect(x, y + 65, 340, 3)) # texts next_y = y + 90 i = 0 start = len(self.log_queue.queue) - 1 for idx in range(start, -1, -1): draw_text(self.log_queue.queue[idx], FONT_DARK, self.screen, x + 35, next_y + i * 30, 16) i = i + 1 def enqueue_log(self, text): if self.log_queue.full(): self.log_queue.get() self.log_queue.put(text) self.draw()