wx超级提示工具在设置消息时更改位置

2024-10-03 19:24:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我在创造一个wx.agw.SuperToolTip. 我每隔几秒钟更新一次提示中的消息,如果消息更新时提示显示,则提示将在不同的位置重新绘制。你知道吗

新位置似乎是相对于原始位置与屏幕左上角的关系,但这可能只是巧合。你知道吗

另外,如果我通过注释掉对self.CalculateBestSize()的调用来修改wx.lib.agw.supertooltip.ToolTipWindowBase.Invalidate(),问题就会消失。当然窗口不会调整大小,所以这不是解决方案。你知道吗

我正在使用wxpython2.8.12.1。你知道吗

下面是一个演示问题的应用程序:

class MyFrame(wx.Frame):

    def __init__(self, parent, title):
        wx.Frame.__init__(self, parent, -1, title,
                          pos=(150, 150), size=(350, 225))

        panel = wx.Panel(self)

        btn = wx.Button(panel, -1, "Hover over this")

        self._superTip = SuperToolTip("")
        self._superTip.SetHeader("Heyo!")
        self._superTip.SetTarget(btn)
        self._superTip.EnableTip(True)
        self._superTip.SetDrawHeaderLine(True)
        self._superTip.SetDrawFooterLine(True)
        self._superTip.SetStartDelay(1)
        self._superTip.SetEndDelay(60)
        currentFooterFont = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
        currentFooterFont.SetPointSize(6)
        currentFooterFont.SetWeight(wx.NORMAL)
        self._superTip.SetFooterFont(currentFooterFont)
        self._superTip.SetFooter('(Click to close)')
        self._superTip.ApplyStyle("Blue Glass")
        self._superTip.SetDropShadow(True)

        self.ttTimer = wx.Timer(self)

        self.ttText = 'What the?'

        self.Bind(wx.EVT_TIMER, self.onTimer, self.ttTimer)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(btn, 0, wx.ALL, 10)
        panel.SetSizer(sizer)

        self.ttTimer.Start(2000)

        panel.Layout()



    def onTimer(self, evt):
        self._superTip.SetMessage(self.ttText)
        self.ttText += '?'

class MyApp(wx.App):
    def OnInit(self):
        frame = MyFrame(None, "STT error demo")
        self.SetTopWindow(frame)

        frame.Show(True)
        return True

app = MyApp(redirect=True)
app.MainLoop()

关于如何在不改变位置的情况下更新可见的工具提示,有什么想法吗?你知道吗

非常感谢。你知道吗


Tags: selftrue消息defframewxpanelbtn