diff --git a/photobooth/StateMachine.py b/photobooth/StateMachine.py index bed4eaa..c26ffb3 100644 --- a/photobooth/StateMachine.py +++ b/photobooth/StateMachine.py @@ -316,45 +316,59 @@ class GreeterState(State): if ((isinstance(event, GuiEvent) or isinstance(event, GpioEvent)) and event.name == 'countdown'): - context.state = CountdownState() + context.state = CountdownState(1) else: raise TypeError('Unknown Event type "{}"'.format(event)) class CountdownState(State): - def __init__(self): + def __init__(self, num_picture): super().__init__() + self._num_picture = num_picture + def __str__(self): return 'CountdownState' + @property + def num_picture(self): + + return self._num_picture + def handleEvent(self, event, context): if isinstance(event, GuiEvent) and event.name == 'countdown': pass elif isinstance(event, GuiEvent) and event.name == 'capture': - context.state == CaptureState() + context.state = CaptureState(self.num_picture) else: raise TypeError('Unknown Event type "{}"'.format(event)) class CaptureState(State): - def __init__(self): + def __init__(self, num_picture): super().__init__() + self._num_picture = num_picture + def __str__(self): return 'CaptureState' + @property + def num_picture(self): + + return self._num_picture + def handleEvent(self, event, context): if isinstance(event, CameraEvent) and event.name == 'countdown': - context.state = CountdownState() + context.state = CountdownState(self.num_picture + 1) elif isinstance(event, CameraEvent) and event.name == 'assemble': context.state = AssembleState() else: @@ -374,25 +388,31 @@ class AssembleState(State): def handleEvent(self, event, context): if isinstance(event, CameraEvent) and event.name == 'review': - context.state = ReviewState() + context.state = ReviewState(event.picture) else: raise TypeError('Unknown Event type "{}"'.format(event)) class ReviewState(State): - def __init__(self): + def __init__(self, picture): super().__init__() + self._picture = picture def __str__(self): return 'ReviewState' + @property + def picture(self): + + return self._picture + def handleEvent(self, event, context): if isinstance(event, GuiEvent) and event.name == 'postprocess': - context.state == PostprocessState() + context.state = PostprocessState() else: raise TypeError('Unknown Event type "{}"'.format(event)) @@ -411,6 +431,6 @@ class PostprocessState(State): if ((isinstance(event, GuiEvent) or isinstance(event, GpioEvent)) and event.name == 'idle'): - context.state == IdleState() + context.state = IdleState() else: raise TypeError('Unknown Event type "{}"'.format(event)) diff --git a/photobooth/camera/__init__.py b/photobooth/camera/__init__.py index 47bd308..4c9989a 100644 --- a/photobooth/camera/__init__.py +++ b/photobooth/camera/__init__.py @@ -70,7 +70,7 @@ class Camera: def teardown(self, state): - if not self._cap is None: + if self._cap is not None: self._cap.cleanup() if state.target == StateMachine.TeardownEvent.EXIT: sys.exit(0) @@ -91,7 +91,7 @@ class Camera: elif isinstance(state, StateMachine.CountdownState): self.capturePreview() elif isinstance(state, StateMachine.CaptureState): - self.capturePicture() + self.capturePicture(state) elif isinstance(state, StateMachine.AssembleState): self.assemblePicture() elif isinstance(state, StateMachine.TeardownState): @@ -119,7 +119,7 @@ class Camera: self._comm.send(Workers.GUI, StateMachine.CameraEvent('preview', picture)) - def capturePicture(self): + def capturePicture(self, state): self.setIdle() picture = self._cap.getPicture() @@ -130,12 +130,12 @@ class Camera: self._comm.send(Workers.WORKER, StateMachine.CameraEvent('capture', picture)) - if len(self._pictures) < self._pic_dims.totalNumPictures: + if state.num_picture < self._pic_dims.totalNumPictures: self._comm.send(Workers.MASTER, - StateMachine.CameraEvent('countdown', picture)) + StateMachine.CameraEvent('countdown')) else: self._comm.send(Workers.MASTER, - StateMachine.CameraEvent('assemble', picture)) + StateMachine.CameraEvent('assemble')) def assemblePicture(self): diff --git a/photobooth/main.py b/photobooth/main.py index 0e21116..f740722 100644 --- a/photobooth/main.py +++ b/photobooth/main.py @@ -31,7 +31,7 @@ import sys from . import camera, gui from .Config import Config from .util import lookup_and_import -from .StateMachine import Context, ErrorEvent, StartupState +from .StateMachine import Context, ErrorEvent from .Threading import Communicator, Workers from .Worker import Worker