Button drag

philippe DALET <[email protected]> Sat, 8 Jun 2019 02:28:35 -0700 (PDT)
Newsgroups gmane.comp.python.wxpython.devel
Message-ID <[email protected]>
------=_Part_1098_86659125.1559986115835
Content-Type: multipart/alternative; 
	boundary="----=_Part_1099_1744923192.1559986115836"

------=_Part_1099_1744923192.1559986115836
Content-Type: text/plain; charset="UTF-8"

Hello

I try to drag a button with the mouse on a panel.

It works fine on win7 (64bits) with wxpython 4.0.6.  py3.7.3

On Ubuntu 18.04--16.04  (64bits) with wxpython 4.0.6. GTK2 py3.5 or py3.6, 
a capturelost event appears, and after my script is out of control.
Only alt+F4 can stop the script.

if I change the code like this
    def OnMouseDown(self, event):
        self.btn.CaptureMouse()
        self.btn.ReleaseMouse()
it works fine.

How to avert this event ?

Thanks for your reply.

Ph.DALET

-- 
You received this message because you are subscribed to the Google Groups "wxPython-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/wxPython-dev/83f704c6-a6d7-443e-a0bc-34d38b7c4d43%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

------=_Part_1099_1744923192.1559986115836
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>Hello</div><div><br></div><div>I try to drag a button=
 with the mouse on a panel.</div><div><br></div><div>It works fine on win7 =
(64bits) with wxpython 4.0.6.=C2=A0 py3.7.3</div><div><br></div><div>On Ubu=
ntu 18.04--16.04=C2=A0  (64bits) with wxpython 4.0.6. GTK2  py3.5 or py3.6,=
 a capturelost event appears, and after my script is out of control.</div><=
div>Only alt+F4 can stop the script.<br></div><div><br></div><div>if I chan=
ge the code like this</div><div>=C2=A0=C2=A0=C2=A0 def OnMouseDown(self, ev=
ent):<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 self.btn.CaptureMouse()=
</div><div>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 self.btn.ReleaseMouse=
()<br></div><div></div><div></div><div>it works fine.</div><div><br></div><=
div>How to avert this event ?<br></div><div><br></div><div>Thanks for your =
reply.<br></div><div><br></div><div></div><div>Ph.DALET<br></div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;wxPython-dev&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:[email protected]">wxPyth=
[email protected]</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/d/msgid/wxPython-dev/83f704c6-a6d7-443e-a0bc-34d38b7c4d43%40googlegroups=
.com?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.com/d/ms=
gid/wxPython-dev/83f704c6-a6d7-443e-a0bc-34d38b7c4d43%40googlegroups.com</a=
>.<br />
For more options, visit <a href=3D"https://groups.google.com/d/optout">http=
s://groups.google.com/d/optout</a>.<br />

------=_Part_1099_1744923192.1559986115836--

------=_Part_1098_86659125.1559986115835
Content-Type: text/x-python; charset=US-ASCII; name=buttonDrag.py
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename=buttonDrag.py
X-Attachment-Id: 82208593-4ef7-4f47-b9ce-0171f882c137
Content-ID: <82208593-4ef7-4f47-b9ce-0171f882c137>

import wx
import time

class Mywin(wx.Frame): 
    def __init__(self, parent, title): 
        super(Mywin, self).__init__(parent, title = title,size = (400,200))  
        self.InitUI()
        self.Centre() 
      
    def InitUI(self):
        self.panel = wx.Panel(self)
        vbox = wx.BoxSizer(wx.VERTICAL) 
        self.btn = wx.Button(self.panel,-1,"click Me",pos=(10, 10)) 
        vbox.Add(self.btn,0,wx.ALIGN_CENTER) 

        self.btn.Bind(wx.EVT_LEFT_DOWN, self.OnMouseDown)
        self.btn.Bind(wx.EVT_MOTION,  self.OnMouseMove)
        self.btn.Bind(wx.EVT_LEFT_UP,  self.OnMouseUp)
        self.btn.Bind(wx.EVT_MOUSE_CAPTURE_LOST, self.OnCaptureLost)
        print ("Init pos:",self.btn.GetPosition())

    def OnMouseDown(self, event):
        self.btn.CaptureMouse()
        print ("Left Down")
        sx,sy   = self.panel.ScreenToClient(self.btn.GetPosition())
        dx,dy  = self.panel.ScreenToClient(wx.GetMousePosition())
        self.btn._x,self.btn._y   = (sx-dx, sy-dy)

    def OnMouseMove(self, event):
        if event.Dragging() and event.LeftIsDown():
               x, y = wx.GetMousePosition()
               self.btn.SetPosition(wx.Point(x+self.btn._x,y+self.btn._y))
               print(self.btn.GetPosition())

    def OnMouseUp(self, event):
        if (self.btn.HasCapture()): 
                self.btn.ReleaseMouse()
        print ("Final pos:",self.btn.GetPosition())

    def OnCaptureLost(self, event):
        print ("Err")
        print(self.btn.GetCapture())



def main():
        app = wx.App()
        w = Mywin(None, title='Button drag demo')
        w.Show()
        app.MainLoop()


if __name__ == '__main__':
       main()


------=_Part_1098_86659125.1559986115835--