Pfad von persistenten Fotos ins lokale Verzeichnis verschoben

+ Laden von statischen Grafiken in ein Dictionary
This commit is contained in:
root 2018-02-11 15:01:58 +01:00
parent 17b62410b5
commit 1f0d1692b5
2 changed files with 51 additions and 53 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
/images/
/tmp?.jpg /tmp?.jpg

View File

@ -55,8 +55,8 @@ TEXT_POS = (250, -40)
OVERLAY_ALPHA = 64 OVERLAY_ALPHA = 64
COLOR_BACK = pygame.Color(0, 0, 0) COLOR_BACK = pygame.Color(0, 0, 0)
COLOR_FLASH = pygame.Color(255, 255, 255) COLOR_FLASH = pygame.Color(255, 255, 255)
GRAPHICS_DIR = "./graphics" GRAPHICS_DIR = "graphics"
IMAGE_DIR = "/var/www/html/current_images" IMAGE_DIR = "images/0-CURRENT"
COUNTDOWN = 3 COUNTDOWN = 3
SHOT_COUNT = 3 SHOT_COUNT = 3
BORDER = 10 BORDER = 10
@ -64,6 +64,9 @@ BORDER = 10
THUMB_WIDTH = int((800 - BORDER) / SHOT_COUNT - BORDER) THUMB_WIDTH = int((800 - BORDER) / SHOT_COUNT - BORDER)
THUMB_HEIGHT = int(THUMB_WIDTH / 1.333) THUMB_HEIGHT = int(THUMB_WIDTH / 1.333)
IMAGES_ORIGINAL = os.path.join(IMAGE_DIR, "original")
IMAGES_TODO = os.path.join(IMAGE_DIR, "todo")
# global variables # global variables
@ -73,22 +76,12 @@ session_start = monotonic_time()
# CREATE DIRECTORIES # CREATE DIRECTORIES
try: try:
os.makedirs(GRAPHICS_DIR) os.makedirs(IMAGES_ORIGINAL)
except OSError: except OSError:
pass pass
try: try:
os.makedirs(IMAGE_DIR) os.makedirs(IMAGES_TODO)
except OSError:
pass
try:
os.makedirs(IMAGE_DIR + "/original")
except OSError:
pass
try:
os.makedirs(IMAGE_DIR + "/todo")
except OSError: except OSError:
pass pass
@ -121,32 +114,26 @@ screen = pygame.display.set_mode((WIDTH,HEIGHT))
# LOAD OVERLAYS # LOAD GRAPHICS
begin = pygame.image.load(GRAPHICS_DIR + "/begin.png") gfx = {}
begin_rect = begin.get_rect()
loading = pygame.image.load(GRAPHICS_DIR + "/loading.png") def _load(name):
loading_rect = loading.get_rect() filename = "%s.png" % name
path = os.path.join(GRAPHICS_DIR, filename)
yes = pygame.image.load(GRAPHICS_DIR + "/yes.png") img = pygame.image.load(path)
yes_rect = yes.get_rect() rect = img.get_rect()
yes_rect.y = 340
no = pygame.image.load(GRAPHICS_DIR + "/no.png") gfx[name] = (img, rect)
no_rect = no.get_rect()
no_rect.y = 340
end_yes = pygame.image.load(GRAPHICS_DIR + "/end_yes.png") _load("begin")
end_yes_rect = end_yes.get_rect() _load("loading")
_load("yes")
end_no = pygame.image.load(GRAPHICS_DIR + "/end_no.png") _load("no")
end_no_rect = end_no.get_rect() _load("end_yes")
_load("end_no")
saved = pygame.image.load(GRAPHICS_DIR + "/saved.png") _load("saved")
saved_rect = saved.get_rect() _load("canceled")
canceled = pygame.image.load(GRAPHICS_DIR + "/canceled.png")
canceled_rect = canceled.get_rect()
@ -154,7 +141,10 @@ canceled_rect = canceled.get_rect()
img_cdn = [] img_cdn = []
pad_cdn = [] pad_cdn = []
for i in range(0, COUNTDOWN): for i in range(0, COUNTDOWN):
img = Image.open(GRAPHICS_DIR + "/%s.png" % (COUNTDOWN - i)) filename = "%s.png" % (COUNTDOWN - i)
path = os.path.join(GRAPHICS_DIR, filename)
img = Image.open(path)
pad = Image.new('RGB', ( pad = Image.new('RGB', (
((img.size[0] + 31) // 32) * 32, ((img.size[0] + 31) // 32) * 32,
((img.size[1] + 15) // 16) * 16, ((img.size[1] + 15) // 16) * 16,
@ -202,10 +192,9 @@ def maintainance():
def waitForBegin(): def waitForBegin():
screen.fill(COLOR_BACK) screen.fill(COLOR_BACK)
screen.blit(begin, begin_rect) screen.blit(*gfx["begin"])
pygame.display.flip() pygame.display.flip()
# wait # wait
@ -267,7 +256,7 @@ def makePhotos():
def chooseImages(): def chooseImages():
# clear screen # clear screen
screen.fill(COLOR_BACK) screen.fill(COLOR_BACK)
screen.blit(loading, loading_rect) screen.blit(*gfx["loading"])
pygame.display.update() pygame.display.update()
# load images from disk # load images from disk
@ -299,9 +288,9 @@ def chooseImages():
# draw background # draw background
screen.fill(COLOR_BACK) screen.fill(COLOR_BACK)
if any_choice: if any_choice:
screen.blit(end_yes, end_yes_rect) screen.blit(*gfx["end_yes"])
else: else:
screen.blit(end_no, end_no_rect) screen.blit(*gfx["end_no"])
# draw images # draw images
for i in range(0, SHOT_COUNT): for i in range(0, SHOT_COUNT):
@ -311,11 +300,13 @@ def chooseImages():
x = 12 x = 12
for choice in choices: for choice in choices:
if choice > 0: if choice > 0:
yes_rect.x = x + (THUMB_WIDTH - yes_rect.width) / 2 (img, rect) = gfx["yes"]
screen.blit(yes, yes_rect)
else: else:
no_rect.x = x + (THUMB_WIDTH - no_rect.width) / 2 (img, rect) = gfx["no"]
screen.blit(no, no_rect)
rect.x = x + (THUMB_WIDTH - rect.width) / 2
rect.y = 340
screen.blit(img, rect)
x = x + THUMB_WIDTH + BORDER x = x + THUMB_WIDTH + BORDER
@ -355,9 +346,15 @@ def saveImages(choices):
for i in range(0, SHOT_COUNT): for i in range(0, SHOT_COUNT):
if choices[i] > 0: if choices[i] > 0:
print(" saving image #%s" % i) print(" saving image #%s" % i)
filename = "%s-%s-session_age=%05d.jpg" % (local.strftime("%Y%m%dT%H:%M:%S.%f%z"), i, session_age) filename = "%s-%s-session_age=%05d.jpg" % (local.strftime("%Y%m%dT%H:%M:%S.%f%z"), i, session_age)
os.rename("tmp%s.jpg" % i, IMAGE_DIR + "/original/" + filename)
copyfile(IMAGE_DIR + "/original/" + filename, IMAGE_DIR + "/todo/" + filename) path_tmp = "tmp%s.jpg" % i
path_original = os.path.join(IMAGES_ORIGINAL, filename)
path_todo = os.path.join(IMAGES_TODO, filename)
os.rename(path_tmp, path_original)
copyfile(path_original, path_todo)
@ -369,11 +366,11 @@ while 1:
if save: if save:
saveImages(choices); saveImages(choices);
screen.fill(COLOR_BACK) screen.fill(COLOR_BACK)
screen.blit(saved, saved_rect) screen.blit(*gfx["saved"])
pygame.display.flip() pygame.display.flip()
else: else:
screen.fill(COLOR_BACK) screen.fill(COLOR_BACK)
screen.blit(canceled, canceled_rect) screen.blit(*gfx["canceled"])
pygame.display.flip() pygame.display.flip()
sleep(2) sleep(2)