[wxPython-users] Print framework on separate thread

Luca Tavoletti luca.tavoletti at gmail.com
Thu May 3 04:48:39 PDT 2007


Hi Andrea,

my program send a lot of pages to printer, and after each print (if
ok) a progress bar is
updated, but if a print return an error I need to stop the execution (thread)
and manage the error.
If I use evet or call after I lose the print return...

Luca.

On 5/3/07, Andrea Gavana <andrea.gavana at gmail.com> wrote:
> Hi Luca,
>
> On 5/3/07, Luca Tavoletti wrote:
> > It's possible to use the wx print framework inside a secondary thread?
>
> The short answer is: no.
>
> > My main frame launch a thread that run a long task and at the end send
> > a print but
> > when:
> >
> > class MyPrintout(wx.Printout):
> > ...
> > def OnPrintPage(self, page):
> >  dc = self.GetDC()                <<<<<<<<<<<<<<
> > ...
> >
> > I've this error:
> > ....
> > wx._core.PyAssertionError: C++ assertion "wxThread::IsMain()" failed
> > at ..\..\src\msw\evtloop.cpp(244) in wxEventLoop::Dispatch(): only the
> > main thread can process Windows messages
>
> You can't generally call wx methods inside threads that are *not* the
> main GUI thread.
>
> > Is there any workaround to do this without use the post-event model?
>
> Is using:
>
> wx.CallAfter(WhateverMethodYouWant)
>
> considered as post-event method? Why are you so concerned about
> posting events? However, the simplest and safest approach is to use
> wx.CallAfter from your secondary thread to call the main GUI thread
> print methods.
>
> Andrea.
>
> "Imagination Is The Only Weapon In The War Against Reality."
> http://xoomer.virgilio.it/infinity77/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wxPython-users-unsubscribe at lists.wxwidgets.org
> For additional commands, e-mail: wxPython-users-help at lists.wxwidgets.org
>
>




More information about the wxpython-users mailing list