当前位置: 动力学知识库 > 问答 > 编程问答 >

python - wxPython Binding Problem

问题描述:

I'm playing with wxPython event bindings in order to make a dragging algorithm. However I've encountered a problem, when the mouse is not directly over my frame the event doesn't trigger.

This becomes a problem while dragging seeing as if the mouse escapes the frame (like if the user moved it quickly), the frame neglects to update it's position.

Is there anyway to change the bindings so that they trigger even if the mouse isn't over the frame in question?

Snippet:

 self.Bind(wx.EVT_LEFT_DOWN, self.relative_mouse_position)

self.Bind(wx.EVT_LEFT_UP, self.wid_unbind)

Snippet:

def relative_mouse_position (self, event):

cx, cy = wx.GetMousePosition()

x, y = self.GetPosition()

RelX = cx - x

RelY = cy - y

self.Bind(wx.EVT_MOTION, lambda event: self.wid_drag(event, RelX, RelY))

def wid_drag (self, event, RelX, RelY):

cx, cy = wx.GetMousePosition()

x = cx - RelX

y = cy - RelY

if x < 0:

x = 0

if y < 0:

y = 0

self.SetPosition((x, y))

def wid_unbind (self, event):

self.Unbind(wx.EVT_MOTION)

网友答案:

When you start a drag, call CaptureMouse to keep the mouse locked to the window that you're dragging.

网友答案:

Not tested but probably bind, EVT_LEAVE_WINDOW to trigger when mouse is outside window.

分享给朋友:
您可能感兴趣的文章:
随机阅读: