Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- # LIRE AVANT UTILISATION INSTALATION :
- # FAIT POUR RASPBIAN JESSIE/TOUCHSCREEN 3.5" GPIO/CAMERAPi MODULE 2.
- # PACK CUPS : https://launchpad.net/ubuntu/trusty/armhf/python3-cups/1.9.66-0ubuntu2
- # METTRE A JOURS LES MODULES ET APPS ( sudo apt-get install update PUIS sudo reboot)
- # INSTALLER MODULE POUR PYTHON3 PILLOW (sudo apt-get install python3-pil.imagetk PUIS sudo reboot)
- # INSTALLER POLICE "Billabong.ttf"
- #PHOTOBOOTH INSTABOOTH BY LuDoPhotography(LudovicArmengaud)
- #VERSION : 0.1-2017.03.18
- #IMPORTATIONS MODULES
- import cups
- from tkinter import *
- from PIL import Image, ImageTk
- from picamera import PiCamera
- from datetime import datetime
- def clearWindow():
- for widget in self.winfo_children():
- widget.destroy()
- #Menu
- def menu():
- global noprint
- noprint = 2
- clearWindow()
- img1 = Image.open('barmenu.png')
- img2 = Image.open('launch.png')
- img3 = Image.open('setting.png')
- camera = ImageTk.PhotoImage(img1)
- launch = ImageTk.PhotoImage(img2)
- setting = ImageTk.PhotoImage(img3)
- photoButton = Button(self, image=camera, width=width, height=66, bg='white')
- photoButton.image = camera
- photoButton.pack(side=TOP)
- photoButton = Button(self, image=launch, width=245, height=257, bg='white', command=waitUser)
- photoButton.image = launch
- photoButton.pack(side=RIGHT)
- photoButton = Button(self, image=setting, width=247, height=257, bg='white', command=confg)
- photoButton.image = setting
- photoButton.pack(side=LEFT)
- self.bind('<Key-Escape>', exitProgram)
- self.bind('<Escape>', exitProgram)
- #APPLIQUATION
- def waitUser():
- global noprint
- noprint = 2
- clearWindow()
- img = Image.open('backgrounda.png')
- camera = ImageTk.PhotoImage(img)
- photoButton = Button(self, image=camera, width=width, height=height, bg='blue', activebackground='blue', command=takePhoto)
- photoButton.image = camera
- photoButton.pack(side=TOP)
- #CONFIGURATION APPAREIL
- def confg():
- global noprint
- noprint = 2
- root = Tk()
- root.wm_title("CONFIG")
- root.geometry('480x320')
- bouton1 = Button(root, text="OK")
- bouton1.pack(side=BOTTOM)
- bouton2 = Button(root, text='TEST')
- bouton2.pack(side=BOTTOM)
- scaleISO = Scale(root, relief='solid', from_=0, to=500, label="ISO", resolution=50, tickinterval=50, length=180)
- scaleISO.pack(side=LEFT)
- scaleISO.set(100)
- scaleContrast = Scale(root, relief='solid', from_=0, to=100, label="CONTS", resolution=10, tickinterval=50, length=180)
- scaleContrast.pack(side=LEFT)
- scaleContrast.set(50)
- scaleBrightness = Scale(root, relief='solid', from_=0, to=100, label="LUMI", resolution=10, tickinterval=50, length=180)
- scaleBrightness.pack(side=LEFT)
- scaleBrightness.set(100)
- scaleSaturation = Scale(root, relief='solid', from_=0, to=100, label="SATUR", resolution=10, tickinterval=50, length=180)
- scaleSaturation.pack(side=LEFT)
- scaleSaturation.set(50)
- #COMPTE A REBOURS
- def countDown(counter):
- clearWindow()
- if counter == 0:
- self.after(100, capturePicture)
- countdown = Label(self, text="Souriez!", font=font, width=width, height=height, bg='white', activebackground='white').pack()
- else:
- ct = str(counter)
- countdown = Label(self, text=counter, font=font, width=width, height=height, bg='white', activebackground='white').pack()
- self.after(1000, countDown, counter-1)
- #APRECUS PHOTO
- def reviewPhoto(filename, counter):
- global noprint
- if noprint == 1:
- waitUser()
- return
- if noprint == 0:
- printCups(filename)
- return
- if counter == 0:
- waitUser()
- return
- elif counter == 60:
- clearWindow()
- canvas = Canvas(self, width=width, height=height, bg='black')
- canvas.pack()
- photo = Image.open(filename)
- photo.thumbnail(maxsize, Image.ANTIALIAS)
- canvas.photo = ImageTk.PhotoImage(photo) #BOUTON RETOUR
- canvas.create_image(53, 0, image=canvas.photo, anchor=NW)
- img2 = Image.open('retour.png')
- noprint = ImageTk.PhotoImage(img2)
- decidePrintNo = Button(self, image=noprint, bg='white', activebackground='white', command=dontPrint)
- decidePrintNo.image = noprint
- decidePrintNo_window = canvas.create_window(0, 0, anchor=NW, window=decidePrintNo)
- if counter > 0:
- self.after(1000, reviewPhoto, filename, counter-1)
- #BOUTON RETOUR
- def doPrint():
- global noprint
- noprint = 0
- def dontPrint():
- global noprint
- noprint = 1
- def printCups(filename):
- clearWindow()
- img = Image.open('printing.png')
- printing = ImageTk.PhotoImage(img)
- printingButton = Button(self, image=printing, width=width, height=height, bg='yellow', activebackground='yellow', command=takePhoto)
- printingButton.image = printing
- printingButton.pack(side=TOP)
- conn = cups.Connection ()
- printers = conn.getPrinters ()
- printer = list(printers)[0]
- printqueue = len(conn.getJobs())
- if printqueue > 0:
- conn.enablePrinter(printer)
- clearWindow()
- img2 = Image.open('paper.png')
- paper = ImageTk.PhotoImage(img2)
- paperButton = Button(self, text="!", font=font, image=paper, compound=CENTER, width=int(width/2), height=height, bg='blue', activebackground='blue', command= lambda: printCups(filename))
- paperButton.image = paper
- paperButton.pack(side=LEFT)
- img3 = Image.open('noprint.png')
- noprint = ImageTk.PhotoImage(img3)
- noprintButton = Button(self, image=noprint, width=int(width/2), height=height, bg='blue', activebackground='blue', command=waitUser)
- noprintButton.image = noprint
- noprintButton.pack(side=LEFT)
- else:
- conn.enablePrinter(printer)
- conn.printFile(printer, filename, filename, {})
- self.after(2000, waitUser)
- #PARAMETTRES APPAREIL PHOTO
- def takePhoto():
- clearWindow()
- camera.start_preview()
- camera.vflip = True
- camera.ISO = scaleISO.get() #ISO
- camera.contrast = scaleContrast.get() #CONTRAST
- camera.brightness = scaleBrightness.get() #LUMINAUSITE
- camera.satration = scaleSaturation.get() #SATURATION
- #PARAMETRES PAR DEFAUTS
- camera.exposure_mode = 'auto' #MODE D'EXPOSITION
- camera.awb_mode = 'auto' # BALANCE DES BLANC
- camera.image_effect = 'none' # STYLE DES PHOTOS
- countDown(3)
- #LIEU D'ENREGISTREMENT
- def capturePicture():
- filename='/home/pi/Pictures/img_' + datetime.now().strftime(dateString) + '.jpg'
- camera.capture(filename)
- camera.stop_preview()
- reviewPhoto(filename, 60)
- def exitProgram(event=None):
- self.destroy()
- #PARAMETRES DIVERS
- self = Tk()
- self.attributes("-fullscreen", True)
- self.title("Photobooth")
- width = self.winfo_screenwidth()
- height = self.winfo_screenheight()
- maxsize = (width, height)
- noprint = 2 # 2=Undecided, 1=Don't print, 0=Print
- camera = PiCamera()
- camera.resolution = (2592, 1944)
- camera.framerate = 15
- font = ['Billabong', 120]
- dateString = '%Y%m%d_%H%M%S'
- waitUser()
- menu()
- self.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement