diff --git a/photoboite.py b/photoboite.py index 8c7918a..e3f925d 100755 --- a/photoboite.py +++ b/photoboite.py @@ -8,7 +8,6 @@ try: class Camera: def __init__(self, rect): self.rect = rect - self.img = pygame.transform.scale(pygame.image.load('tournesol.jpg'), (self.rect.width, self.rect.height)) self.camera = picamera.PiCamera() self.camera.led = False self.camera.resolution = (self.rect.width, self.rect.height) @@ -18,8 +17,11 @@ try: self.camera.close() def take(self, name): - self.camera.capture(name + '.jpg') - print('Take picture! ' + name) + name = name + '.jpg' + self.camera.resolution = (3280, 2464) + self.camera.capture(name) + self.camera.resolution = (self.rect.width, self.rect.height) + return name def stream(self): stream = io.BytesIO() @@ -46,7 +48,7 @@ except: def take(self, name): print('Take picture! ' + name) - return self.img + return 'tournesol.jpg' def draw_on(self, screen): screen.blit(self.img, self.rect) @@ -54,24 +56,13 @@ except: class Button: - def __init__(self, size, topleft): - self.up_image = pygame.image.load('button-up.png').convert_alpha() - self.up_image = pygame.transform.smoothscale(self.up_image, (size, size)) - - self.down_image = pygame.image.load('button-down.png').convert_alpha() - self.down_image = pygame.transform.smoothscale(self.down_image, (size, size)) - - self.rect = self.up_image.get_rect() - self.rect.topleft = topleft - + def __init__(self, rect): + self.rect = rect self.pressed = False self.enabled = True def draw_on(self, screen): - if self.pressed: - screen.blit(self.down_image, self.rect) - else: - screen.blit(self.up_image, self.rect) + pass def is_pressed(self, pos): return self.rect.collidepoint(pos) @@ -90,7 +81,16 @@ class CaptureButton(Button): countdown = 3 def __init__(self, size, topleft, photoboite): - super(CaptureButton, self).__init__(size, topleft) + self.up_image = pygame.image.load('button-up.png').convert_alpha() + self.up_image = pygame.transform.smoothscale(self.up_image, (size, size)) + + self.down_image = pygame.image.load('button-down.png').convert_alpha() + self.down_image = pygame.transform.smoothscale(self.down_image, (size, size)) + + rect = self.up_image.get_rect() + rect.topleft = topleft + + super(CaptureButton, self).__init__(rect) self.photoboite = photoboite self.elapsed = 0 self.capture_mode = False @@ -107,7 +107,10 @@ class CaptureButton(Button): def draw_on(self, screen): if self.enabled: - super(CaptureButton, self).draw_on(screen) + if self.pressed: + screen.blit(self.down_image, self.rect) + else: + screen.blit(self.up_image, self.rect) if self.capture_mode and self.elapsed < CaptureButton.countdown: screen.blit(self.background, self.background_rect.topleft) @@ -142,14 +145,17 @@ class CaptureButton(Button): pygame.display.flip() capture.take(self.photoboite.camera) - pygame.time.wait(1000) + pygame.time.wait(600) for photo in capture.photos: + self.photoboite.screen.blit(photo.capture, (81, 0)) self.photoboite.screen.blit(self.photo_film, (0, 0)) pygame.display.flip() - pygame.time.wait(1000) + pygame.time.wait(800) self.photoboite.event() + pygame.time.wait(200) + pygame.event.set_allowed((pygame.MOUSEBUTTONDOWN, pygame.MOUSEBUTTONUP)) self.capture_mode = False self.enabled = True @@ -172,7 +178,7 @@ class Photo: def take(self, camera): self.name = "%s-%04d-%04d" % (time.strftime('%Y%m%d-%H%M%S'), self.cid, self.uid) - camera.take(self.name) + self.capture = pygame.transform.smoothscale(pygame.image.load(camera.take(self.name)), (638, 480)) return self