Changes to printing and sequence
This commit is contained in:
parent
79303fced2
commit
a10832daa7
1 changed files with 69 additions and 190 deletions
259
photobooth.py
259
photobooth.py
|
|
@ -1,213 +1,92 @@
|
|||
#!/usr/local/bin/python
|
||||
#Written by Mari DeGrazia
|
||||
#arizona4n6@gmail.com
|
||||
#Based off the All Seeing Pi by the Rasbperry Pi Foundation
|
||||
|
||||
from gpiozero import Button
|
||||
#modified All Seeing Pi to remove overlay and overlay button.
|
||||
from picamera import PiCamera
|
||||
from time import gmtime, strftime,sleep
|
||||
from overlay_functions import *
|
||||
from shutil import copyfile
|
||||
import subprocess
|
||||
import Tkinter
|
||||
import tkMessageBox
|
||||
import ttk
|
||||
from PIL import Image, ImageTk
|
||||
import pygame
|
||||
from gpiozero import Button
|
||||
#from overlay_functions import *
|
||||
from time import gmtime, strftime, sleep
|
||||
import time
|
||||
from multiprocessing import Process
|
||||
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
|
||||
|
||||
###############CHANGE ME###########################
|
||||
printer_MAC = "00-04-48-13-5E-8D"
|
||||
printer_MAC = "00:04:48:13:5E:8D"
|
||||
####################################################
|
||||
|
||||
|
||||
def kill_keyboard():
|
||||
cmd = "sudo pkill -f matchbox-keyboard"
|
||||
k = subprocess.Popen(cmd,shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||
message = k.communicate(input)
|
||||
return
|
||||
|
||||
def next_overlay():
|
||||
global overlay
|
||||
global current_position
|
||||
current_position = current_position + 1
|
||||
if current_position >= len(overlays):
|
||||
current_position = 0
|
||||
overlay = overlays[current_position]
|
||||
if overlay == "":
|
||||
remove_overlays(camera)
|
||||
else:
|
||||
preview_overlay(camera, overlay)
|
||||
|
||||
def prev_overlay():
|
||||
global overlay
|
||||
global current_position
|
||||
|
||||
current_position = current_position - 1
|
||||
overlay = overlays[current_position]
|
||||
if overlay == "":
|
||||
remove_overlays(camera)
|
||||
else:
|
||||
preview_overlay(camera, overlay)
|
||||
|
||||
def take_picture():
|
||||
global output
|
||||
global latest_photo
|
||||
global current_position
|
||||
global overlay
|
||||
|
||||
output = strftime("/home/pi/Pi-Photobooth/photos/image-%d-%m_%H_%M_%S.png", gmtime())
|
||||
time.sleep(.3)
|
||||
camera.stop_preview()
|
||||
|
||||
remove_overlays(camera)
|
||||
camera.hflip = False
|
||||
camera.capture(output)
|
||||
|
||||
if overlay:
|
||||
output_overlay(output, overlays[current_position])
|
||||
else:
|
||||
output_no_overlay(output)
|
||||
size = 400, 400
|
||||
gif_img = Image.open(output)
|
||||
gif_img.thumbnail(size, Image.ANTIALIAS)
|
||||
|
||||
gif_img.save(latest_photo, 'gif')
|
||||
loadImage(latest_photo)
|
||||
camera.hflip = True
|
||||
just_taken = True
|
||||
|
||||
def new_picture():
|
||||
global overlay
|
||||
kill_keyboard()
|
||||
camera.start_preview()
|
||||
time.sleep(1)
|
||||
copyfile('/home/pi/Pi-Photobooth/images/loading.gif', '/home/pi/Pi-Photobooth/images/latest.gif')
|
||||
remove_overlays(camera)
|
||||
current_position = 0
|
||||
loadImage(latest_photo)
|
||||
overlay = ""
|
||||
photo3 = Tkinter.PhotoImage(file='/home/pi/Pi-Photobooth/images/button_new.gif')
|
||||
b3 = Tkinter.Button(master, text="Take Picture",command=take_picture,image=photo3)
|
||||
b3.image = photo3
|
||||
b3.pack()
|
||||
|
||||
|
||||
|
||||
def remove():
|
||||
global overlay
|
||||
remove_overlays(camera)
|
||||
overlay = ""
|
||||
|
||||
def print_photo():
|
||||
global printer_MAC
|
||||
kill_keyboard()
|
||||
|
||||
top = Tkinter.Tk()
|
||||
top.title("Printing")
|
||||
msg = Tkinter.Label(top, text="Sending to printer. Please wait a minute.",width=50,background='#B1B1B1')
|
||||
msg.pack()
|
||||
top.geometry("%dx%d%+d%+d" % (400, 100, 250, 125))
|
||||
top.configure(background='#B1B1B1')
|
||||
center(top)
|
||||
|
||||
master.config(cursor="watch")
|
||||
top.config(cursor="watch")
|
||||
master.update()
|
||||
top.update()
|
||||
|
||||
print ("Print photo")
|
||||
pp = subprocess.Popen(["obexftp --nopath --noconn --uuid none --bluetooth " + printer_MAC + " --channel 4 -p " + output],shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||
message = pp.communicate(input)
|
||||
master.config(cursor="")
|
||||
top.destroy()
|
||||
msg = "failed"
|
||||
if msg.encode('utf-8') in message[0]:
|
||||
tkMessageBox.showerror("Error", "Print failed. Check paper or make sure printer is on and paired and print again")
|
||||
|
||||
else:
|
||||
tkMessageBox.showinfo("Printing", "Photo successfully sent. Now printing...")
|
||||
|
||||
return True
|
||||
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.")
|
||||
|
||||
def center(toplevel):
|
||||
toplevel.update_idletasks()
|
||||
w = toplevel.winfo_screenwidth()
|
||||
h = toplevel.winfo_screenheight()
|
||||
size = tuple(int(_) for _ in toplevel.geometry().split('+')[0].split('x'))
|
||||
x = w/2 - size[0]/2
|
||||
y = h/2 - size[1]/2
|
||||
|
||||
toplevel.geometry("%dx%d+%d+%d" % (size + (x, y)))
|
||||
|
||||
def lower(toplevel):
|
||||
toplevel.update_idletasks()
|
||||
w = toplevel.winfo_screenwidth()
|
||||
h = toplevel.winfo_screenheight()
|
||||
size = tuple(int(_) for _ in toplevel.geometry().split('+')[0].split('x'))
|
||||
x = w/2 - size[0]/2
|
||||
y = h/2 - size[1]/2
|
||||
|
||||
toplevel.geometry("%dx%d+%d+%d" % (size + (x, y+150)))
|
||||
|
||||
# Tell the take picture button what to do
|
||||
def take_picture():
|
||||
global output
|
||||
output = strftime("/home/pi/simplebooth/image-%d-%m%H:%M.jpg", gmtime())
|
||||
camera.stop_preview()
|
||||
your_pic.set(ready_photo)
|
||||
time.sleep(3)
|
||||
camera.capture(output)
|
||||
your_pic.set(black_photo)
|
||||
|
||||
def loadImage(latest_photo):
|
||||
global picture3
|
||||
picture3 = Tkinter.PhotoImage(file=latest_photo)
|
||||
c.itemconfigure(picture2, image = picture3)
|
||||
|
||||
|
||||
current_position = 0
|
||||
|
||||
|
||||
#reset image
|
||||
copyfile('/home/pi/Pi-Photobooth/images/loading.gif', '/home/pi/Pi-Photobooth/images/latest.gif')
|
||||
|
||||
#camera.stop_preview()
|
||||
|
||||
overlay = ""
|
||||
#no buttons connected.
|
||||
# remove_overlays(camera)
|
||||
# output_overlay(output)
|
||||
|
||||
# Save a smaller gif
|
||||
size = 320, 200
|
||||
gif_img = Image.open(output)
|
||||
gif_img.thumbnail(size, Image.ANTIALIAS)
|
||||
gif_img.save(latest_photo, 'gif')
|
||||
|
||||
# Set the gui picture to this picture
|
||||
your_pic.set(latest_photo)
|
||||
|
||||
|
||||
def new_picture():
|
||||
camera.start_preview(fullscreen=False, window = (100, 20, 640, 480))
|
||||
# preview_overlay(camera, overlay)
|
||||
|
||||
|
||||
# Set up buttons
|
||||
#next_overlay_btn = Button(23)
|
||||
#take_pic_btn = Button(11)
|
||||
|
||||
|
||||
#next_overlay_btn.when_pressed = next_overlay
|
||||
take_pic_btn = Button(21)
|
||||
take_pic_btn.when_pressed = take_picture
|
||||
|
||||
# Set up camera (with resolution of the touchscreen)
|
||||
camera = PiCamera()
|
||||
camera.resolution = (800, 480)
|
||||
camera.resolution = (1296, 730)
|
||||
camera.hflip = True
|
||||
|
||||
# Start camera preview
|
||||
#camera.start_preview()
|
||||
|
||||
camera.start_preview()
|
||||
# Set up filename
|
||||
output = ""
|
||||
latest_photo = '/home/pi/Pi-Photobooth/images/latest.gif'
|
||||
|
||||
p = Process(target=start_wii_script)
|
||||
p.start()
|
||||
|
||||
master = Tkinter.Tk()
|
||||
master.wm_title(subject)
|
||||
master.attributes("-fullscreen", True)
|
||||
c = Tkinter.Canvas(master, width=400, height=300)
|
||||
|
||||
picture = Tkinter.PhotoImage(file=latest_photo)
|
||||
picture2 = c.create_image(200,150,image=picture)
|
||||
c.pack()
|
||||
|
||||
photo1 = Tkinter.PhotoImage(file='/home/pi/Pi-Photobooth/images/button_new.gif')
|
||||
photo2 = Tkinter.PhotoImage(file='/home/pi/Pi-Photobooth/images/button_print.gif')
|
||||
|
||||
b1 = Tkinter.Button(master, text="New Picture",command=new_picture,image=photo1)
|
||||
b2 = Tkinter.Button(master, text="Print Picture",command=print_photo,image=photo2)
|
||||
|
||||
b1.image = photo1
|
||||
b2.image = photo2
|
||||
|
||||
b1.pack()
|
||||
b2.pack()
|
||||
|
||||
|
||||
Tkinter.mainloop( )
|
||||
latest_photo = '/home/pi/simplebooth/latest.gif'
|
||||
ready_photo = '/home/pi/simplebooth/countdown.gif'
|
||||
black_photo = '/home/pi/simplebooth/black.gif'
|
||||
|
||||
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()
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue