【问题标题】:How to clear wxpython frame content when dragging a panel?拖动面板时如何清除wxpython框架内容?
【发布时间】: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


【解决方案1】:

要在 self 的每次重新定位时刷新父级,您可以添加

self.parent.Refresh()

在您在 def onMouseMove 方法中对 self.SetPosition 的现有调用之后。现在您仅在def onDraggingDown 方法中刷新框架,即第一次单击并按住鼠标左键,而不是每次在按住所述按钮时移动鼠标(即“拖动" 动作本身)。

我无法下载您的代码进行测试,因为您选择将其上传到相当“垃圾邮件”的网站——该网站一直在用广告轰炸我,我没有明确的方法来进行下载,偶尔抱怨它不支持我的机器(我使用 Mac 和谷歌 Chrome,某些地方的网站坚持使用 IE 或 Firefox 的 Windows ......)等等。我相信你可以找到其他网站,更多比那个更有用,对于那些试图帮助你的人!-)

【讨论】:

  • 在我提出这个问题之前,我已经测试了 self.parent.Refresh() :(
猜你喜欢
  • 2011-01-04
  • 1970-01-01
  • 2014-11-03
  • 2014-08-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-01
相关资源
最近更新 更多