simplebooth/photobooth.py

93 lines
2.6 KiB
Python
Raw Normal View History

2018-08-26 13:17:54 +00:00
#modified All Seeing Pi to remove overlay and overlay button.
2017-06-04 05:37:21 +00:00
from picamera import PiCamera
2018-08-26 13:17:54 +00:00
from gpiozero import Button
#from overlay_functions import *
from time import gmtime, strftime, sleep
2017-06-04 05:37:21 +00:00
import time
2018-08-26 13:17:54 +00:00
import string
import subprocess
from guizero import App, PushButton, Text, Picture, Window, info
#from twython import Twython
#from auth import (
# consumer_key,
# consumer_secret,
# access_token,
# access_token_secret
#)
from PIL import Image
2017-06-04 05:37:21 +00:00
###############CHANGE ME###########################
2018-08-26 13:17:54 +00:00
printer_MAC = "00:04:48:13:5E:8D"
2017-06-04 05:37:21 +00:00
####################################################
2018-08-26 13:17:54 +00:00
def print_photo():
global printer_MAC
print ("Print photo")
commandtag ="obexftp --nopath --noconn --uuid none --bluetooth "+printer_MAC+" --channel 1 -p "+output
#uncomment this for debugging
#print (commandtag)
p = subprocess.Popen(commandtag, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
#uncomment these for debugging
#for line in iter(p.stdout.readline, ''):
# print(line)
#retval = p.wait()
info("Printing", "Sending to printer. Please wait a minute.")
2017-06-04 05:37:21 +00:00
2018-08-26 13:17:54 +00:00
# Tell the take picture button what to do
2017-06-04 05:37:21 +00:00
def take_picture():
global output
2018-08-26 13:17:54 +00:00
output = strftime("/home/pi/simplebooth/image-%d-%m%H:%M.jpg", gmtime())
2017-06-04 05:37:21 +00:00
camera.stop_preview()
2018-08-26 13:17:54 +00:00
your_pic.set(ready_photo)
time.sleep(3)
2017-06-04 05:37:21 +00:00
camera.capture(output)
2018-08-26 13:17:54 +00:00
your_pic.set(black_photo)
#camera.stop_preview()
2017-06-04 05:37:21 +00:00
2018-08-26 13:17:54 +00:00
# remove_overlays(camera)
# output_overlay(output)
# Save a smaller gif
size = 320, 200
2017-06-04 05:37:21 +00:00
gif_img = Image.open(output)
gif_img.thumbnail(size, Image.ANTIALIAS)
gif_img.save(latest_photo, 'gif')
2018-08-26 13:17:54 +00:00
# Set the gui picture to this picture
your_pic.set(latest_photo)
2017-06-04 05:37:21 +00:00
2018-08-26 13:17:54 +00:00
def new_picture():
camera.start_preview(fullscreen=False, window = (100, 20, 640, 480))
# preview_overlay(camera, overlay)
2017-06-04 05:37:21 +00:00
2018-08-26 13:17:54 +00:00
# Set up buttons
2018-08-25 20:27:39 +00:00
#next_overlay_btn = Button(23)
#next_overlay_btn.when_pressed = next_overlay
2018-08-26 13:17:54 +00:00
take_pic_btn = Button(21)
2017-06-04 05:37:21 +00:00
take_pic_btn.when_pressed = take_picture
2018-08-26 13:17:54 +00:00
# Set up camera (with resolution of the touchscreen)
2017-06-04 05:37:21 +00:00
camera = PiCamera()
2018-08-26 13:17:54 +00:00
camera.resolution = (1296, 730)
2017-06-04 05:37:21 +00:00
camera.hflip = True
2018-08-26 13:17:54 +00:00
# Start camera preview
#camera.start_preview()
2017-06-04 05:37:21 +00:00
2018-08-26 13:17:54 +00:00
# Set up filename
2017-06-04 05:37:21 +00:00
output = ""
2018-08-26 13:17:54 +00:00
latest_photo = '/home/pi/simplebooth/latest.gif'
ready_photo = '/home/pi/simplebooth/countdown.gif'
black_photo = '/home/pi/simplebooth/black.gif'
2017-06-04 05:37:21 +00:00
2018-08-26 13:17:54 +00:00
app = App("The JAM Wedding Photo Booth", 320, 300)
#app.attributes("-fullscreen", True)
your_pic = Picture(app, latest_photo)
new_pic = PushButton(app, new_picture, text="New picture")
print_pic = PushButton(app, print_photo, text="Print picture")
app.display()
2017-06-04 05:37:21 +00:00