Started implementing a camera class
This commit is contained in:
@@ -2,6 +2,8 @@
|
|||||||
# Created by br@re-web.eu, 2015
|
# Created by br@re-web.eu, 2015
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
import subprocess
|
||||||
|
import time
|
||||||
import pygame
|
import pygame
|
||||||
|
|
||||||
#####################
|
#####################
|
||||||
@@ -21,10 +23,6 @@ image_offset = (80,60)
|
|||||||
### Classes ###
|
### Classes ###
|
||||||
###############
|
###############
|
||||||
|
|
||||||
class Usage(Exception):
|
|
||||||
def __init__(self, msg):
|
|
||||||
self.msg = msg
|
|
||||||
|
|
||||||
class GUI_PyGame:
|
class GUI_PyGame:
|
||||||
"""The GUI class using PyGame"""
|
"""The GUI class using PyGame"""
|
||||||
def __init__(self, name, size):
|
def __init__(self, name, size):
|
||||||
@@ -59,10 +57,13 @@ class GUI_PyGame:
|
|||||||
def teardown(self):
|
def teardown(self):
|
||||||
pygame.quit()
|
pygame.quit()
|
||||||
|
|
||||||
# class Camera:
|
class Camera:
|
||||||
# """Camera class providing functionality to take pictures"""
|
"""Camera class providing functionality to take pictures"""
|
||||||
# def __init__(self):
|
#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():
|
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):
|
def handle_keypress(key):
|
||||||
if key == ord('q'):
|
if key == ord('q'):
|
||||||
display.teardown()
|
teardown()
|
||||||
sys.exit()
|
|
||||||
elif key == ord('c'):
|
elif key == ord('c'):
|
||||||
print "Taking picture"
|
print "Taking picture"
|
||||||
|
|
||||||
@@ -89,6 +98,7 @@ def main():
|
|||||||
########################
|
########################
|
||||||
|
|
||||||
display = GUI_PyGame('Photobooth', display_size)
|
display = GUI_PyGame('Photobooth', display_size)
|
||||||
|
camera = Camera()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
sys.exit(main())
|
sys.exit(main())
|
||||||
Reference in New Issue
Block a user