webview and agw.persist

Hi,

Experimenting with webview to display Sphinx generated files - works pretty well, except if the frame is closed and opened again during the same session.

If I close the help frame by clicking the "X" and then open help again I get this exception.

wx._core.PyDeadObjectError: The C++ part of the SizedFrame object has been deleted, attribute access no longer allowed.
File "c:\dev\twcbv4\twcbsrc\controllers\app_cb.py", line 1157, in <module>
   app.MainLoop()
File "c:\Python27\Lib\site-packages\wx-2.9.5-msw\wx\_core.py", line 8660, in MainLoop
   wx.PyApp.MainLoop(self)
File "c:\Python27\Lib\site-packages\wx-2.9.5-msw\wx\_core.py", line 7952, in MainLoop
   return _core_.PyApp_MainLoop(*args, **kwargs)
File "c:\dev\twcbv4\twcbsrc\controllers\base.py", line 1587, in onMenuHelp
   hc = self.initHelp()
File "c:\dev\twcbv4\twcbsrc\controllers\base.py", line 1614, in initHelp
   self.persistMgr.Restore(self._hc)
File "c:\Python27\Lib\site-packages\wx-2.9.5-msw\wx\lib\agw\persist\persistencemanager.py", line 540, in Restore
   return self._persistentObjects[name].Restore()
File "c:\Python27\Lib\site-packages\wx-2.9.5-msw\wx\lib\agw\persist\persistencemanager.py", line 144, in Restore
   return self._persistentHandler.Restore()
File "c:\Python27\Lib\site-packages\wx-2.9.5-msw\wx\lib\agw\persist\persist_handlers.py", line 423, in Restore
   tlw.Move(wx.Point(x, y), wx.SIZE_ALLOW_MINUS_ONE)
File "c:\Python27\Lib\site-packages\wx-2.9.5-msw\wx\_core.py", line 16723, in __getattr__
   raise PyDeadObjectError(self.attrStr % self._name)

The code to start/close the help frame is below, can someone see what I am doing wrong.
Werner

     def initHelp(self):
         """Initiallize the help controller"""
         if self._hc:
             return self._hc

         self._hc = sc.SizedFrame(self.view, name="helpController")
         self._hc.SetTitle(_(u"Help for The Wine Cellar Book"))
         myIcon = uiutils.getImageResource('twcb-64.png', True, True)
         self._hc.SetIcon(myIcon)
         self._hc.Bind(wx.EVT_CLOSE, self.onCloseHC)

         self.wv = webview.WebView.New(self._hc.GetContentsPane(),
                                       name="helpWebview")
         self.wv.SetSizerProps(expand=True, proportion=1)

         hDir = os.path.join(wx.GetApp().getDirLocations()[1], 'help')
         helpfile = os.path.join(hDir, "index.html")

         self.wv.LoadURL(helpfile)
         self._hc.Show()

         if self.persistMgr.Find(self._hc):
             self.persistMgr.Restore(self._hc) # < line 1614 in controllers.base
         else:
             self.persistMgr.RegisterAndRestoreAll(self._hc)

         return self._hc

     def onCloseHC(self, evt):
         """Close handler for the help controller"""
         if self._hc:
             cf = self.persistMgr.GetPersistenceFile()
             self.persistMgr.Save(self._hc)
             cf.Flush()
             self._hc = None
         evt.Skip()

Werner wrote:

Hi,

Experimenting with webview to display Sphinx generated files - works
pretty well, except if the frame is closed and opened again during the
same session.

If I close the help frame by clicking the "X" and then open help again I
get this exception.

wx._core.PyDeadObjectError: The C++ part of the SizedFrame object has
been deleted, attribute access no longer allowed.
File "c:\dev\twcbv4\twcbsrc\controllers\app_cb.py", line 1157, in <module>
app.MainLoop()
File "c:\Python27\Lib\site-packages\wx-2.9.5-msw\wx\_core.py", line
8660, in MainLoop
wx.PyApp.MainLoop(self)
File "c:\Python27\Lib\site-packages\wx-2.9.5-msw\wx\_core.py", line
7952, in MainLoop
return _core_.PyApp_MainLoop(*args, **kwargs)
File "c:\dev\twcbv4\twcbsrc\controllers\base.py", line 1587, in onMenuHelp
hc = self.initHelp()
File "c:\dev\twcbv4\twcbsrc\controllers\base.py", line 1614, in initHelp
self.persistMgr.Restore(self._hc)
File
"c:\Python27\Lib\site-packages\wx-2.9.5-msw\wx\lib\agw\persist\persistencemanager.py",
line 540, in Restore
return self._persistentObjects[name].Restore()
File
"c:\Python27\Lib\site-packages\wx-2.9.5-msw\wx\lib\agw\persist\persistencemanager.py",
line 144, in Restore
return self._persistentHandler.Restore()
File
"c:\Python27\Lib\site-packages\wx-2.9.5-msw\wx\lib\agw\persist\persist_handlers.py",
line 423, in Restore
tlw.Move(wx.Point(x, y), wx.SIZE_ALLOW_MINUS_ONE)
File "c:\Python27\Lib\site-packages\wx-2.9.5-msw\wx\_core.py", line
16723, in __getattr__
raise PyDeadObjectError(self.attrStr % self._name)

The code to start/close the help frame is below, can someone see what I
am doing wrong.
Werner

def initHelp(self):
"""Initiallize the help controller"""
if self._hc:
return self._hc

self._hc = sc.SizedFrame(self.view, name="helpController")
self._hc.SetTitle(_(u"Help for The Wine Cellar Book"))
myIcon = uiutils.getImageResource('twcb-64.png', True, True)
self._hc.SetIcon(myIcon)
self._hc.Bind(wx.EVT_CLOSE, self.onCloseHC)

self.wv = webview.WebView.New(self._hc.GetContentsPane(),
name="helpWebview")
self.wv.SetSizerProps(expand=True, proportion=1)

hDir = os.path.join(wx.GetApp().getDirLocations()[1], 'help')
helpfile = os.path.join(hDir, "index.html")

self.wv.LoadURL(helpfile)
self._hc.Show()

if self.persistMgr.Find(self._hc):
self.persistMgr.Restore(self._hc) # < line 1614 in controllers.base
else:
self.persistMgr.RegisterAndRestoreAll(self._hc)

return self._hc

def onCloseHC(self, evt):
"""Close handler for the help controller"""
if self._hc:
cf = self.persistMgr.GetPersistenceFile()
self.persistMgr.Save(self._hc)
cf.Flush()
self._hc = None
evt.Skip()

I don't know agw.persist that well, but don't you need to call self.persistMgr.SaveAndUnregister from the EVT_CLOSE handler?

···

--
Robin Dunn
Software Craftsman

Hi Robin,

Werner wrote:

...

I don't know agw.persist that well, but don't you need to call self.persistMgr.SaveAndUnregister from the EVT_CLOSE handler?

Absolutely correct - don't know why I didn't catch on to that one.

Thanks
Werner

···

On 28/03/2013 17:49, Robin Dunn wrote: