如何在拖动面板时清除wxpython框架内容?
我有 3 个面板,我想对它们进行拖动。 问题是,当我拖动一个时,会发生这种情况: http://img41.yfrog.com/img41/9043/soundlog.png http://img41.yfrog.com/img41/9043/soundlog.png http:/ /img41.yfrog.com/img41/9043/soundlog.png
当面板不再存在时,如何刷新框架以显示其颜色?
这是我必须进行拖动的代码:
def onMouseMove(self, event):
(self.pointWidth, self.pointHeight) = event.GetPosition()
(self.width, self.height) = self.GetSizeTuple()
if (self.pointWidth>100 and self.pointWidth<(self.width-100) and self.pointHeight < 15) or self.parent.dragging:
self.SetCursor(wx.StockCursor(wx.CURSOR_SIZING))
"""implement dragging"""
if not event.Dragging():
self.w = 0
self.h = 0
return
self.CaptureMouse()
if self.w == 0 and self.h == 0:
(self.w, self.h) = event.GetPosition()
else:
(posw, posh) = event.GetPosition()
displacement = self.h - posh
self.SetPosition( self.GetPosition() - (0, displacement))
else:
self.SetCursor(wx.StockCursor(wx.CURSOR_ARROW))
def onDraggingDown(self, event):
if self.pointWidth>100 and self.pointWidth<(self.width-100) and self.pointHeight < 15:
self.parent.dragging = 1
self.SetCursor(wx.StockCursor(wx.CURSOR_ARROW))
self.SetBackgroundColour('BLUE')
self.parent.SetTransparent(220)
self.Refresh()
def onDraggingUp(self, event):
self.parent.dragging = 0
self.parent.SetTransparent(255)
self.SetCursor(wx.StockCursor(wx.CURSOR_ARROW))
这是此事件的绑定:
self.Bind(wx.EVT_MOTION, self.onMouseMove)
self.Bind(wx.EVT_LEFT_DOWN, self.onDraggingDown)
self.Bind(wx.EVT_LEFT_UP, self.onDraggingUp)
有了这个,如果我单击面板顶部,然后向下或向上移动,面板位置会发生变化(我拖动面板)到鼠标的位置。
I have 3 panels and I want to make drags on them.
The problem is that when I do a drag on one this happens:
http://img41.yfrog.com/img41/9043/soundlog.png http://img41.yfrog.com/img41/9043/soundlog.png
How can I refresh the frame to happear its color when the panel is no longer there?
This is the code that I have to make the drag:
def onMouseMove(self, event):
(self.pointWidth, self.pointHeight) = event.GetPosition()
(self.width, self.height) = self.GetSizeTuple()
if (self.pointWidth>100 and self.pointWidth<(self.width-100) and self.pointHeight < 15) or self.parent.dragging:
self.SetCursor(wx.StockCursor(wx.CURSOR_SIZING))
"""implement dragging"""
if not event.Dragging():
self.w = 0
self.h = 0
return
self.CaptureMouse()
if self.w == 0 and self.h == 0:
(self.w, self.h) = event.GetPosition()
else:
(posw, posh) = event.GetPosition()
displacement = self.h - posh
self.SetPosition( self.GetPosition() - (0, displacement))
else:
self.SetCursor(wx.StockCursor(wx.CURSOR_ARROW))
def onDraggingDown(self, event):
if self.pointWidth>100 and self.pointWidth<(self.width-100) and self.pointHeight < 15:
self.parent.dragging = 1
self.SetCursor(wx.StockCursor(wx.CURSOR_ARROW))
self.SetBackgroundColour('BLUE')
self.parent.SetTransparent(220)
self.Refresh()
def onDraggingUp(self, event):
self.parent.dragging = 0
self.parent.SetTransparent(255)
self.SetCursor(wx.StockCursor(wx.CURSOR_ARROW))
and this are the binds for this events:
self.Bind(wx.EVT_MOTION, self.onMouseMove)
self.Bind(wx.EVT_LEFT_DOWN, self.onDraggingDown)
self.Bind(wx.EVT_LEFT_UP, self.onDraggingUp)
With this, if I click on the top of the panel, and move down or up, the panel position changes (I drag the panel) to the position of the mouse.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要在每次重新定位
self
时刷新父级,您可以在
def onMouseMove
方法中对self.SetPosition
的现有调用之后添加。现在,您仅在def onDraggingDown
方法中刷新框架,即第一次单击并按住鼠标左键时,而不是每次按住该按钮时移动鼠标(即“拖动”动作本身)。我无法下载您的代码用于测试目的,因为您选择将其上传到相当“垃圾邮件奇特”的网站 - 该网站不断用广告轰炸我,我没有明确的方法来下载,偶尔会抱怨它不支持我的机器(我使用 Mac 和 Google Chrome,该网站在某些地方坚持使用带有 IE 或 Firefox 的 Windows...)等等。我相信您可以找到其他网站,比这更有用一,对于那些试图帮助你的人!-)
To refresh the parent on every repositioning of
self
, you could addright after your existing call to
self.SetPosition
in yourdef onMouseMove
method. Right now you're refreshing the frame only in thedef onDraggingDown
method, i.e., the first time the mouse left button is clicked and held down, not every time the mouse is moved while said button is held down (i.e., the "dragging" action itself).I was unable to download your code for testing purposes, due to the rather "spammy peculiar" site you chose to upload it to -- the site keeps bombarding me with ads, no clear way for me to just do the download, occasionally complaining that it doesn't support my machine (I use a Mac and Google Chrome, the site at some spots insists on Windows with IE or Firefox...), etc etc. I'm sure you can find other sites, more usable than that one, for people who are trying to help you out!-)