From 8788a613580d0d73d37912430108cba0dbcaa1a5 Mon Sep 17 00:00:00 2001 From: Noah Rahm Date: Fri, 25 Jun 2021 11:19:42 -0500 Subject: [PATCH] Fix position calculations to keep tooltip onscreen --- wx/lib/agw/supertooltip.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/wx/lib/agw/supertooltip.py b/wx/lib/agw/supertooltip.py index a92ce10d12..3fa3fb0552 100644 --- a/wx/lib/agw/supertooltip.py +++ b/wx/lib/agw/supertooltip.py @@ -682,18 +682,22 @@ def CalculateBestSize(self): def CalculateBestPosition(self,widget): + x, y = wx.GetMousePosition() screen = wx.ClientDisplayRect()[2:] - left,top = widget.ClientToScreen((0, 0)) - right,bottom = widget.ClientToScreen(widget.GetClientRect()[2:]) + left, top = widget.ClientToScreen((0, 0)) + right, bottom = widget.ClientToScreen(widget.GetClientRect()[2:]) size = self.GetSize() - if right+size[0]>screen[0]: - xpos = left-size[0] + + if x+size[0]>screen[0]: + xpos = x-size[0] else: - xpos = right + xpos = x + if bottom+size[1]>screen[1]: - ypos = top-size[1] + ypos = top-size[1] + 6 else: - ypos = bottom + ypos = bottom + 6 + self.SetPosition((xpos,ypos))