Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is WxPythons motion detection so slow?

I set the on_motion to handle EVT_MOTION. I want the mouse location for interactively generating a coordinate-specific image, but WxPython has a ~400ms delay in registering successive motion events. Which makes the interface sluggish.

Why is EVT_MOTION so slow and how do I fix it? I tried it in Ubuntu 11.10 and WinXP and the delays are comparable?

I need fast response times for selecting a portion from an image like the picture shows. As it stands, the "cross-hairs" follow the mouse too slowly.

enter image description here

Here is the code which I tried EVT_MOTION:

def on_motion(self, event):
    """mouse in motion"""
    #pt = event.GetPosition()
    self.mouseover_location = event.GetPosition()
    self.t2 = time.time()
    print "delay",self.t2 - self.t1
    self.t1 = self.t2

delay 0.379776954651
delay 0.00115919113159
delay 0.421130895615
delay 0.416938066483
delay 0.376848936081
delay 0.387464046478
delay 0.40311384201
delay 0.392899036407
delay 0.385301113129
delay 0.422554969788
delay 0.355197906494
like image 387
Jesvin Jose Avatar asked Jun 01 '12 11:06

Jesvin Jose


2 Answers

The question as it stands is incomplete, as there is no sample app to demonstrate the problem. However, I would say that the motion handler has got nothing to do with your problem, because most likely you are doing some expensive operation between subsequent motion handlers (like refreshing your entire drawing canvas).

If this is the case (and you can easily check if your paint routine is called between mouse motion events), I would suggest the following:

  1. If your drawing that stuff yourself, ensure that you are using double buffering (via wx.BufferedPaintDC);
  2. If your paint routine is indeed called between mouse motions, try and refresh only the damaged portion of your plot (via RefreshRect);
  3. Use wx.Overlay to draw your rectangular selection (there are a few demos available on how to do that);
  4. Post a small, runnable sample app that demonstrate the problem.
like image 59
Infinity77 Avatar answered Nov 18 '22 23:11

Infinity77


The EVT_MOTION is fired every time the mouse is moved! If you then call event.GetPosition() on every movement and also process the data, this will slow down performance. How would it be to use EVT_LEFT_DOWN or something similar, and then get the position and process that data. This will be much more efficient since you are only looking for a certain area of the image.

like image 2
Gerald Spreer Avatar answered Nov 18 '22 21:11

Gerald Spreer