Advertisement
Guest User

Untitled

a guest
Mar 31st, 2017
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.17 KB | None | 0 0
  1. #!/usr/bin/python3
  2. # LIRE AVANT UTILISATION INSTALATION :
  3. # FAIT POUR RASPBIAN JESSIE/TOUCHSCREEN 3.5" GPIO/CAMERAPi MODULE 2.
  4. # PACK CUPS : https://launchpad.net/ubuntu/trusty/armhf/python3-cups/1.9.66-0ubuntu2
  5. # METTRE A JOURS LES MODULES ET APPS ( sudo apt-get install update PUIS sudo reboot)
  6. # INSTALLER MODULE POUR PYTHON3 PILLOW (sudo apt-get install python3-pil.imagetk PUIS sudo reboot)
  7. # INSTALLER POLICE "Billabong.ttf"
  8.  
  9. #PHOTOBOOTH INSTABOOTH BY LuDoPhotography(LudovicArmengaud)
  10. #VERSION : 0.1-2017.03.18
  11.  
  12. #IMPORTATIONS MODULES
  13. import cups
  14. from tkinter import *
  15. from PIL import Image, ImageTk
  16. from picamera import PiCamera
  17. from datetime import datetime
  18.  
  19. def clearWindow():
  20.     for widget in self.winfo_children():
  21.         widget.destroy()    
  22.  
  23.        
  24. #Menu
  25. def menu():
  26.     global noprint
  27.     noprint = 2
  28.     clearWindow()
  29.     img1 = Image.open('barmenu.png')
  30.     img2 = Image.open('launch.png')
  31.     img3 = Image.open('setting.png')
  32.     camera = ImageTk.PhotoImage(img1)
  33.     launch = ImageTk.PhotoImage(img2)
  34.     setting = ImageTk.PhotoImage(img3)
  35.     photoButton = Button(self, image=camera, width=width, height=66, bg='white')
  36.     photoButton.image = camera
  37.     photoButton.pack(side=TOP)
  38.     photoButton = Button(self, image=launch, width=245, height=257, bg='white', command=waitUser)
  39.     photoButton.image = launch
  40.     photoButton.pack(side=RIGHT)
  41.     photoButton = Button(self, image=setting, width=247, height=257, bg='white', command=confg)
  42.     photoButton.image = setting
  43.     photoButton.pack(side=LEFT)
  44.     self.bind('<Key-Escape>', exitProgram)
  45.     self.bind('<Escape>', exitProgram)
  46.    
  47. #APPLIQUATION
  48. def waitUser():
  49.     global noprint
  50.     noprint = 2
  51.     clearWindow()
  52.     img = Image.open('backgrounda.png')
  53.     camera = ImageTk.PhotoImage(img)
  54.     photoButton = Button(self, image=camera, width=width, height=height, bg='blue', activebackground='blue', command=takePhoto)
  55.     photoButton.image = camera
  56.     photoButton.pack(side=TOP)
  57.  
  58.  
  59. #CONFIGURATION APPAREIL
  60. def confg():
  61.     global noprint
  62.     noprint = 2
  63.  
  64.     root = Tk()
  65.  
  66.     root.wm_title("CONFIG")
  67.     root.geometry('480x320')
  68.  
  69.     bouton1 = Button(root, text="OK")
  70.     bouton1.pack(side=BOTTOM)
  71.     bouton2 = Button(root, text='TEST')
  72.     bouton2.pack(side=BOTTOM)
  73.  
  74.     scaleISO = Scale(root, relief='solid', from_=0, to=500, label="ISO", resolution=50, tickinterval=50, length=180)
  75.     scaleISO.pack(side=LEFT)
  76.     scaleISO.set(100)
  77.    
  78.     scaleContrast = Scale(root, relief='solid', from_=0, to=100, label="CONTS", resolution=10, tickinterval=50, length=180)
  79.     scaleContrast.pack(side=LEFT)
  80.     scaleContrast.set(50)
  81.  
  82.     scaleBrightness = Scale(root, relief='solid', from_=0, to=100, label="LUMI", resolution=10, tickinterval=50, length=180)
  83.     scaleBrightness.pack(side=LEFT)
  84.     scaleBrightness.set(100)
  85.  
  86.     scaleSaturation = Scale(root, relief='solid', from_=0, to=100, label="SATUR", resolution=10, tickinterval=50, length=180)
  87.     scaleSaturation.pack(side=LEFT)
  88.     scaleSaturation.set(50)
  89.  
  90.    
  91.  
  92.                  
  93. #COMPTE A REBOURS
  94. def countDown(counter):
  95.     clearWindow()
  96.     if counter == 0:
  97.         self.after(100, capturePicture)
  98.         countdown = Label(self, text="Souriez!", font=font, width=width, height=height, bg='white', activebackground='white').pack()
  99.     else:
  100.         ct = str(counter)
  101.         countdown = Label(self, text=counter, font=font, width=width, height=height, bg='white', activebackground='white').pack()
  102.         self.after(1000, countDown, counter-1)
  103.  
  104. #APRECUS PHOTO
  105. def reviewPhoto(filename, counter):
  106.     global noprint
  107.     if noprint == 1:
  108.         waitUser()
  109.         return
  110.     if noprint == 0:
  111.         printCups(filename)
  112.         return
  113.     if counter == 0:
  114.         waitUser()
  115.         return
  116.     elif counter == 60:
  117.         clearWindow()
  118.         canvas = Canvas(self, width=width, height=height, bg='black')
  119.         canvas.pack()
  120.         photo = Image.open(filename)
  121.         photo.thumbnail(maxsize, Image.ANTIALIAS)
  122.         canvas.photo = ImageTk.PhotoImage(photo) #BOUTON RETOUR
  123.         canvas.create_image(53, 0, image=canvas.photo, anchor=NW)
  124.         img2 = Image.open('retour.png')
  125.         noprint = ImageTk.PhotoImage(img2)
  126.         decidePrintNo = Button(self, image=noprint, bg='white', activebackground='white', command=dontPrint)
  127.         decidePrintNo.image = noprint
  128.         decidePrintNo_window = canvas.create_window(0, 0, anchor=NW, window=decidePrintNo)
  129.     if counter > 0:
  130.         self.after(1000, reviewPhoto, filename, counter-1)
  131.  
  132. #BOUTON RETOUR
  133. def doPrint():
  134.     global noprint
  135.     noprint = 0
  136.  
  137. def dontPrint():
  138.     global noprint
  139.     noprint = 1
  140.  
  141. def printCups(filename):
  142.     clearWindow()
  143.     img = Image.open('printing.png')
  144.     printing = ImageTk.PhotoImage(img)
  145.     printingButton = Button(self, image=printing, width=width, height=height, bg='yellow', activebackground='yellow', command=takePhoto)
  146.     printingButton.image = printing
  147.     printingButton.pack(side=TOP)
  148.     conn = cups.Connection ()
  149.     printers = conn.getPrinters ()
  150.     printer = list(printers)[0]
  151.     printqueue = len(conn.getJobs())
  152.     if printqueue > 0:
  153.         conn.enablePrinter(printer)
  154.         clearWindow()
  155.         img2 = Image.open('paper.png')
  156.         paper = ImageTk.PhotoImage(img2)
  157.         paperButton = Button(self, text="!", font=font, image=paper, compound=CENTER, width=int(width/2), height=height, bg='blue', activebackground='blue', command= lambda: printCups(filename))
  158.         paperButton.image = paper
  159.         paperButton.pack(side=LEFT)
  160.         img3 = Image.open('noprint.png')
  161.         noprint = ImageTk.PhotoImage(img3)
  162.         noprintButton = Button(self, image=noprint, width=int(width/2), height=height, bg='blue', activebackground='blue', command=waitUser)
  163.         noprintButton.image = noprint
  164.         noprintButton.pack(side=LEFT)
  165.     else:
  166.         conn.enablePrinter(printer)
  167.         conn.printFile(printer, filename, filename, {})
  168.         self.after(2000, waitUser)
  169.  
  170. #PARAMETTRES APPAREIL PHOTO
  171. def takePhoto():
  172.     clearWindow()
  173.     camera.start_preview()
  174.     camera.vflip = True
  175.     camera.ISO = scaleISO.get()                #ISO
  176.     camera.contrast = scaleContrast.get()     #CONTRAST
  177.     camera.brightness = scaleBrightness.get() #LUMINAUSITE
  178.     camera.satration = scaleSaturation.get()  #SATURATION
  179.  #PARAMETRES PAR DEFAUTS
  180.     camera.exposure_mode = 'auto' #MODE D'EXPOSITION
  181.     camera.awb_mode = 'auto' # BALANCE DES BLANC
  182.     camera.image_effect = 'none' # STYLE DES PHOTOS
  183.     countDown(3)
  184.  
  185. #LIEU D'ENREGISTREMENT
  186. def capturePicture():
  187.     filename='/home/pi/Pictures/img_' + datetime.now().strftime(dateString) + '.jpg'
  188.     camera.capture(filename)
  189.     camera.stop_preview()
  190.     reviewPhoto(filename, 60)
  191.  
  192. def exitProgram(event=None):
  193.     self.destroy()
  194.  
  195. #PARAMETRES DIVERS
  196. self = Tk()
  197. self.attributes("-fullscreen", True)
  198. self.title("Photobooth")
  199. width = self.winfo_screenwidth()
  200. height = self.winfo_screenheight()
  201. maxsize = (width, height)
  202. noprint = 2 # 2=Undecided, 1=Don't print, 0=Print
  203. camera = PiCamera()
  204. camera.resolution = (2592, 1944)
  205. camera.framerate = 15
  206. font = ['Billabong', 120]
  207. dateString = '%Y%m%d_%H%M%S'
  208. waitUser()
  209. menu()
  210. self.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement