Hei
Found a solution using curry to supply an additional argument to the
OnLeftDown and OnMouseMove buttons. If I add the x and y position of
the label on the Frame to the x and y position returned by
self.ClientToScreen(evt.GetPosition()) the mouse behaves as it should.
Here is the code if anybody are interested:
# Binding to frame itself:
self.Bind(wx.EVT_LEFT_DOWN, curry(self.OnLeftDown, None))
self.Bind(wx.EVT_MOTION, curry(self.OnMouseMove, None))
# Binding to label:
label.Bind(wx.EVT_LEFT_DOWN, curry(self.OnLeftDown, (label_x_pos, label_y_pos)))
# Moving stuff
def OnLeftDown(self, pos, evt):
self.CaptureMouse()
x, y = self.ClientToScreen(evt.GetPosition())
if pos != None:
x += pos[0]
y += pos[1]
originx, originy = self.GetPosition()
dx = x - originx
dy = y - originy
self.delta = ((dx, dy))
def OnMouseMove(self, pos, evt):
if evt.Dragging() and evt.LeftIsDown():
x, y = self.ClientToScreen(evt.GetPosition())
if pos != None:
x += pos[0]
y += pos[1]
fp = (x - self.delta[0], y - self.delta[1])
self.Move(fp)
You can read about the curry class you also will need here:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52549
- Rune
ยทยทยท
On 5/6/05, Rune Devik <rune.devik@gmail.com> wrote:
Hei
Thanks for the answer, but this looks like what I have already tried.
Pasting some code here:self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown, None)
self.Bind(wx.EVT_MOTION, self.OnMouseMove, None)def OnLeftDown(self, evt):
self.CaptureMouse()
x, y = self.ClientToScreen(evt.GetPosition())
originx, originy = self.GetPosition()
dx = x - originx
dy = y - originy
self.delta = ((dx, dy))def OnMouseMove(self, evt):
if evt.Dragging() and evt.LeftIsDown():
x, y = self.ClientToScreen(evt.GetPosition())
fp = (x - self.delta[0], y - self.delta[1])
self.Move(fp)These are the methods handling the events for the frame. When I tried
to bind the same methods to the labels it worked but the mouse itself
changed position from the middle of the frame to the upper right
corner. Probably because when the event is triggered I get the
position relative to the label and not the Frame. Is there a way to
get the position of the mouse relative to the parent frame and not the
label? Or any other ideas on how I can avoid this?- Rune
On 5/6/05, Vladimir Ignatov <vignatov@colorpilot.com> wrote:
> Hi,
>
> >I have a frame that I can move around when
> >holding down the left mouse button. Then I added a few GenStaticText
> >labels to the frame. The problem is that I want to be able to move the
> >frame around as before regardless if the user presses the left mouse
> >button down over the labels (GenStaticText widget) or the frame
> >itself. I have tried to bind the same OnLeftDown and OnMouseMove
> >events to the labels using the same functions as the frame but this
> >does not give me the correct behavior. Probably because the
> >GetPosition call returns the position inside the label and not the
> >mouse position within the frame itself...?
>
> Yes, it is "by design".
> event.GetPosition() coordinates are client coordinates inside the "catcher"
> window.
>
> >What I'm looking for is probably how I can make the label just
> >propagate the events in question to the parent Frame. But how can this
> >be done, and will GetPosition then return the correct position within
> >the frame so that it is moved correctly? Or is there another way to do
> >this?
>
> I can think of several possible ways. Your label can have a reference to
> frame or use label.GetParent() and move frame directly inside the MOTION
> handler. Use label.ClientToScreen function for coordinate translating.
> Another way is to use frame.CaptureMouse() in label.OnMouseDown handler.
> Don't forget to release mouse back using ReleaseMouse().
>
> Beware on one pitfall. Once you Move() window (your frame), you will
> immediately receive another MOTION event because mouse's "relative" (to the
> window) position is changed. If your code does not ready to handle this
> additional event, then you can see some funny behaviour (like small "jitter"
> while moving your frame).
>
> Vladimir Ignatov
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
> For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org
>
>--
Rune Devik
Siv.ing. Informatikk
--
Rune Devik
Siv.ing. Informatikk