wxGTK ProgressDialog in Idle loop crashes

Pim Buurman wrote:

Hello List,

I have the following situation:
some frame with a fancy picture, where the picture needs to be recalculated.
I do this in an idle loop and use ProgressDialog to inform the user that something is happening.

Now, the first idel event does ProgressDialog.Update(1, "..") but does not seem to finish,
but the next idle events are handled.
When I Destroy the ProgressDialog, the first idle event delivers its update to the ProgressDialog. But it is explicitly forbidden to decrease the value of the Gauge, so the
program crashes.

See below.

A related question:
The idle loop on GTK does not start, unless you Refresh the ProgressDialog.

Try calling wx.WakeUpIdle() instead.

Code snippet:
        self._idleState = None
        self._idleProgress = wx.ProgressDialog('Processing', '/',
                N, self, wx.PD_CAN_ABORT | wx.PD_APP_MODAL)
        self._idleProgress.Refresh() # On GTK, force en event
        self._idleState = fs.nChildren(-1)

    def onIdle(self, evt):
        if self._idleState == None:
            return
        initF, contextF, getContextF = contextTypes[self._type]
        mapd = self.mapdata
        fs = self.mapdata.coll
        low = self._idleState
        high = min(low + 500, len(fs))
        isSize = self._size == 'Size'
        for i in xrange(low, high):
            if isSize:
                N = int((fs._getSize(i, fs) + 1023) / 1024)
                if N == 0:
                    continue
            else:
                N = 1
            cxt = getContextF(fs, i)
            mapd.add(fs.parentId(i), cxt, N)
        if high < len(fs):
            self._idleState = high
            print 'update', high / 500
            res = self._idleProgress.Update(high / 500, fs.getPathName(high - 1))
            print 'updated', high / 500
            evt.RequestMore()
            if not res:
                self.restoreMenu(self._idleMode)
                self._idleState = None
                mapd.restore()
                self._idleProgress.Destroy()

Perhaps a evt.RequestMore(0) here would help?

            return
        self._idleState = None
        self._idleProgress.Destroy()
        evt.RequestMore(0)
        mapd.finish()
        self.treemap.newContexts(self._idleMode)

If that doesn't help then please create a small as possible standalone sample that shows the problem.

ยทยทยท

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!