2022-04-10 18:38:57 +02:00
|
|
|
from queue import Queue
|
|
|
|
|
2022-03-09 16:59:58 +01:00
|
|
|
import pygame
|
|
|
|
|
2022-03-11 19:42:17 +01:00
|
|
|
from common.colors import FONT_DARK, ORANGE, WHITE
|
|
|
|
from common.constants import COLUMNS, GRID_CELL_PADDING, GRID_CELL_WIDTH, BORDER_WIDTH, BORDER_RADIUS
|
|
|
|
from common.helpers import draw_text
|
2022-03-09 16:59:58 +01:00
|
|
|
|
|
|
|
|
|
|
|
class Logs:
|
2022-04-10 18:38:57 +02:00
|
|
|
def __init__(self, screen):
|
|
|
|
self.log_queue = Queue(maxsize=7)
|
|
|
|
self.screen = screen
|
2022-03-09 16:59:58 +01:00
|
|
|
|
2022-04-10 18:38:57 +02:00
|
|
|
def draw(self):
|
2022-03-09 16:59:58 +01:00
|
|
|
x = (GRID_CELL_PADDING + GRID_CELL_WIDTH) * COLUMNS + BORDER_WIDTH + 15
|
|
|
|
y = 470
|
|
|
|
|
|
|
|
# background
|
2022-04-10 18:38:57 +02:00
|
|
|
pygame.draw.rect(self.screen, WHITE, pygame.Rect(x, y, 340, 323), 0, BORDER_RADIUS)
|
2022-03-09 16:59:58 +01:00
|
|
|
|
|
|
|
# title
|
2022-04-10 18:38:57 +02:00
|
|
|
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))
|
2022-03-09 16:59:58 +01:00
|
|
|
|
|
|
|
# texts
|
2022-04-10 18:38:57 +02:00
|
|
|
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()
|