Returns the anchor point that best fits within the given widget from
        the inputed global position.
        
        :param      widget      | <QWidget>
                    point       | <QPoint>
        
        :return     <XPopupWidget.Anchor>

def mapAnchorFrom(self, widget, point):
        """
        Returns the anchor point that best fits within the given widget from
        the inputed global position.
        
        :param      widget      | <QWidget>
                    point       | <QPoint>
        
        :return     <XPopupWidget.Anchor>
        """
        screen_geom = QtGui.QDesktopWidget(self).screenGeometry()

        # calculate the end rect for each position
        Anchor = self.Anchor
        w = self.width()
        h = self.height()

        possible_rects = {
            # top anchors
            Anchor.TopLeft: QtCore.QRect(point.x(), point.y(), w, h),
            Anchor.TopCenter: QtCore.QRect(point.x() - w / 2, point.y(), w, h),
            Anchor.TopRight: QtCore.QRect(point.x() - w, point.y(), w, h),

            # left anchors
            Anchor.LeftTop: QtCore.QRect(point.x(), point.y(), w, h),
            Anchor.LeftCenter: QtCore.QRect(point.x(), point.y() - h / 2, w, h),
            Anchor.LeftBottom: QtCore.QRect(point.x(), point.y() - h, w, h),

            # bottom anchors
            Anchor.BottomLeft: QtCore.QRect(point.x(), point.y() - h, w, h),
            Anchor.BottomCenter: QtCore.QRect(point.x() - w / 2, point.y() - h, w, h),
            Anchor.BottomRight: QtCore.QRect(point.x() - w, point.y() - h, w, h),

            # right anchors
            Anchor.RightTop: QtCore.QRect(point.x() - self.width(), point.y(), w, h),
            Anchor.RightCenter: QtCore.QRect(point.x() - self.width(), point.y() - h / 2, w, h),
            Anchor.RightBottom: QtCore.QRect(point.x() - self.width(), point.y() - h, w ,h)
        }

        for anchor in (Anchor.TopCenter,
                       Anchor.BottomCenter,
                       Anchor.LeftCenter,
                       Anchor.RightCenter,
                       Anchor.TopLeft,
                       Anchor.LeftTop,
                       Anchor.BottomLeft,
                       Anchor.LeftBottom,
                       Anchor.TopRight,
                       Anchor.RightTop,
                       Anchor.BottomRight,
                       Anchor.RightBottom):

            if not self.isPossibleAnchor(anchor):
                continue

            rect = possible_rects[anchor]
            if screen_geom.contains(rect):
                return anchor

        return self.anchor()