0

我正在尝试制作一个简单的停靠框架,它将停靠到父窗口并跟随它。到目前为止,我有以下内容:

class DockingFrame(wx.Frame):
    def __init__(self, parent):
        wx.Frame.__init__(self, parent, style=wx.CAPTION)

        parent.Bind(wx.EVT_MOVE, self.OnParentMove)
        parent.Bind(wx.EVT_ACTIVATE, self.OnParentActivate)
        parent.Bind(wx.EVT_SHOW, self.OnParentShow)

    def OnParentMove(self, moveEvent):
        print "Docked frame parent moved"
        pr = positioning.position(
            self.Rect,
            my='right_top', at='left_top', of=self.Parent.Rect)
        self.Move(pr.top_left)
        moveEvent.Skip()

    def OnParentActivate(self, event):
        print "Docked frame parent activated"
        self.Raise()
        event.Skip()

    def OnParentShow(self, event):
        print "Docked frame parent showed"
        self.Show(event.GetShow())
        event.Skip()

class MainFrame(wx.Frame):
    def __init__(self, title):
        wx.Frame.__init__(self, None, title=title)

        self.info_frame = DockingFrame(self)

        self.Show(True)

这是因为如果我移动父窗口,停靠的窗口会随之移动,如果我单击父窗口,停靠的窗口会自行升起。但是,它严重干扰了父窗口的功能。我无法再关闭或重新调整父窗口的大小,并且每当我单击父窗口时,都会收到大量“已激活停靠框架父窗口”的消息。看来我不明白一些基本的 wxPython 概念,here。发生了什么事,我该如何解决?

我已经看到它aui似乎支持对接,但文档很少,所以我没有尝试过。如果有人可以提供一个最小的工作代码示例来说明Frame如何Frame使用aui.

请注意,我也在这个应用程序中使用pygameand twisted,它可能会或可能不会干扰这里......

4

2 回答 2

2

而且,当然,简单的方法是简单地使用wx.FRAME_FLOAT_ON_PARENT样式......

class DockingFrame(wx.Frame):
    def __init__(self, parent):
        wx.Frame.__init__(self, parent, title="Last Hand",
                          style=wx.CAPTION  | wx.FRAME_FLOAT_ON_PARENT)

        parent.Bind(wx.EVT_MOVE, self.OnParentMove)
        parent.Bind(wx.EVT_SHOW, self.OnParentShow)

    def SnapToParent(self):
        print "*Snapping to parent"
        pr = positioning.position(
            self.Rect,
            my='right_top', at='left_top', of=self.Parent.Rect)
        self.Move(pr.top_left)

    def OnParentMove(self, moveEvent):
        moveEvent.Skip()
        self.SnapToParent()

    def OnParentShow(self, event):
        event.Skip()
        print "Parent %s" % ("Hide", "Show")[event.GetShow()]
        self.Show(event.GetShow())
于 2013-03-18T23:15:22.380 回答
0

诀窍是EVT_ACTIVATE激活和取消激活都会触发。以下代码有效。如果父级被激活,则扩展坞会自行升起并在之后立即升起父级。

class DockingFrame(wx.Frame):
    def __init__(self, parent):
        self.handleParentActiveState = 'noTriggers'

        wx.Frame.__init__(self, parent, title="Last Hand", style=wx.CAPTION)

        parent.Bind(wx.EVT_MOVE, self.OnParentMove)
        parent.Bind(wx.EVT_ACTIVATE, self.OnParentActivate)
        self.Bind(wx.EVT_ACTIVATE, self.OnActivate)
        parent.Bind(wx.EVT_SHOW, self.OnParentShow)        

    def OnActivate(self, event):
        event.Skip()
        if not event.GetActive():
            return

        if self.handleParentActiveState == 'activateParentNext':
            self.handleParentActiveState = 'resetTriggers'
            self.Parent.Raise()

    def OnParentActivate(self, event):
        event.Skip()
        if not event.GetActive():
            return

        if self.handleParentActiveState == 'noTriggers':
            self.handleParentActiveState = 'activateParentNext'
            self.Raise()
        elif self.handleParentActiveState == 'resetTriggers':
            self.handleParentActiveState = 'noTriggers'

    def OnParentMove(self, moveEvent):
        pr = positioning.position(
            self.Rect,
            my='right_top', at='left_top', of=self.Parent.Rect)
        self.Move(pr.top_left)
        moveEvent.Skip()

    def OnParentShow(self, event):
        event.Skip()
        self.Show(event.GetShow())
于 2013-03-18T22:57:08.520 回答