The following code behaves in a somewhat unexpected manner: immediately
after undocking, the window can be dragged to a new position, but only
slowly -- if the mouse finds itself outside the window borders, the
window will not receive the mouse move events. One back inside,
dragging resumes. If I release the mouse and then drag the window
again, the window is able to keep up and doesn't suffer the problem it
had before.
What am I overlooking?
···
----------
Keith J. Farmer
kfarmer@thuban.org
http://www.thuban.org
def OnLeftDown(self, evt):
self.CaptureMouse()
pos = self.ClientToScreen(evt.GetPosition())
origin = self.GetPosition()
dx = pos.x - origin.x
dy = pos.y - origin.y
self.delta = wxPoint(dx, dy)
self.startpos = pos
def OnLeftUp(self, evt):
if (self.IsDocked == FALSE):
self.ReleaseMouse()
def OnMouseMove(self, evt):
print "Dragging: %s, LeftIsDown: %s" % (evt.Dragging(),
evt.LeftIsDown())
if evt.Dragging() and evt.LeftIsDown():
pos = self.ClientToScreen(evt.GetPosition())
fp = (pos.x - self.delta.x, pos.y - self.delta.y)
screenSize =
wxPoint(win32api.GetSystemMetrics(win32con.SM_CXSCREEN),win32api.GetSyst
emMetrics(win32con.SM_CYSCREEN))
if (self.IsDocked == FALSE):
self.Move(fp)
print fp
if (pos.x < 20):
self.startpos = pos
self._uEdge = PyAppBar.ABE_LEFT
self.Dock()
elif (pos.y < 20):
self.startpos = pos
self._uEdge = PyAppBar.ABE_TOP
self.Dock()
elif (pos.x > screenSize.x - 20):
self.startpos = pos
self._uEdge = PyAppBar.ABE_RIGHT
self.Dock()
elif (pos.y > screenSize.y - 20):
self.startpos = pos
self._uEdge = PyAppBar.ABE_BOTTOM
self.Dock()
else:
if (abs(pos.x - self.startpos.x) > 100 or
abs(pos.y - self.startpos.y) > 100):
sd = self._SizeDocked['undocked']
winRect = wxRect(sd[0], sd[1],
sd[2]-sd[0], sd[3]-sd[1])
if winRect.GetBottom() <= pos.y:
print "bottom = %s, pos.y = %s,
height = %s" % (winRect.GetBottom(), pos.y, winRect.GetHeight())
winRect.SetY(pos.y -
winRect.GetHeight() + 10)
print "set Y = %s" %
winRect.GetY()
if winRect.GetBottom() > screenSize.y:
print "bottom = %s, screenSize =
%s, height = %s" % (winRect.GetBottom(), screenSize.y,
winRect.GetHeight())
winRect.SetY(screenSize.y -
winRect.GetHeight())
print "set Y = %s" %
winRect.GetY()
if winRect.GetRight() <= pos.x:
print "right = %s, pos.x = %s,
width = %s" % (winRect.GetRight(), pos.x, winRect.GetWidth())
winRect.SetX(pos.x -
winRect.GetWidth() + 10)
print "set X = %s" %
winRect.GetX()
if winRect.GetRight() > screenSize.x:
print "right = %s, screenSize.x
= %s, width = %s" % (winRect.GetRight(), screenSize.x,
winRect.GetWidth())
winRect.SetX(screenSize.x -
winRect.GetWidth())
print "set X = %s" %
winRect.GetX()
if winRect.GetLeft() > pos.x:
print "left = %s, pos.x = %s" %
(winRect.GetLeft(), pos.x)
winRect.SetX(pos.x - 10)
print "set X = %s" %
winRect.GetX()
if winRect.GetTop() > pos.y:
print "top = %s, pos.y = %s" %
(winRect.GetTop(), pos.y)
winRect.SetY(pos.y -
winRect.GetHeight()+ 10)
print "set Y = %s" %
winRect.GetY()
self._SizeDocked['undocked'] =
(winRect.GetX(), winRect.GetY(), winRect.GetRight(),
winRect.GetBottom())
self.UnDock()
origin = self.GetPosition()
dx = pos.x - origin.x
dy = pos.y - origin.y
self.delta = wxPoint(dx, dy)
print "pos = %s, delta = %s, rect = %s,
rect pos = %s" % ((pos.x, pos.y), (self.delta.x, self.delta.y),
(winRect.GetX(), winRect.GetY(), winRect.GetRight(),
winRect.GetBottom()), str(winRect.GetPosition()))