-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui_collage.py
223 lines (191 loc) · 6.75 KB
/
gui_collage.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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# -*- coding: utf-8 -*-
"""
Created on Tue May 1 11:44:35 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")
root.attributes('-fullscreen', True) # Vollbild
# Hintergrund
background_image=tk.PhotoImage(file="background/Holzwand.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
# Exit button
def close_window ():
root.destroy()
exit_button = tk.Button (root, text = "X", command = close_window)
exit_button.place(x=0, y=0)
# 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")
photo_NextPic=tk.PhotoImage(file="buttons/NaechstesBild.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"),
tk.Button(root,image=photo_NextPic,width="220",height="81")]
# Alle Labels
labels = tk.Label(root)
labels.config(font=("Courier", 44))
pic = tk.Label(root)
# Alle Radiobuttons
numberOfpages = tk.IntVar()
numberOfpages.set(1)
radiobutton = [tk.Radiobutton(root,text="1x drucken",font=("Courier", 20),variable = numberOfpages, value = 1),
tk.Radiobutton(root,text="2x drucken",font=("Courier", 20),variable = numberOfpages, value = 2)]
# Bild resize (Größe des Previews)
basewidth = 600
# Location
folder_name = imageCapture.giveFolderName()
# Counter
printPage = 0
printCounter = tk.Label(root, text = printPage)
printCounter.place(x=5,y=1)
# Sonstiges
fileName = None
path = None
listofimages = []
## Which mode should be use:
# 1 -> Hochzeit (Mit Bilduntertitel)
# 2 -> Party (Ohne Bilduntertiel)
modus = 1
# 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()
pic.place_forget()
radiobutton[0].place_forget()
radiobutton[1].place_forget()
global listofimages
listofimages = []
labels.config(text = "Willkommen zur PhotoBooth")
buttons[5].place(relx=0.5, rely=0.5, anchor=tk.CENTER)
buttons[5].config(command = AreYouReady)
labels.place(relx=0.5, rely=0.3, anchor=tk.CENTER)
root.update()
def AreYouReady():
pic.place_forget()
ButtonsDelete()
deletePreview()
labels.config(text ="Seid ihr bereit?")
buttons[6].place(relx=0.5, rely=0.7, anchor=tk.CENTER)
buttons[6].config(command = CaptureImage)
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, path
fileName = imageCapture.giveFileName()
path = folder_name + "/" + fileName
PictureReview()
def PictureReview():
labels.config(text = "Error")
img = Image.open(path)
# Image resize:
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")
# Place Preview
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)
if len(listofimages) < 3:
buttons[7].config(command = NextPicture)
buttons[3].config(command = AreYouReady)
buttons[7].place(relx=0.8, rely=0.9, anchor=tk.CENTER)
buttons[3].place(relx=0.2, rely=0.9, anchor=tk.CENTER)
if len(listofimages) == 3:
buttons[5].config(command = NextPicture)
buttons[3].config(command = AreYouReady)
buttons[5].place(relx=0.8, rely=0.9, anchor=tk.CENTER)
buttons[3].place(relx=0.2, rely=0.9, anchor=tk.CENTER)
if len(listofimages) == 4:
global numberOfpages
buttons[2].config(command = Printing)
buttons[0].config(command = WelcomePhotoBooth) # Komplett löschen
buttons[2].place(relx=0.8, rely=0.9, anchor=tk.CENTER)
buttons[0].place(relx=0.2, rely=0.9, anchor=tk.CENTER)
radiobutton[0].place(relx=0.9, rely=0.6, anchor=tk.CENTER)
radiobutton[1].place(relx=0.9, rely=0.7, anchor=tk.CENTER)
def NextPicture():
global listofimages, fileName, path
listofimages.append(path)
if len(listofimages) < 4:
AreYouReady()
if len(listofimages) == 4:
ButtonsDelete()
pic.place_forget()
labels.config(text = "Collage wird erstellt... \n Einen Moment bitte...")
root.update()
collage.create_collage(6000,4000,listofimages,modus) #ggfs ändern
fileName = collage.giveFileName()
path = folder_name + "/" + fileName
print(fileName)
PictureReview()
def DeletePicture():
global listofimages
if len(listofimages) > 0:
del listofimages[-1]
AreYouReady()
def Printing():
global printPage
pic.place_forget()
ButtonsDelete()
deletePreview()
radiobutton[0].place_forget()
radiobutton[1].place_forget()
labels.config(text = "Bild wird gedruckt...\n ...einen Moment")
root.update()
for i in range(numberOfpages.get()):
#print(i)
printPage += 1
printer.printImage(path)
time.sleep(5)
printCounter.config(text = printPage)
root.update()
time.sleep(2)
WelcomePhotoBooth()