Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 import rospy
00019 
00020 from python_qt_binding import QtGui
00021 from python_qt_binding import QtCore
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 class QAgiPopup(QtGui.QWidget):
00031 
00032     TopLeft     = 1
00033     BottomRight = 2
00034     TopRight    = 3
00035     BottomLeft  = 4
00036     Center      = 5
00037     
00038     def __init__(self, parent = None):
00039         """! The constructor.
00040         @param parent: object parent.
00041         @type parent: QObject.
00042         """
00043         
00044         QtGui.QWidget.__init__(self, parent)
00045         self.setWindowFlags(QtCore.Qt.Popup | QtCore.Qt.FramelessWindowHint)
00046         self.setStyleSheet("QWidget{background-color: #d9d9d9;}")
00047         self._parent = parent
00048         self._popup_link  = self.TopRight
00049         self._parent_link = self.BottomRight
00050     
00051     @staticmethod
00052     def getObjectPosition(obj, corner):
00053         """! Get glabal corner position.
00054         @param obj: object.
00055         @type obj: QObject.
00056         
00057         @param corner: corner type.
00058         @type corner: int.
00059         """
00060         if corner == QAgiPopup.TopLeft:
00061             return obj.mapToGlobal(obj.rect().topLeft())
00062         elif corner == QAgiPopup.BottomRight:
00063             return obj.mapToGlobal(obj.rect().bottomRight())
00064         elif corner == QAgiPopup.TopRight:
00065             return obj.mapToGlobal(obj.rect().topRight())
00066         elif corner == QAgiPopup.BottomLeft:
00067             return obj.mapToGlobal(obj.rect().bottomLeft())
00068         else :
00069             return obj.mapToGlobal(obj.rect().center())
00070         
00071     def setRelativePosition(self, popup, widget):
00072         self._popup_link  = popup
00073         self._parent_link = widget
00074         
00075     def show_(self):
00076         
00077         """! Show popup."""
00078         parent_pos = QAgiPopup.getObjectPosition(self._parent, self._parent_link)
00079         popup_pos = QAgiPopup.getObjectPosition(self, self._popup_link)
00080         
00081         self.move(parent_pos - popup_pos)
00082         self.show()
00083         
00084