Print framework on separate thread

Hi all,
It's possible to use the wx print framework inside a secondary thread?

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

Is there any workaround to do this without use the post-event model?

I've also attached a simple demo.

Tanks in Advance,
Luca.

test_print_thread.py (1.07 KB)

Hi Luca,

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/

···

On 5/3/07, Luca Tavoletti wrote:

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@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@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org