Is it possible to process a custom event before a window has been created?
Maybe, it depends on how you need it to work. There has to be an object derived from wx.EvtHandler to bind the handler and to receive the event, and unless the MainLoop is running you will only be able to do immediate event processing, not holding the event for processing later. For example, you could bind a handler to the wx.App object, and then send it an event with wx.GetApp().ProcessEvent(event), but with those limitations you may as well just call the method directly.
···
On Friday, February 23, 2018 at 12:17:09 PM UTC-8, kg*2 wrote:
Is it possible to process a custom event before a window has been created?
–
Robin Dunn
Software Craftsman
I use a background thread to contact a server and then use PostEvent to deliver the results to the main thread. This has created a race condition where the server thread can sometimes (1 in a 100) return before the main window has been created. I’m currently creating a temporary wx.Frame and posting the event to that to work around the issue, but I figured there was a better way to do it.
···
On Monday, February 26, 2018 at 10:56:35 AM UTC-8, Robin Dunn wrote:
On Friday, February 23, 2018 at 12:17:09 PM UTC-8, kg*2 wrote:
Is it possible to process a custom event before a window has been created?
Maybe, it depends on how you need it to work. There has to be an object derived from wx.EvtHandler to bind the handler and to receive the event, and unless the MainLoop is running you will only be able to do immediate event processing, not holding the event for processing later. For example, you could bind a handler to the wx.App object, and then send it an event with wx.GetApp().ProcessEvent(event), but with those limitations you may as well just call the method directly.
–
Robin Dunn
Software Craftsman
Why don’t you launch your background thread from the main window
_init() method ? I do this in several of my projects at work
without any issue.
···
Le 26/02/2018 à 23:25, kg*2 a écrit :
I use a background thread to contact a server and
then use PostEvent to deliver the results to the main thread.
This has created a race condition where the server thread can
sometimes (1 in a 100) return before the main window has been
created. I’m currently creating a temporary wx.Frame and posting
the event to that to work around the issue, but I figured there
was a better way to do it.
On Monday, February 26, 2018 at 10:56:35 AM UTC-8, Robin Dunn
wrote:
On Friday, February 23, 2018 at 12:17:09 PM
UTC-8, kg*2 wrote:
Is it possible to process a custom event
before a window has been created?
Maybe, it depends on how you need it to work. There
has to be an object derived from wx.EvtHandler to bind the
handler and to receive the event, and unless the MainLoop
is running you will only be able to do immediate event
processing, not holding the event for processing later.
For example, you could bind a handler to the wx.App
object, and then send it an event with
wx.GetApp().ProcessEvent( event), but with those
limitations you may as well just call the method directly.
–
Robin Dunn
Software Craftsman
–
You received this message because you are subscribed to the Google
Groups “wxPython-dev” group.
To unsubscribe from this group and stop receiving emails from it,
send an email to wxPython-dev+unsubscribe@googlegroups.com.
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
I did consider that, but I need the thread to run even if the init raises an error… I could wrap the window instantiation in a try/finally and still call the thread, but it leaves me with the same problem of not having a window to post the event to. I wasn’t aware that you could bind to the wx.App so I’ll try that and see how it works.
···
On Tuesday, February 27, 2018 at 11:56:09 AM UTC-8, Nicolas Pinault wrote:
Le 26/02/2018 à 23:25, kg*2 a écrit :
I use a background thread to contact a server and
then use PostEvent to deliver the results to the main thread.
This has created a race condition where the server thread can
sometimes (1 in a 100) return before the main window has been
created. I’m currently creating a temporary wx.Frame and posting
the event to that to work around the issue, but I figured there
was a better way to do it.
Why don't you launch your background thread from the main window
_init() method ? I do this in several of my projects at work
without any issue.On Monday, February 26, 2018 at 10:56:35 AM UTC-8, Robin Dunn > > wrote:
On Friday, February 23, 2018 at 12:17:09 PM > > > UTC-8, kg*2 wrote:
Is it possible to process a custom event
before a window has been created?
Maybe, it depends on how you need it to work. There
has to be an object derived from wx.EvtHandler to bind the
handler and to receive the event, and unless the MainLoop
is running you will only be able to do immediate event
processing, not holding the event for processing later.
For example, you could bind a handler to the wx.App
object, and then send it an event with
wx.GetApp().ProcessEvent( event), but with those
limitations you may as well just call the method directly.
–
Robin Dunn
Software Craftsman
–
You received this message because you are subscribed to the Google
Groups “wxPython-dev” group.
To unsubscribe from this group and stop receiving emails from it,
send an email to wxPython-dev...@googlegroups.com.
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
posting to binding and posting to wx.GetApp() works flawlessly. Thanks Robin
···
On Wednesday, February 28, 2018 at 9:17:59 AM UTC-8, kg*2 wrote:
I did consider that, but I need the thread to run even if the init raises an error… I could wrap the window instantiation in a try/finally and still call the thread, but it leaves me with the same problem of not having a window to post the event to. I wasn’t aware that you could bind to the wx.App so I’ll try that and see how it works.
On Tuesday, February 27, 2018 at 11:56:09 AM UTC-8, Nicolas Pinault wrote:
Le 26/02/2018 à 23:25, kg*2 a écrit :
I use a background thread to contact a server and
then use PostEvent to deliver the results to the main thread.
This has created a race condition where the server thread can
sometimes (1 in a 100) return before the main window has been
created. I’m currently creating a temporary wx.Frame and posting
the event to that to work around the issue, but I figured there
was a better way to do it.
Why don't you launch your background thread from the main window
_init() method ? I do this in several of my projects at work
without any issue.On Monday, February 26, 2018 at 10:56:35 AM UTC-8, Robin Dunn > > > wrote:
On Friday, February 23, 2018 at 12:17:09 PM > > > > UTC-8, kg*2 wrote:
Is it possible to process a custom event
before a window has been created?
Maybe, it depends on how you need it to work. There
has to be an object derived from wx.EvtHandler to bind the
handler and to receive the event, and unless the MainLoop
is running you will only be able to do immediate event
processing, not holding the event for processing later.
For example, you could bind a handler to the wx.App
object, and then send it an event with
wx.GetApp().ProcessEvent( event), but with those
limitations you may as well just call the method directly.
–
Robin Dunn
Software Craftsman
–
You received this message because you are subscribed to the Google
Groups “wxPython-dev” group.
To unsubscribe from this group and stop receiving emails from it,
send an email to wxPython-dev...@googlegroups.com.
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).