Benjamin Herwig escribi�:
Hi Steven
Thank you. Sure, that'd be the "easiest" method. But I'm looking for a
more nifty way to make m objects and their data persistent.
Maybe someone else has any idea. If not: Steven's idea is the way to
go.
Benjamin, you can pickle swig objects making a simple hack to wx, this is, replacing the __reduce__ method.
I'm doing it for pickle wx.Bitmap, wx.Image, wx.Brush, etc..
I think that you can use the same technique to implementing new __reduce__ or __method in an event object
Example: pickling a wx.Font object:
>>> # Create a new reduce function:
>>> def _reduce_Font(self):
... if not self.IsOk():
... # invalid font, need a valid font to pickle
... return (self.__class__,
... (-1, -1, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL))
... else:
... return (self.__class__,
... (self.GetPointSize(),
... self.GetFamily(),
... self.GetStyle(),
... self.GetWeight(),
... self.GetUnderlined(),
... self.GetFaceName(),
... self.GetDefaultEncoding()))
...
>>> # Replace the original Font.__reduce__ method:
>>> wx.Font.__reduce__ = _reduce_Font
>>>
>>> # Now create the font and pickle it
>>> f = wx.Font(16, wx.FONTFAMILY_ROMAN, wx.FONTSTYLE_ITALIC, wx.FONTWEIGHT_BOLD)
>>> pickledFont = pickle.dumps(f)
>>>
>>> type(pickledFont)
<type 'str'>
>>>
>>> # Create new font using the pickled font
>>>
>>> unpickledFont = pickle.loads(pickedFont)
>>>
>>> type(unpickledFont)
<class 'wx._gdi.Font'>
>>>
If yours think that these technique may be interesting, I can wrote a new wiki article to show it with some wx objects.
Regards
···
--
*****************************************
Oswaldo Hern�ndez
oswaldo (@) soft-com (.) es
*****************************************
PD:
Antes de imprimir este mensaje, aseg�rese de que es necesario.
El medio ambiente est� en nuestra mano.