Saturday, August 6, 2016

Photo Booth Code Base

#!/bin/bash

from tkinter import *
from tkinter import ttk
from tkinter import font
import RPi.GPIO as GPIO
import subprocess, time, os
from picamera import PiCamera
import smtplib
from email.mime.text import MIMEText

GPIO.setmode(GPIO.BCM)

#define GPIO / pins
PUSHBUTTON = 24
PRINT_LED = 22
POSE_LED = 18
READY_LED = 23

#set up pins
GPIO.setup(PUSHBUTTON, GPIO.IN)
GPIO.setup(PRINT_LED, GPIO.OUT)
GPIO.setup(POSE_LED, GPIO.OUT)
GPIO.setup(READY_LED, GPIO.OUT)

GPIO.output(PRINT_LED, True)
GPIO.output(POSE_LED, True)
GPIO.output(READY_LED, True)

#setup the main window as "win"

root = Tk()
root.title("LRP Photo Booth")
root.option_add("tearOff", False)

menubar = Menu(root)
root['menu'] = menubar
menu_file = Menu(menubar)
menu_edit = Menu(menubar)
menubar.add_cascade(menu=menu_file, label='File')
menu_file.add_command(label="Exit", command=root.quit)
menubar.add_cascade(menu=menu_edit, label='Edit')
#add options here to open text editors for the email file and such

ttk.Style().configure("TButton", padding=10, font='helvetica 34')
ttk.Style().configure("TEntry", padding=10, font='helvetica 34')

g_name = "Tell us your  name"
g_email = "youraddress@mail.com"
myFont = font.Font(family = "Helvetica", size = 34, weight = "bold")

mainframe=ttk.Frame(root, padding="12 12 12 12")
mainframe.grid(column=0, row=0, sticky=(N, W, E, S))
mainframe.columnconfigure(0, weight=2)
mainframe.rowconfigure(0, weight=2)

ttk.Label(mainframe, text="     Press Here and Get Ready!     ", font = myFont).grid(column=1, row=1, columnspan = 3)

#set up the camera
camera = PiCamera()
camera.resolution = (1275, 767)
camera.hflip = False
camera.vflip = False

#define functions
def TakePicture():
        l_photoName = time.strftime("%Y%m%d_%H%M%S")
        snaponePhoto('TL')
        snaponePhoto('TR')
        snaponePhoto('BL')
        snaponePhoto('BR')
        subprocess.call( ['montage', '-tile', '2x2', '-geometry', '+5+5', '*.jpg', '/home/pi/Pictures/'+l_photoName+'.jpg'] )
        sendorDelete(l_photoName)

def snaponePhoto(photoName):
        camera.start_preview()
        time.sleep(2)
        camera.capture(photoName +".jpg")
        camera.stop_preview()

def send(l_name, l_email, l_photoName):

        #send the photo to email
        subject = 'LiningerRoodPhotography'
        mutt =  "mutt -s "+subject+" "+l_email.get()+" john.r.rood@gmail.com < /home/pi/GUI/body_text -a /home/pi/Pictures/"+l_photoName+".jpg"
        ml = subprocess.Popen([mutt], shell = True)
        ml.communicate()
        mutt =  "mutt -s "+subject+" "+l_email.get()+" john.r.rood.update@blogger.com < /home/pi/GUI/body_text -a /home/pi/Pictures/"+l_photoName+".jpg"
        ml = subprocess.Popen([mutt], shell = True)
        ml.communicate()

        #print the photo to the local printer
        printer = "lpr -d SELPHY /home/pi/Pictures/"+l_photoName+".jpg"
        #subprocess.Popen([printer], shell = True)

def sendorDelete(l_photoName):
        global myFont
        l_name = StringVar()
        l_name.set(g_name)
        l_email = StringVar()
        l_email.set(g_email)
        photoName = l_photoName

        def sendButtonAction():
                send(l_name, l_email, photoName)
                contactBox.destroy()

        contactBox = Toplevel(root)
        contactBox.title("Enter Your Contact Info")

        contactFrame=ttk.Frame(contactBox, padding="3 3 12 12")
        contactFrame.grid(column=0, row=0, sticky=(N, W, E, S))
        nameBox=ttk.Entry(contactFrame, textvariable= l_name, font = 30, width = 40).grid(column=2, row=1, columnspan =2)
        emailBox=ttk.Entry(contactFrame, textvariable= l_email, font = 30, width = 40).grid(column=2, row=2, columnspan =2)
        ttk.Label(contactFrame, text="Your Name:", font=  myFont).grid(column=1, row=1, sticky=S)
        ttk.Label(contactFrame, text="Your e-Mail:", font= myFont).grid(column=1, row=2, sticky=S)

        sendButton = ttk.Button(contactFrame, text = "Send It!", command = sendButtonAction).grid(column=2, row=3)
        deleteButton = ttk.Button(contactFrame, text = "Start Over!", command = contactBox.destroy).grid(column=3, row=3)

        for child in contactFrame.winfo_children():child.grid_configure(padx=5, pady=5)

def exitProgram():
        GPIO.cleanup()
        root.quit()

pictureButton = ttk.Button(mainframe, text = "Touch Here To Start!", command = TakePicture).grid(column=1, row=2, columnspan = 3)
exitButton = ttk.Button(mainframe, text = "Exit", command = exitProgram).grid(column=3, row=3, sticky=E)
for child in mainframe.winfo_children():child.grid_configure(padx=5, pady=5)


mainloop()

No comments:

Post a Comment