|
|
|
@ -1,24 +1,26 @@
|
|
|
|
|
import pygame, pygame.camera
|
|
|
|
|
import picamera
|
|
|
|
|
import picamera.array
|
|
|
|
|
from pygame import *
|
|
|
|
|
|
|
|
|
|
def render_text_line(image, color, font, text, pos = (0,0)):
|
|
|
|
|
|
|
|
|
|
def render_text_line(image, color, font, text, pos=(0, 0)):
|
|
|
|
|
render_text = font.render(text, 1, color)
|
|
|
|
|
image.blit(render_text, pos)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Screen:
|
|
|
|
|
"""The Screen for the Terminal"""
|
|
|
|
|
|
|
|
|
|
def __init__(self, size = (100,100), title = "Screen"):
|
|
|
|
|
def __init__(self, size=(100, 100), title="Screen"):
|
|
|
|
|
pygame.display.init()
|
|
|
|
|
self.size = size
|
|
|
|
|
self.screen = pygame.display.set_mode(self.size)
|
|
|
|
|
pygame.display.set_caption(title)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def refresh(self, rectangles=None):
|
|
|
|
|
pygame.display.update(rectangles)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def toggle_fullscreen(self):
|
|
|
|
|
if self.fullscreen:
|
|
|
|
|
pygame.display.set_mode(self.size)
|
|
|
|
@ -38,15 +40,14 @@ class List(pygame.sprite.Sprite):
|
|
|
|
|
pygame.font.init()
|
|
|
|
|
self.size = size
|
|
|
|
|
self.image = pygame.Surface(self.size)
|
|
|
|
|
self.image.fill((0,0,0))
|
|
|
|
|
self.image.fill((0, 0, 0))
|
|
|
|
|
self.rect = self.image.get_rect()
|
|
|
|
|
self.rect.topleft = position
|
|
|
|
|
self.font = pygame.font.SysFont('Arial',25)
|
|
|
|
|
self.font = pygame.font.SysFont('Arial', 25)
|
|
|
|
|
self.dict = {}
|
|
|
|
|
self.updated = True
|
|
|
|
|
self.txtsize = self.font.size('__||__')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def set_dict(self, dict):
|
|
|
|
|
self.dict = dict
|
|
|
|
|
self.updated = True
|
|
|
|
@ -57,10 +58,12 @@ class List(pygame.sprite.Sprite):
|
|
|
|
|
|
|
|
|
|
for key in self.dict.keys():
|
|
|
|
|
line = '{}: {}'.format(key, self.dict[key])
|
|
|
|
|
render_text_line(self.image, (255, 255, 255), self.font, line, (0,height))
|
|
|
|
|
height+=self.txtsize[1]
|
|
|
|
|
render_text_line(self.image, (255, 255, 255), self.font, line, (0, height))
|
|
|
|
|
height += self.txtsize[1]
|
|
|
|
|
|
|
|
|
|
self.updated = False
|
|
|
|
|
print('update function called')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PiCamera(pygame.sprite.Sprite):
|
|
|
|
|
"""The Picamera as pygame cam"""
|
|
|
|
@ -68,8 +71,7 @@ class PiCamera(pygame.sprite.Sprite):
|
|
|
|
|
def __init__(self, position, size):
|
|
|
|
|
pygame.sprite.Sprite.__init__(self)
|
|
|
|
|
pygame.camera.init()
|
|
|
|
|
cam_list = pygame.camera.list_cameras()
|
|
|
|
|
camera = pygame.camera.Camera(cam_list[0], size)
|
|
|
|
|
camera = picamera.PiCamera()
|
|
|
|
|
self.camera = camera
|
|
|
|
|
self.size = size
|
|
|
|
|
self.image = pygame.Surface(self.size)
|
|
|
|
@ -78,4 +80,7 @@ class PiCamera(pygame.sprite.Sprite):
|
|
|
|
|
self.rect.topleft = position
|
|
|
|
|
|
|
|
|
|
def update(self, *args):
|
|
|
|
|
self.camera.get_image(self.image)
|
|
|
|
|
print('updating camera')
|
|
|
|
|
with picamera.array.PiRGBArray(self.camera, size=self.size) as output:
|
|
|
|
|
self.camera.capture(output, 'rgb', resize=self.size)
|
|
|
|
|
print(output)
|