如何在拖动面板时清除wxpython框架内容?

发布于 2024-08-25 17:30:12 字数 1885 浏览 7 评论 0原文

我有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

人生戏 2024-09-01 17:30:12

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

self.parent.Refresh()

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

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

To refresh the parent on every repositioning of self, you could add

self.parent.Refresh()

right after your existing call to self.SetPosition in your def onMouseMove method. Right now you're refreshing the frame only in the def 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!-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文