Advertisement
Guest User

Untitled

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