Accessing wx.* from a thread

I know that modifying UI elements from a thread is bad-mojo, but what
about calling methods attached to a class inheriting from a wx object?

In particular, I have a class that inherits from wx.Frame, to which
I've added a few of my own methods. Is it ok for a thread to call one
of those methods, as long as that method does not affect any of the UI
elements? Or should all interaction between threads and anything
deriving from wx.* happen through events?

Thanks,
Jay P.

Hello,

···

On Thu, Dec 4, 2008 at 2:44 PM, Jay Parlar parlar@gmail.com wrote:

I know that modifying UI elements from a thread is bad-mojo, but what

about calling methods attached to a class inheriting from a wx object?

In particular, I have a class that inherits from wx.Frame, to which

I’ve added a few of my own methods. Is it ok for a thread to call one

of those methods, as long as that method does not affect any of the UI

elements? Or should all interaction between threads and anything

deriving from wx.* happen through events?

Yes, As long as your method doesn’t try to modify or call on anything belonging to the underlying control, and that you preserve the safety of manipulating your own data. Meaning if your methods may be called by multiple threads wanting to manipulate the same data at the same time you will run into the same problem as calling the gui from a background thread unless you employ some precautions in your methods (i.e a mutex). Google “thread safety” if you need more info.

Cody

Ok, that's what I thought. Along the same lines, does a wx.Timer run
in a separate thread, or is part of the UI thread context? I'm
planning on having a wx.Timer touching parts of the UI, but I can't
tell if behind the scenes it's running in a thread.

Jay P.

···

On Thu, Dec 4, 2008 at 4:03 PM, Cody Precord <codyprecord@gmail.com> wrote:

Yes, As long as your method doesn't try to modify or call on anything
belonging to the underlying control, and that you preserve the safety of
manipulating your own data. Meaning if your methods may be called by
multiple threads wanting to manipulate the same data at the same time you
will run into the same problem as calling the gui from a background thread
unless you employ some precautions in your methods (i.e a mutex). Google
"thread safety" if you need more info.

Hello,

···

On Thu, Dec 4, 2008 at 3:06 PM, Jay Parlar parlar@gmail.com wrote:

On Thu, Dec 4, 2008 at 4:03 PM, Cody Precord codyprecord@gmail.com wrote:

Yes, As long as your method doesn’t try to modify or call on anything

belonging to the underlying control, and that you preserve the safety of

manipulating your own data. Meaning if your methods may be called by

multiple threads wanting to manipulate the same data at the same time you

will run into the same problem as calling the gui from a background thread

unless you employ some precautions in your methods (i.e a mutex). Google

“thread safety” if you need more info.

Ok, that’s what I thought. Along the same lines, does a wx.Timer run

in a separate thread, or is part of the UI thread context? I’m

planning on having a wx.Timer touching parts of the UI, but I can’t

tell if behind the scenes it’s running in a thread.

No, A wx.Timer must run on the Main thread. It will assert if you try to use one on a thread that is not the main thread.

Cody