From 77734846e38d7cd2845e9e45cf7b703078b1355c Mon Sep 17 00:00:00 2001 From: Balthasar Reuter Date: Fri, 1 May 2015 17:12:55 +0200 Subject: [PATCH] Started implementing a camera class --- photobooth.py | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/photobooth.py b/photobooth.py index 57041ef..9116498 100755 --- a/photobooth.py +++ b/photobooth.py @@ -2,6 +2,8 @@ # Created by br@re-web.eu, 2015 import sys +import subprocess +import time import pygame ##################### @@ -21,10 +23,6 @@ image_offset = (80,60) ### Classes ### ############### -class Usage(Exception): - def __init__(self, msg): - self.msg = msg - class GUI_PyGame: """The GUI class using PyGame""" def __init__(self, name, size): @@ -59,10 +57,13 @@ class GUI_PyGame: def teardown(self): pygame.quit() -# class Camera: -# """Camera class providing functionality to take pictures""" - # def __init__(self): - +class Camera: + """Camera class providing functionality to take pictures""" + #def __init__(self): + def preview(self, filename="/tmp/preview.jpg"): + ret = subprocess.call("gphoto2 --force-overwrite --capture-preview --quiet --filename " + filename) + if ret != 0: error("Error during preview!", ret) + return filename ################# @@ -70,12 +71,20 @@ class GUI_PyGame: ################# def actions(): - display.show_picture('../../capture_preview.jpg', image_size, image_offset) + display.show_picture(camera.preview(), image_size, image_offset) + time.sleep(0.5) + +def error(msg, exit_code=1): + print "ERROR:" + msg + teardown(exit_code) + +def teardown(exit_code=0): + display.teardown() + sys.exit(exit_code) def handle_keypress(key): if key == ord('q'): - display.teardown() - sys.exit() + teardown() elif key == ord('c'): print "Taking picture" @@ -89,6 +98,7 @@ def main(): ######################## display = GUI_PyGame('Photobooth', display_size) +camera = Camera() if __name__ == "__main__": sys.exit(main()) \ No newline at end of file