Introduced pickling-by-hand for pictures, possible fix for #35
This commit is contained in:
@@ -19,6 +19,8 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from . import util
|
||||||
|
|
||||||
|
|
||||||
class Context:
|
class Context:
|
||||||
|
|
||||||
@@ -167,16 +169,12 @@ class TeardownEvent(Event):
|
|||||||
|
|
||||||
class GuiEvent(Event):
|
class GuiEvent(Event):
|
||||||
|
|
||||||
def __init__(self, name):
|
pass
|
||||||
|
|
||||||
super().__init__(name)
|
|
||||||
|
|
||||||
|
|
||||||
class GpioEvent(Event):
|
class GpioEvent(Event):
|
||||||
|
|
||||||
def __init__(self, name):
|
pass
|
||||||
|
|
||||||
super().__init__(name)
|
|
||||||
|
|
||||||
|
|
||||||
class CameraEvent(Event):
|
class CameraEvent(Event):
|
||||||
@@ -184,19 +182,17 @@ class CameraEvent(Event):
|
|||||||
def __init__(self, name, picture=None):
|
def __init__(self, name, picture=None):
|
||||||
|
|
||||||
super().__init__(name)
|
super().__init__(name)
|
||||||
self._picture = picture
|
self._picture = util.pickle_image(picture)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def picture(self):
|
def picture(self):
|
||||||
|
|
||||||
return self._picture
|
return util.unpickle_image(self._picture)
|
||||||
|
|
||||||
|
|
||||||
class WorkerEvent(Event):
|
class WorkerEvent(Event):
|
||||||
|
|
||||||
def __init__(self, name):
|
pass
|
||||||
|
|
||||||
super().__init__(name)
|
|
||||||
|
|
||||||
|
|
||||||
class State:
|
class State:
|
||||||
@@ -206,6 +202,10 @@ class State:
|
|||||||
super().__init__()
|
super().__init__()
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
|
||||||
|
return type(self).__name__
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
|
|
||||||
pass
|
pass
|
||||||
@@ -225,10 +225,6 @@ class ErrorState(State):
|
|||||||
self.is_running = is_running
|
self.is_running = is_running
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
|
|
||||||
return 'ErrorState'
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def origin(self):
|
def origin(self):
|
||||||
|
|
||||||
@@ -302,10 +298,6 @@ class TeardownState(State):
|
|||||||
super().__init__()
|
super().__init__()
|
||||||
self._target = target
|
self._target = target
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
|
|
||||||
return 'TeardownState'
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def target(self):
|
def target(self):
|
||||||
|
|
||||||
@@ -328,10 +320,6 @@ class WelcomeState(State):
|
|||||||
|
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
|
|
||||||
return 'WelcomeState'
|
|
||||||
|
|
||||||
def handleEvent(self, event, context):
|
def handleEvent(self, event, context):
|
||||||
|
|
||||||
if isinstance(event, GuiEvent):
|
if isinstance(event, GuiEvent):
|
||||||
@@ -349,10 +337,6 @@ class StartupState(State):
|
|||||||
|
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
|
|
||||||
return 'StartupState'
|
|
||||||
|
|
||||||
def handleEvent(self, event, context):
|
def handleEvent(self, event, context):
|
||||||
|
|
||||||
if isinstance(event, CameraEvent) and event.name == 'ready':
|
if isinstance(event, CameraEvent) and event.name == 'ready':
|
||||||
@@ -368,10 +352,6 @@ class IdleState(State):
|
|||||||
|
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
|
|
||||||
return 'IdleState'
|
|
||||||
|
|
||||||
def handleEvent(self, event, context):
|
def handleEvent(self, event, context):
|
||||||
|
|
||||||
if ((isinstance(event, GuiEvent) or isinstance(event, GpioEvent)) and
|
if ((isinstance(event, GuiEvent) or isinstance(event, GpioEvent)) and
|
||||||
@@ -387,10 +367,6 @@ class GreeterState(State):
|
|||||||
|
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
|
|
||||||
return 'GreeterState'
|
|
||||||
|
|
||||||
def handleEvent(self, event, context):
|
def handleEvent(self, event, context):
|
||||||
|
|
||||||
if ((isinstance(event, GuiEvent) or isinstance(event, GpioEvent)) and
|
if ((isinstance(event, GuiEvent) or isinstance(event, GpioEvent)) and
|
||||||
@@ -408,10 +384,6 @@ class CountdownState(State):
|
|||||||
|
|
||||||
self._num_picture = num_picture
|
self._num_picture = num_picture
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
|
|
||||||
return 'CountdownState'
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def num_picture(self):
|
def num_picture(self):
|
||||||
|
|
||||||
@@ -435,10 +407,6 @@ class CaptureState(State):
|
|||||||
|
|
||||||
self._num_picture = num_picture
|
self._num_picture = num_picture
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
|
|
||||||
return 'CaptureState'
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def num_picture(self):
|
def num_picture(self):
|
||||||
|
|
||||||
@@ -460,10 +428,6 @@ class AssembleState(State):
|
|||||||
|
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
|
|
||||||
return 'AssembleState'
|
|
||||||
|
|
||||||
def handleEvent(self, event, context):
|
def handleEvent(self, event, context):
|
||||||
|
|
||||||
if isinstance(event, CameraEvent) and event.name == 'review':
|
if isinstance(event, CameraEvent) and event.name == 'review':
|
||||||
@@ -477,16 +441,12 @@ class ReviewState(State):
|
|||||||
def __init__(self, picture):
|
def __init__(self, picture):
|
||||||
|
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self._picture = picture
|
self._picture = util.pickle_image(picture)
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
|
|
||||||
return 'ReviewState'
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def picture(self):
|
def picture(self):
|
||||||
|
|
||||||
return self._picture
|
return util.unpickle_image(self._picture)
|
||||||
|
|
||||||
def handleEvent(self, event, context):
|
def handleEvent(self, event, context):
|
||||||
|
|
||||||
@@ -502,10 +462,6 @@ class PostprocessState(State):
|
|||||||
|
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
|
|
||||||
return 'PostprocessState'
|
|
||||||
|
|
||||||
def handleEvent(self, event, context):
|
def handleEvent(self, event, context):
|
||||||
|
|
||||||
if ((isinstance(event, GuiEvent) or isinstance(event, GpioEvent)) and
|
if ((isinstance(event, GuiEvent) or isinstance(event, GpioEvent)) and
|
||||||
|
|||||||
@@ -19,6 +19,8 @@
|
|||||||
|
|
||||||
import importlib
|
import importlib
|
||||||
|
|
||||||
|
from PIL import Image
|
||||||
|
|
||||||
|
|
||||||
def lookup_and_import(module_list, name, package=None):
|
def lookup_and_import(module_list, name, package=None):
|
||||||
|
|
||||||
@@ -36,3 +38,21 @@ def lookup_and_import(module_list, name, package=None):
|
|||||||
return import_module
|
return import_module
|
||||||
else:
|
else:
|
||||||
return getattr(import_module, result[1])
|
return getattr(import_module, result[1])
|
||||||
|
|
||||||
|
|
||||||
|
def pickle_image(image):
|
||||||
|
|
||||||
|
if image is None:
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
image_data = (image.mode, image.size, image.tobytes())
|
||||||
|
return image_data
|
||||||
|
|
||||||
|
|
||||||
|
def unpickle_image(image_data):
|
||||||
|
|
||||||
|
if image_data is None:
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
image = Image.frombytes(*image_data)
|
||||||
|
return image
|
||||||
|
|||||||
Reference in New Issue
Block a user