Startup works now, getting stuck at capture
This commit is contained in:
@@ -333,7 +333,9 @@ class CountdownState(State):
|
|||||||
|
|
||||||
def handleEvent(self, event, context):
|
def handleEvent(self, event, context):
|
||||||
|
|
||||||
if isinstance(event, GuiEvent) and event.name == 'capture':
|
if isinstance(event, GuiEvent) and event.name == 'countdown':
|
||||||
|
pass
|
||||||
|
elif isinstance(event, GuiEvent) and event.name == 'capture':
|
||||||
context.state == CaptureState()
|
context.state == CaptureState()
|
||||||
else:
|
else:
|
||||||
raise TypeError('Unknown Event type "{}"'.format(event))
|
raise TypeError('Unknown Event type "{}"'.format(event))
|
||||||
|
|||||||
@@ -44,21 +44,34 @@ class Camera:
|
|||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
self._comm = comm
|
self._comm = comm
|
||||||
self._cap = CameraModule()
|
self._cfg = config
|
||||||
self._pic_dims = PictureDimensions(config, self._cap.getPicture().size)
|
self._cam = CameraModule
|
||||||
|
|
||||||
self._is_preview = (config.getBool('Photobooth', 'show_preview') and
|
self._cap = None
|
||||||
self._cap.hasPreview)
|
self._pic_dims = None
|
||||||
self._is_keep_pictures = config.getBool('Photobooth', 'keep_pictures')
|
|
||||||
|
self._is_preview = self._cfg.getBool('Photobooth', 'show_preview')
|
||||||
|
self._is_keep_pictures = self._cfg.getBool('Photobooth',
|
||||||
|
'keep_pictures')
|
||||||
|
|
||||||
|
def startup(self):
|
||||||
|
|
||||||
|
self._cap = self._cam()
|
||||||
|
self._pic_dims = PictureDimensions(self._cfg,
|
||||||
|
self._cap.getPicture().size)
|
||||||
|
self._is_preview = self._is_preview and self._cap.hasPreview
|
||||||
|
|
||||||
logging.info('Using camera {} preview functionality'.format(
|
logging.info('Using camera {} preview functionality'.format(
|
||||||
'with' if self._is_preview else 'without'))
|
'with' if self._is_preview else 'without'))
|
||||||
|
|
||||||
self.setIdle()
|
self.setIdle()
|
||||||
|
|
||||||
|
self._comm.send(Workers.MASTER, StateMachine.CameraEvent('ready'))
|
||||||
|
|
||||||
def teardown(self, state):
|
def teardown(self, state):
|
||||||
|
|
||||||
self._cap.cleanup()
|
if not self._cap is None:
|
||||||
|
self._cap.cleanup()
|
||||||
if state.target == StateMachine.TeardownEvent.EXIT:
|
if state.target == StateMachine.TeardownEvent.EXIT:
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
elif state.target == StateMachine.TeardownEvent.RESTART:
|
elif state.target == StateMachine.TeardownEvent.RESTART:
|
||||||
@@ -71,7 +84,9 @@ class Camera:
|
|||||||
|
|
||||||
def handleState(self, state):
|
def handleState(self, state):
|
||||||
|
|
||||||
if isinstance(state, StateMachine.GreeterState):
|
if isinstance(state, StateMachine.StartupState):
|
||||||
|
self.startup()
|
||||||
|
elif isinstance(state, StateMachine.GreeterState):
|
||||||
self.prepareCapture()
|
self.prepareCapture()
|
||||||
elif isinstance(state, StateMachine.CountdownState):
|
elif isinstance(state, StateMachine.CountdownState):
|
||||||
self.capturePreview()
|
self.capturePreview()
|
||||||
|
|||||||
@@ -30,70 +30,33 @@ import sys
|
|||||||
|
|
||||||
from . import camera, gui
|
from . import camera, gui
|
||||||
from .Config import Config
|
from .Config import Config
|
||||||
# from .Photobooth import Photobooth
|
|
||||||
from .util import lookup_and_import
|
from .util import lookup_and_import
|
||||||
from .StateMachine import Context, ErrorEvent
|
from .StateMachine import Context, ErrorEvent, StartupState
|
||||||
from .Threading import Communicator, Workers
|
from .Threading import Communicator, Workers
|
||||||
from .Worker import Worker
|
from .Worker import Worker
|
||||||
|
|
||||||
|
|
||||||
class CameraProcess(mp.Process):
|
class CameraProcess(mp.Process):
|
||||||
|
|
||||||
def __init__(self, config, comm): # conn, worker_queue):
|
def __init__(self, config, comm):
|
||||||
|
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.daemon = True
|
self.daemon = True
|
||||||
|
|
||||||
self.cfg = config
|
self._cfg = config
|
||||||
self.comm = comm
|
self._comm = comm
|
||||||
# self.conn = conn
|
|
||||||
# self.worker_queue = worker_queue
|
|
||||||
|
|
||||||
# def run_camera(self):
|
|
||||||
|
|
||||||
# try:
|
|
||||||
# # cap = lookup_and_import(
|
|
||||||
# # camera.modules, self.cfg.get('Camera', 'module'), 'camera')
|
|
||||||
|
|
||||||
# # photobooth = Photobooth(
|
|
||||||
# # self.cfg, cap, self.conn, self.worker_queue)
|
|
||||||
# # return photobooth.run()
|
|
||||||
|
|
||||||
# except BaseException as e:
|
|
||||||
# self.conn.send(gui.GuiState.ErrorState('Camera error', str(e)))
|
|
||||||
# event = self.conn.recv()
|
|
||||||
# if str(event) in ('cancel', 'ack'):
|
|
||||||
# return 123
|
|
||||||
# else:
|
|
||||||
# logging.error('Unknown event received: %s', str(event))
|
|
||||||
# raise RuntimeError('Unknown event received', str(event))
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
|
||||||
CameraModule = lookup_and_import(camera.modules,
|
CameraModule = lookup_and_import(
|
||||||
self.cfg.get('Camera', 'module'),
|
camera.modules, self._cfg.get('Camera', 'module'), 'camera')
|
||||||
'camera')
|
cap = camera.Camera(self._cfg, self._comm, CameraModule)
|
||||||
cap = camera.Camera(self.cfg, self.comm, CameraModule)
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
cap.run()
|
cap.run()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.comm.send(Workers.MASTER, ErrorEvent(e))
|
self._comm.send(Workers.MASTER, ErrorEvent(e))
|
||||||
|
|
||||||
# status_code = 123
|
|
||||||
|
|
||||||
# while status_code == 123:
|
|
||||||
# event = self.conn.recv()
|
|
||||||
|
|
||||||
# if str(event) != 'start':
|
|
||||||
# logging.warning('Unknown event received: %s', str(event))
|
|
||||||
# continue
|
|
||||||
|
|
||||||
# status_code = self.run_camera()
|
|
||||||
# logging.info('Camera exited with status code %d', status_code)
|
|
||||||
|
|
||||||
# sys.exit(status_code)
|
|
||||||
|
|
||||||
|
|
||||||
class WorkerProcess(mp.Process):
|
class WorkerProcess(mp.Process):
|
||||||
@@ -108,7 +71,11 @@ class WorkerProcess(mp.Process):
|
|||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
|
||||||
sys.exit(Worker(self.cfg, self.comm).run())
|
while True:
|
||||||
|
try:
|
||||||
|
Worker(self.cfg, self.comm).run()
|
||||||
|
except Exception as e:
|
||||||
|
self._comm.send(Workers.MASTER, ErrorEvent(e))
|
||||||
|
|
||||||
|
|
||||||
class GuiProcess(mp.Process):
|
class GuiProcess(mp.Process):
|
||||||
|
|||||||
Reference in New Issue
Block a user