diff --git a/python/GafferUI/PopupWindow.py b/python/GafferUI/PopupWindow.py index 73009eb77f..c849a34f8a 100644 --- a/python/GafferUI/PopupWindow.py +++ b/python/GafferUI/PopupWindow.py @@ -72,7 +72,9 @@ def popup( self, center = None, parent = None ) : self.setVisible( True ) size = self._qtWidget().sizeHint() + print( "PopupWindow.popup : Attempting to move popup to {}".format( center - imath.V2i( size.width() / 2, size.height() / 2 ) ) ) self.setPosition( center - imath.V2i( size.width() / 2, size.height() / 2 ) ) + print( "PopupWindow.popup : Popup moved to {}".format( self.getPosition() ) ) ## Reimplemented from Widget to report the parent passed to `popup()`. def parent( self ) : diff --git a/python/GafferUI/Window.py b/python/GafferUI/Window.py index 385388e2a2..ec857ef7f0 100644 --- a/python/GafferUI/Window.py +++ b/python/GafferUI/Window.py @@ -40,6 +40,8 @@ import warnings import imath +import IECore + import GafferUI import Gaffer @@ -299,22 +301,29 @@ def __constrainToScreen( self, position ) : windowRect = self._qtWidget().frameGeometry() windowRect.moveTo( position ) - # Determine the offset and which direction to move to stay on screen, - # based on this size difference and which co-ordinate changed in the - # intersected frame + if windowRect.intersects( screenRect ) : - intersection = windowRect.intersected( screenRect ) - difference = windowRect.size() - intersection.size() + # Determine the offset and which direction to move to stay on screen, + # based on this size difference and which co-ordinate changed in the + # intersected frame - signX = -1 if intersection.left() == windowRect.left() else 1 - signY = -1 if intersection.top() == windowRect.top() else 1 + intersection = windowRect.intersected( screenRect ) + difference = windowRect.size() - intersection.size() - offset = QtCore.QPoint( - signX * difference.width(), - signY * difference.height() - ) + signX = -1 if intersection.left() == windowRect.left() else 1 + signY = -1 if intersection.top() == windowRect.top() else 1 + + offset = QtCore.QPoint( + signX * difference.width(), + signY * difference.height() + ) + + newPosition = position + offset + + else : - newPosition = position + offset + IECore.msg( IECore.Msg.Level.Warning, "Window.__constrainToScreen", "Window is outside screen's available geometry. screen: {} screenRect: {} windowRect: {}".format( screen.name(), screenRect, windowRect ) ) + newPosition = position # Bottom-right corrections may have moved us off to the top-left, # constrain to the screen origin.