Why is WxPythons motion detection so slow?
python, wxpython
Solution
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:
- If your drawing that stuff yourself, ensure that you are using double buffering (via wx.BufferedPaintDC);
- If your paint routine is indeed called between mouse motions, try and refresh only the damaged portion of your plot (via RefreshRect);
- Use wx.Overlay to draw your rectangular selection (there are a few demos available on how to do that);
- Post a small, runnable sample app that demonstrate the problem.
Problem
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. 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 ```