--- a/src/eric7/EricWidgets/EricPassivePopup.py Wed Jul 13 11:16:20 2022 +0200 +++ b/src/eric7/EricWidgets/EricPassivePopup.py Wed Jul 13 14:55:47 2022 +0200 @@ -18,45 +18,47 @@ """ Class defining the popup styles. """ - BOXED = 0 # box with no shadow - STYLED = 1 # styled panel with no shadow - CUSTOM = 128 # reserved for extensions + + BOXED = 0 # box with no shadow + STYLED = 1 # styled panel with no shadow + CUSTOM = 128 # reserved for extensions class EricPassivePopup(QFrame): """ Class implementing dialog-like popup that displays messages without interrupting the user. - + @signal clicked emitted to indicate a mouse button click """ - DefaultPopupTime = 6 * 1000 # time im milliseconds - - clicked = pyqtSignal((), (QPoint, )) - + + DefaultPopupTime = 6 * 1000 # time im milliseconds + + clicked = pyqtSignal((), (QPoint,)) + def __init__(self, style=EricPassivePopupStyle.BOXED, parent=None): """ Constructor - + @param style style of the popup @type EricPassivePopupStyle @param parent reference to the parent widget @type QWidget """ super().__init__(None) - + self.__msgView = None self.__topLayout = None self.__hideDelay = EricPassivePopup.DefaultPopupTime self.__hideTimer = QTimer(self) self.__autoDelete = False self.__fixedPosition = QPoint() - + self.setWindowFlags( - Qt.WindowType.Tool | - Qt.WindowType.X11BypassWindowManagerHint | - Qt.WindowType.WindowStaysOnTopHint | - Qt.WindowType.FramelessWindowHint + Qt.WindowType.Tool + | Qt.WindowType.X11BypassWindowManagerHint + | Qt.WindowType.WindowStaysOnTopHint + | Qt.WindowType.FramelessWindowHint ) if style == EricPassivePopupStyle.STYLED: self.setFrameStyle(QFrame.Shape.StyledPanel | QFrame.Shadow.Plain) @@ -66,13 +68,13 @@ self.setLineWidth(2) self.__hideTimer.timeout.connect(self.hide) self.clicked.connect(self.hide) - + self.__customData = {} # dictionary to store some custom data - + def setView(self, child): """ Public method to set the message view. - + @param child reference to the widget to set as the message view (QWidget) """ @@ -80,58 +82,58 @@ self.__topLayout = QVBoxLayout(self) self.__topLayout.addWidget(self.__msgView) self.__topLayout.activate() - + def view(self): """ Public method to get a reference to the message view. - + @return reference to the message view (QWidget) """ return self.__msgView - + def setVisible(self, visible): """ Public method to show or hide the popup. - + @param visible flag indicating the visibility status (boolean) """ if not visible: super().setVisible(visible) return - + if self.size() != self.sizeHint(): self.resize(self.sizeHint()) - + if self.__fixedPosition.isNull(): self.__positionSelf() else: self.move(self.__fixedPosition) super().setVisible(True) - + delay = self.__hideDelay if delay < 0: delay = EricPassivePopup.DefaultPopupTime if delay > 0: self.__hideTimer.start(delay) - + def show(self, p=None): """ Public slot to show the popup. - + @param p position for the popup (QPoint) """ if p is not None: self.__fixedPosition = p super().show() - + def setTimeout(self, delay): """ Public method to set the delay for the popup is removed automatically. - + Setting the delay to 0 disables the timeout. If you're doing this, you may want to connect the clicked() signal to the hide() slot. Setting the delay to -1 makes it use the default value. - + @param delay value for the delay in milliseconds (integer) """ self.__hideDelay = delay @@ -142,63 +144,63 @@ self.__hideTimer.start(delay) else: self.__hideTimer.stop() - + def timeout(self): """ Public method to get the delay before the popup is removed automatically. - + @return the delay before the popup is removed automatically (integer) """ return self.__hideDelay - + def mouseReleaseEvent(self, evt): """ Protected method to handle a mouse release event. - + @param evt reference to the mouse event (QMouseEvent) """ self.clicked.emit() self.clicked.emit(evt.position().toPoint()) - + def hideEvent(self, evt): """ Protected method to handle the hide event. - + @param evt reference to the hide event (QHideEvent) """ self.__hideTimer.stop() - + def __defaultArea(self): """ Private method to determine the default rectangle to be passed to moveNear(). - + @return default rectangle (QRect) """ return QRect(100, 100, 200, 200) - + def __positionSelf(self): """ Private method to position the popup. """ self.__moveNear(self.__defaultArea()) - + def __moveNear(self, target): """ Private method to move the popup to be adjacent to the specified rectangle. - + @param target rectangle to be placed at (QRect) """ pos = self.__calculateNearbyPoint(target) self.move(pos.x(), pos.y()) - + def __calculateNearbyPoint(self, target): """ Private method to calculate the position to place the popup near the specified rectangle. - + @param target rectangle to be placed at (QRect) @return position to place the popup (QPoint) """ @@ -207,45 +209,45 @@ y = pos.y() w = self.minimumSizeHint().width() h = self.minimumSizeHint().height() - + r = QApplication.screenAt(QPoint(x + w // 2, y + h // 2)).geometry() - + if x < r.center().x(): x += target.width() else: x -= w - + # It's apparently trying to go off screen, so display it ALL at the # bottom. if (y + h) > r.bottom(): y = r.bottom() - h - + if (x + w) > r.right(): x = r.right() - w - + if y < r.top(): y = r.top() - + if x < r.left(): x = r.left() - + return QPoint(x, y) - + def setCustomData(self, key, data): """ Public method to set some custom data. - + @param key key for the custom data @type str @param data data to be stored @type any """ self.__customData[key] = data - + def getCustomData(self, key): """ Public method to get some custom data. - + @param key key for the custom data @type str @return stored data