【发布时间】:2011-01-27 03:01:20
【问题描述】:
我有 3 个面板,我想对它们进行拖拽。 问题是,当我拖拽一个时,会发生这种情况: 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)
这样,如果我点击面板的顶部,然后向下或向上移动,面板位置就会改变(我拖动面板)到鼠标的位置。
【问题讨论】:
-
“拖累他们”是什么意思?你能放一些自包含的示例代码来演示这个问题吗?
-
我放了代码,你现在明白了吗?
-
你能不能放一些我不用复制粘贴就可以运行的代码,这样我就可以直接看到问题并解决它。
-
你可以在这里下载它(等待等待):2shared.com/file/12230037/b5ee8e79/SoundLog.html Execute SoundLog :) 并尝试一下。现在,你能回答我吗? :)
标签: python wxpython refresh panel