[ocrfeeder/new_fixes: 6/10] add __setstate__ and __getstate__ to the DataBox
- From: Joaquim Manuel Pereira Rocha <jrocha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ocrfeeder/new_fixes: 6/10] add __setstate__ and __getstate__ to the DataBox
- Date: Mon, 1 Oct 2012 19:51:18 +0000 (UTC)
commit cf4aeca93717d3bd2141006ed66604a3cae401c6
Author: Jan Losinski <losinski wh2 tu-dresden de>
Date: Fri Jul 27 15:13:45 2012 +0200
add __setstate__ and __getstate__ to the DataBox
This is needed for proper pickling and unpickling of the boxes
Signed-off-by: Jan Losinski <losinski wh2 tu-dresden de>
src/ocrfeeder/studio/dataHolder.py | 13 +++++++++++++
1 files changed, 13 insertions(+), 0 deletions(-)
---
diff --git a/src/ocrfeeder/studio/dataHolder.py b/src/ocrfeeder/studio/dataHolder.py
index 82c89cd..2c1b2e1 100644
--- a/src/ocrfeeder/studio/dataHolder.py
+++ b/src/ocrfeeder/studio/dataHolder.py
@@ -81,6 +81,19 @@ class DataBox(gobject.GObject):
self.text_data = TextData()
self.text = text
+ def __setstate__(self, state):
+ state['image'] = Image.fromstring(*state['_image_state'])
+ del state['_image_state']
+ self.__dict__.update(state)
+ super(DataBox, self).__init__()
+ self.setType(self.type)
+
+ def __getstate__(self):
+ state = self.__dict__
+ state["_image_state"] = (state["image"].mode, (state["image"].size[0], state["image"].size[1]), state["image"].tostring())
+ del state["image"]
+ return state
+
def configTextData(self, face = 'Sans', size = 12, justification = ALIGN_LEFT, line_space = 1, letter_space = 1):
self.text_data = TextData(face, size, justification, line_space, letter_space)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]