-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui.py
205 lines (169 loc) · 5.81 KB
/
gui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 21 10:45:54 2018
@author: Pascha
"""
import os
import tkinter as tk
import time
from PIL import ImageTk, Image
import imageCapture
import printer
import telegram
import collage
root = tk.Tk()
# Geometrie des Fensters
root.geometry("1024x600")
# Hintergrund
background_image=tk.PhotoImage(file="background/bg.png")
background_label = tk.Label(root, image=background_image, width="1024",height="600")
background_label.place(x=0, y=0, relwidth=1, relheight=1)
background_label.image = background_image
# Alle ButtonImage
photo_BildDrucken=tk.PhotoImage(file="buttons/BildDrucken.png")
photo_JA=tk.PhotoImage(file="buttons/JA.png")
photo_Nochmal=tk.PhotoImage(file="buttons/Nochmal.png")
photo_Start=tk.PhotoImage(file="buttons/Start.png")
photo_Einzelbild=tk.PhotoImage(file="buttons/Einzelbild.png")
photo_Collage=tk.PhotoImage(file="buttons/Collage.png")
# Alle Buttons
buttons = [tk.Button(root,image=photo_Start,width="220",height="82"),
tk.Button(root,image=photo_Einzelbild,width="220",height="81"),
tk.Button(root,image=photo_BildDrucken,width="240",height="80"),
tk.Button(root,image=photo_Nochmal,width="222",height="82"),
tk.Button(root,image=photo_Start,width="220",height="81"),
tk.Button(root,image=photo_Collage,width="220",height="81"),
tk.Button(root,image=photo_JA, width = "221", height="82")]
# Alle Labels
labels = tk.Label(root)
labels.config(font=("Courier", 44))
pic = tk.Label(root)
# Bild resize (Größe des Previews)
basewidth = 600
# Location
folder_name = imageCapture.giveFolderName()
# Counter
printPage = 0
# Sonstiges
fileName = None
path = None
# Hilfsfunktionen:
def Countdown():
labels.config(text = "Achtung!")
root.update()
time.sleep(1)
for sek in ["3","2","1"]:
labels.config(text = "Foto wird geschossen in \n" + sek)
root.update()
time.sleep(1)
def ButtonsDelete():
for i in range(len(buttons)):
buttons[i].place_forget()
def deletePreview():
try:
os.remove(folder_name + "/Preview.jpg")
print("Löschen von 'Preview.jpg'")
except:
print("Preview war nicht vorhanden")
# Dialoge:
def WelcomePhotoBooth():
ButtonsDelete()
labels.config(text = "Willkommen zur PhotoBooth")
buttons[0].config(command = ChooseSelection)
buttons[0].place(relx=0.5, rely=0.5, anchor=tk.CENTER)
labels.place(relx=0.5, rely=0.3, anchor=tk.CENTER)
root.update()
def ChooseSelection():
pic.place_forget()
ButtonsDelete()
deletePreview()
labels.config(text ="Was wollt ihr drucken?")
buttons[1].place(relx=0.3, rely=0.5, anchor=tk.CENTER)
buttons[1].config(command = lambda: AreYouReady(CaptureImage))
buttons[5].place(relx=0.7, rely=0.5, anchor=tk.CENTER)
buttons[5].config(command = lambda: AreYouReady(Collage))
root.update()
def AreYouReady(com):
pic.place_forget()
ButtonsDelete()
deletePreview()
if com == CaptureImage:
labels.config(text ="Seid ihr bereit?")
if com == Collage:
labels.config(text ="Jetzt werden vier Bilder \n in kurzer Zeit gemacht! \n \n" +
"Seid ihr bereit?")
buttons[6].place(relx=0.5, rely=0.7, anchor=tk.CENTER)
buttons[6].config(command = com)
def Collage():
ButtonsDelete()
listofimages = []
for nbImage in range(4):
Countdown()
labels.config(text = "Lächeln!!")
root.update()
imageCapture.captureImages()
labels.config(text = "Nächstes Foto")
root.update()
imageCapture.renameFiles()
fileName_temp = imageCapture.giveFileName()
listofimages.append(folder_name + "/" + fileName_temp)
labels.config(text = "Collage wird erstellt... \n Einen Moment bitte...")
root.update()
collage.create_collage(6000,4000,listofimages) #ggfs ändern
global fileName
fileName = collage.giveFileName()
print(fileName)
PictureReview()
def CaptureImage():
ButtonsDelete()
Countdown()
labels.config(text = "Lächeln!!")
root.update()
imageCapture.captureImages()
labels.config(text = "Einen Moment noch...")
root.update()
imageCapture.renameFiles()
global fileName
fileName = imageCapture.giveFileName()
PictureReview()
def PictureReview():
labels.config(text = "Error")
global path
path = folder_name + "/" + fileName
img = Image.open(path)
wpercent = (basewidth / float(img.size[0]))
hsize = int((float(img.size[1]) * float(wpercent)))
img = img.resize((basewidth, hsize), Image.ANTIALIAS)
img.save("Preview.jpg")
print("Image was resized")
####################
path_Preview = folder_name + "/" + "Preview.jpg"
image = Image.open(path_Preview)
photo = ImageTk.PhotoImage(image)
pic.config(image=photo)
pic.image = photo # keep a reference!
pic.place(relx = 0.5, rely = 0.4, anchor=tk.CENTER)
buttons[2].config(command = Printing)
buttons[3].config(command = ChooseSelection)
#buttons5.config(command = lambda: UploadTelegram(path_Preview))
buttons[2].place(relx=0.8, rely=0.9, anchor=tk.CENTER)
buttons[3].place(relx=0.2, rely=0.9, anchor=tk.CENTER)
#buttons5.place(relx=0.5, rely=0.9, anchor=tk.CENTER)
def UploadTelegram(path): # oder durch Bluetooth ersetzen
telegram.BotPhoto(path)
PictureReview()
def Printing():
pic.place_forget()
ButtonsDelete()
deletePreview()
labels.config(text = "Bild wird gedruckt...\n ...einen Moment")
root.update()
printer.printImage(path)
global printPage
printPage += 1
time.sleep(1)
if printPage == 2: #Todo noch ändern
telegram.BotMessage("Papier ist bald leer...")
printPage = -1
time.sleep(30)
WelcomePhotoBooth()