Move button images in CaptureButton
parent
933f63d146
commit
00c0c98f56
|
@ -8,7 +8,6 @@ try:
|
||||||
class Camera:
|
class Camera:
|
||||||
def __init__(self, rect):
|
def __init__(self, rect):
|
||||||
self.rect = 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 = picamera.PiCamera()
|
||||||
self.camera.led = False
|
self.camera.led = False
|
||||||
self.camera.resolution = (self.rect.width, self.rect.height)
|
self.camera.resolution = (self.rect.width, self.rect.height)
|
||||||
|
@ -18,8 +17,11 @@ try:
|
||||||
self.camera.close()
|
self.camera.close()
|
||||||
|
|
||||||
def take(self, name):
|
def take(self, name):
|
||||||
self.camera.capture(name + '.jpg')
|
name = name + '.jpg'
|
||||||
print('Take picture! ' + name)
|
self.camera.resolution = (3280, 2464)
|
||||||
|
self.camera.capture(name)
|
||||||
|
self.camera.resolution = (self.rect.width, self.rect.height)
|
||||||
|
return name
|
||||||
|
|
||||||
def stream(self):
|
def stream(self):
|
||||||
stream = io.BytesIO()
|
stream = io.BytesIO()
|
||||||
|
@ -46,7 +48,7 @@ except:
|
||||||
|
|
||||||
def take(self, name):
|
def take(self, name):
|
||||||
print('Take picture! ' + name)
|
print('Take picture! ' + name)
|
||||||
return self.img
|
return 'tournesol.jpg'
|
||||||
|
|
||||||
def draw_on(self, screen):
|
def draw_on(self, screen):
|
||||||
screen.blit(self.img, self.rect)
|
screen.blit(self.img, self.rect)
|
||||||
|
@ -54,24 +56,13 @@ except:
|
||||||
|
|
||||||
|
|
||||||
class Button:
|
class Button:
|
||||||
def __init__(self, size, topleft):
|
def __init__(self, rect):
|
||||||
self.up_image = pygame.image.load('button-up.png').convert_alpha()
|
self.rect = rect
|
||||||
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
|
|
||||||
|
|
||||||
self.pressed = False
|
self.pressed = False
|
||||||
self.enabled = True
|
self.enabled = True
|
||||||
|
|
||||||
def draw_on(self, screen):
|
def draw_on(self, screen):
|
||||||
if self.pressed:
|
pass
|
||||||
screen.blit(self.down_image, self.rect)
|
|
||||||
else:
|
|
||||||
screen.blit(self.up_image, self.rect)
|
|
||||||
|
|
||||||
def is_pressed(self, pos):
|
def is_pressed(self, pos):
|
||||||
return self.rect.collidepoint(pos)
|
return self.rect.collidepoint(pos)
|
||||||
|
@ -90,7 +81,16 @@ class CaptureButton(Button):
|
||||||
countdown = 3
|
countdown = 3
|
||||||
|
|
||||||
def __init__(self, size, topleft, photoboite):
|
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.photoboite = photoboite
|
||||||
self.elapsed = 0
|
self.elapsed = 0
|
||||||
self.capture_mode = False
|
self.capture_mode = False
|
||||||
|
@ -107,7 +107,10 @@ class CaptureButton(Button):
|
||||||
|
|
||||||
def draw_on(self, screen):
|
def draw_on(self, screen):
|
||||||
if self.enabled:
|
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:
|
if self.capture_mode and self.elapsed < CaptureButton.countdown:
|
||||||
screen.blit(self.background, self.background_rect.topleft)
|
screen.blit(self.background, self.background_rect.topleft)
|
||||||
|
|
||||||
|
@ -142,14 +145,17 @@ class CaptureButton(Button):
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
|
|
||||||
capture.take(self.photoboite.camera)
|
capture.take(self.photoboite.camera)
|
||||||
pygame.time.wait(1000)
|
pygame.time.wait(600)
|
||||||
|
|
||||||
for photo in capture.photos:
|
for photo in capture.photos:
|
||||||
|
self.photoboite.screen.blit(photo.capture, (81, 0))
|
||||||
self.photoboite.screen.blit(self.photo_film, (0, 0))
|
self.photoboite.screen.blit(self.photo_film, (0, 0))
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
pygame.time.wait(1000)
|
pygame.time.wait(800)
|
||||||
self.photoboite.event()
|
self.photoboite.event()
|
||||||
|
|
||||||
|
pygame.time.wait(200)
|
||||||
|
|
||||||
pygame.event.set_allowed((pygame.MOUSEBUTTONDOWN, pygame.MOUSEBUTTONUP))
|
pygame.event.set_allowed((pygame.MOUSEBUTTONDOWN, pygame.MOUSEBUTTONUP))
|
||||||
self.capture_mode = False
|
self.capture_mode = False
|
||||||
self.enabled = True
|
self.enabled = True
|
||||||
|
@ -172,7 +178,7 @@ class Photo:
|
||||||
|
|
||||||
def take(self, camera):
|
def take(self, camera):
|
||||||
self.name = "%s-%04d-%04d" % (time.strftime('%Y%m%d-%H%M%S'), self.cid, self.uid)
|
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
|
return self
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue