Prettifying
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# Created by br@re-web.eu, 2015
|
# Created by br@re-web.eu, 2015
|
||||||
|
|
||||||
|
from __future__ import division
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
import time
|
import time
|
||||||
@@ -22,6 +24,9 @@ image_offset = (80,60)
|
|||||||
# Idle image
|
# Idle image
|
||||||
image_idle = "idle.jpg"
|
image_idle = "idle.jpg"
|
||||||
|
|
||||||
|
# Pose image
|
||||||
|
image_pose = "pose.png"
|
||||||
|
|
||||||
# Image basename
|
# Image basename
|
||||||
image_basename = "pic"
|
image_basename = "pic"
|
||||||
|
|
||||||
@@ -70,9 +75,18 @@ class GUI_PyGame:
|
|||||||
return self.size
|
return self.size
|
||||||
|
|
||||||
def show_picture(self, filename, size=(0,0), offset=(0,0)):
|
def show_picture(self, filename, size=(0,0), offset=(0,0)):
|
||||||
|
# Use window size if none given
|
||||||
if size == (0,0):
|
if size == (0,0):
|
||||||
size = self.size
|
size = self.size
|
||||||
|
# Load image from file
|
||||||
image = pygame.image.load(filename)
|
image = pygame.image.load(filename)
|
||||||
|
# Extract image size and determine scaling
|
||||||
|
image_size = image.get_rect().size
|
||||||
|
max_size = (min(size[0],image_size[0]),min(size[1],image_size[1]))
|
||||||
|
image_scale = min(max_size[0]/image_size[0], max_size[1]/image_size[1])
|
||||||
|
# New image size
|
||||||
|
size = (int(image_size[0] * image_scale), int(image_size[1] * image_scale))
|
||||||
|
# Apply scaling and display picture
|
||||||
image = pygame.transform.scale(image, size).convert()
|
image = pygame.transform.scale(image, size).convert()
|
||||||
self.screen.blit(image, offset)
|
self.screen.blit(image, offset)
|
||||||
|
|
||||||
@@ -134,32 +148,40 @@ class Camera:
|
|||||||
### Functions ###
|
### Functions ###
|
||||||
#################
|
#################
|
||||||
|
|
||||||
# def error(msg, exit_code=1):
|
|
||||||
# print "ERROR: " + msg
|
|
||||||
# teardown(exit_code)
|
|
||||||
|
|
||||||
def handle_keypress(key):
|
def handle_keypress(key):
|
||||||
|
# Exit the application
|
||||||
if key == ord('q'):
|
if key == ord('q'):
|
||||||
teardown()
|
teardown()
|
||||||
|
# Take pictures
|
||||||
elif key == ord('c'):
|
elif key == ord('c'):
|
||||||
print "Taking 4 pictures"
|
# Show pose message
|
||||||
|
display.reset()
|
||||||
|
display.show_picture(image_pose)
|
||||||
|
display.show_message("POSE! Taking four pictures...");
|
||||||
|
display.apply()
|
||||||
|
time.sleep(5)
|
||||||
|
# Extract display and image sizes
|
||||||
size = display.get_size()
|
size = display.get_size()
|
||||||
image_size = (int(size[0]/2), int(size[1]/2))
|
image_size = (int(size[0]/2), int(size[1]/2))
|
||||||
|
# Take pictures
|
||||||
filenames = [i for i in range(4)]
|
filenames = [i for i in range(4)]
|
||||||
for x in range(4):
|
for x in range(4):
|
||||||
filenames[x] = camera.take_picture(images.get_next())
|
filenames[x] = camera.take_picture(images.get_next())
|
||||||
|
# Show pictures for 10 seconds
|
||||||
display.show_picture(filenames[0], image_size, (0,0))
|
display.show_picture(filenames[0], image_size, (0,0))
|
||||||
display.show_picture(filenames[1], image_size, (image_size[0],0))
|
display.show_picture(filenames[1], image_size, (image_size[0],0))
|
||||||
display.show_picture(filenames[2], image_size, (0,image_size[1]))
|
display.show_picture(filenames[2], image_size, (0,image_size[1]))
|
||||||
display.show_picture(filenames[3], image_size, (image_size[0],image_size[1]))
|
display.show_picture(filenames[3], image_size, (image_size[0],image_size[1]))
|
||||||
display.apply()
|
display.apply()
|
||||||
time.sleep(5)
|
time.sleep(10)
|
||||||
|
display.reset()
|
||||||
|
|
||||||
def handle_exception(msg):
|
def handle_exception(msg):
|
||||||
display.reset()
|
display.reset()
|
||||||
display.show_message("Error: " + msg)
|
display.show_message("Error: " + msg)
|
||||||
display.apply()
|
display.apply()
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
|
display.reset()
|
||||||
|
|
||||||
def teardown(exit_code=0):
|
def teardown(exit_code=0):
|
||||||
display.teardown()
|
display.teardown()
|
||||||
|
|||||||
Reference in New Issue
Block a user