Need to interrupt to check for mouse movement

S

stringy

I have a program that shows a 3d representation of a cell, depending on
some data that it receives from some C++. It runs with wx.timer(500),
and on wx.EVT_TIMER, it updates the the data, and receives it over the
socket.
In my program I also want to be able to rotate the 3d representation,
and can do so, and all the code works. However, I have a problem in
that while the program is updating itself (pretty much all the time
unless I tell it not to), it won't detect mouse motion, I'm guessing
because it doesn't have time to.

Is there any manual way to get a program to check for mouse movement,
that way I'd be able to check for mouse movement half way through my
updating the data over the socket, and then do the necessary rotations
before it finishes updating the data.
 
P

Peter Hansen

stringy said:
I have a program that shows a 3d representation of a cell, depending on
some data that it receives from some C++. It runs with wx.timer(500),
and on wx.EVT_TIMER, it updates the the data, and receives it over the
socket.

It's generally inappropriate to have a GUI program do network
communications in the main GUI thread. You should create a worker
thread and communicate with it using Queues and possibly the
AddPendingEvent() or PostEvent() methods in wx. There should be many
easily accessible examples of how to do such things. Post again if you
need help finding them.

-Peter
 
C

Christopher Subich

Peter said:
It's generally inappropriate to have a GUI program do network
communications in the main GUI thread. You should create a worker
thread and communicate with it using Queues and possibly the
AddPendingEvent() or PostEvent() methods in wx. There should be many
easily accessible examples of how to do such things. Post again if you
need help finding them.

I'd argue that point; it's certainly inappropriate to do
(long-)/blocking/ network communications in a main GUI thread, but
that's just the same as any blocking IO. If the main thread is blocked
on IO, it can't respond to the user which is Bad.

However, instead of building threads (possibly needlessly) and dealing
with synchronization issues, I'd argue that the solution is to use a
nonblocking network IO package that integrates with the GUI event loop.
Something like Twisted is perfect for this task, although it might
involve a significant application restructuring for the grandparent poster.

Since blocking network IO is generally slow, this should help the
grandparent poster -- I am presuming that "the program updating itself"
is an IO-bound, rather than processor-bound process.
 
S

stringy

Cheers for the replies people, but I got it sorted by just whacking in
wx.YieldIfNeeded() in the code before it communicates over the socket.
It's kind of jerky, but it works, where as before I'd click and drag,
and the 3d view wouldn't move for about 20 seconds.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top