def popup(self, pos=None): """ Pops up this widget at the inputed position. The inputed point should \ be in global space. :param pos | <QPoint> :return <bool> success """ if self._first and self.centralWidget() is not None: self.adjustSize() self._first = False if not self.signalsBlocked(): self.aboutToShow.emit() if not pos: pos = QCursor.pos() if self.currentMode() == XPopupWidget.Mode.Dialog and \ self.isVisible(): return False elif self.currentMode() == XPopupWidget.Mode.Dialog: self.setPopupMode() # auto-calculate the point if self.autoCalculateAnchor(): self.setAnchor(self.mapAnchorFrom(self.parent(), pos)) pad = self.popupPadding() # determine where to move based on the anchor anchor = self.anchor() # MODIFY X POSITION # align x-left if (anchor & (XPopupWidget.Anchor.TopLeft | XPopupWidget.Anchor.BottomLeft)): pos.setX(pos.x() - pad) # align x-center elif (anchor & (XPopupWidget.Anchor.TopCenter | XPopupWidget.Anchor.BottomCenter)): pos.setX(pos.x() - self.width() / 2) # align x-right elif ( anchor & (XPopupWidget.Anchor.TopRight | XPopupWidget.Anchor.BottomRight)): pos.setX(pos.x() - self.width() + pad) # align x-padded elif (anchor & (XPopupWidget.Anchor.RightTop | XPopupWidget.Anchor.RightCenter | XPopupWidget.Anchor.RightBottom)): pos.setX(pos.x() - self.width()) # MODIFY Y POSITION # align y-top if (anchor & (XPopupWidget.Anchor.LeftTop | XPopupWidget.Anchor.RightTop)): pos.setY(pos.y() - pad) # align y-center elif (anchor & (XPopupWidget.Anchor.LeftCenter | XPopupWidget.Anchor.RightCenter)): pos.setY(pos.y() - self.height() / 2) # align y-bottom elif (anchor & (XPopupWidget.Anchor.LeftBottom | XPopupWidget.Anchor.RightBottom)): pos.setY(pos.y() - self.height() + pad) # align y-padded elif ( anchor & (XPopupWidget.Anchor.BottomLeft | XPopupWidget.Anchor.BottomCenter | XPopupWidget.Anchor.BottomRight)): pos.setY(pos.y() - self.height()) self.adjustMask() self.move(pos) self.update() self.setUpdatesEnabled(True) if self.isAnimated(): anim = QPropertyAnimation(self, 'windowOpacity') anim.setParent(self) anim.setStartValue(0.0) anim.setEndValue(self.windowOpacity()) anim.setDuration(500) anim.finished.connect(anim.deleteLater) self.setWindowOpacity(0.0) else: anim = None self.show() if self.currentMode() != XPopupWidget.Mode.ToolTip: self.activateWindow() widget = self.centralWidget() if widget: self.centralWidget().setFocus() if anim: anim.start() if not self.signalsBlocked(): self.shown.emit() return True
def slideIn(self, index, direction=Direction.Automatic): """ Slides in the panel at the inputed index in the given direction for this widget. :param index | <int> direction | <XStackedWidget.Direction> :return <bool> | success """ # do not allow multiple slides while it is active if self._active: return False # determine the proper index to calculate invert = False if self.count() <= index: if not self.wrap(): return False index = self.count() % index invert = True elif index < 0: if not self.wrap(): return False index = self.count() + index invert = True # define the direction information if index == self.currentIndex(): return False elif self.currentIndex() < index: if direction == XStackedWidget.Direction.Automatic: if self.isVerticalMode(): direction = XStackedWidget.Direction.BottomToTop else: direction = XStackedWidget.Direction.RightToLeft else: if direction == XStackedWidget.Direction.Automatic: if self.isVerticalMode(): direction = XStackedWidget.Direction.TopToBottom else: direction = XStackedWidget.Direction.LeftToRight # invert the animation if we are wrapping if invert: if direction == XStackedWidget.Direction.BottomToTop: direction = XStackedWidget.Direction.TopToBottom elif direction == XStackedWidget.Direction.TopToBottom: direction = XStackedWidget.Direction.BottomToTop elif direction == XStackedWidget.Direction.LeftToRight: direction = XStackedWidget.Direction.RightToLeft else: direction = XStackedWidget.Direction.LeftToRight self._active = True offset_x = self.frameRect().width() offset_y = self.frameRect().height() next_widget = self.widget(index) curr_widget = self.widget(self.currentIndex()) next_widget.setGeometry(0, 0, offset_x, offset_y) if direction == XStackedWidget.Direction.BottomToTop: offset_x = 0 offset_y = -offset_y elif direction == XStackedWidget.Direction.TopToBottom: offset_x = 0 elif direction == XStackedWidget.Direction.RightToLeft: offset_x = -offset_x offset_y = 0 elif direction == XStackedWidget.Direction.LeftToRight: offset_y = 0 next_point = next_widget.pos() curr_point = curr_widget.pos() self._nextIndex = index self._lastIndex = self.currentIndex() self._lastPoint = QPoint(curr_point) next_widget.move(next_point.x()-offset_x, next_point.y()-offset_y) next_widget.raise_() next_widget.show() curr_anim = QPropertyAnimation(curr_widget, 'pos') curr_anim.setDuration(self.speed()) curr_anim.setEasingCurve(self.animationType()) curr_anim.setStartValue(curr_point) curr_anim.setEndValue(QPoint(curr_point.x()+offset_x, curr_point.y()+offset_y)) next_anim = QPropertyAnimation(next_widget, 'pos') next_anim.setDuration(self.speed()) next_anim.setEasingCurve(self.animationType()) next_anim.setStartValue(QPoint(next_point.x()-offset_x, next_point.y()-offset_y)) next_anim.setEndValue(next_point) anim_group = QParallelAnimationGroup(self) anim_group.addAnimation(curr_anim) anim_group.addAnimation(next_anim) anim_group.finished.connect(self._finishAnimation) anim_group.finished.connect(anim_group.deleteLater) anim_group.start() return True
def popup(self, pos=None): """ Pops up this widget at the inputed position. The inputed point should \ be in global space. :param pos | <QPoint> :return <bool> success """ if self._first and self.centralWidget() is not None: self.adjustSize() self._first = False if not self.signalsBlocked(): self.aboutToShow.emit() if not pos: pos = QCursor.pos() if self.currentMode() == XPopupWidget.Mode.Dialog and \ self.isVisible(): return False elif self.currentMode() == XPopupWidget.Mode.Dialog: self.setPopupMode() # auto-calculate the point if self.autoCalculateAnchor(): self.setAnchor(self.mapAnchorFrom(self.parent(), pos)) pad = self.popupPadding() # determine where to move based on the anchor anchor = self.anchor() # MODIFY X POSITION # align x-left if ( anchor & (XPopupWidget.Anchor.TopLeft | XPopupWidget.Anchor.BottomLeft) ): pos.setX(pos.x() - pad) # align x-center elif ( anchor & (XPopupWidget.Anchor.TopCenter | XPopupWidget.Anchor.BottomCenter) ): pos.setX(pos.x() - self.width() / 2) # align x-right elif ( anchor & (XPopupWidget.Anchor.TopRight | XPopupWidget.Anchor.BottomRight) ): pos.setX(pos.x() - self.width() + pad) # align x-padded elif ( anchor & (XPopupWidget.Anchor.RightTop | XPopupWidget.Anchor.RightCenter | XPopupWidget.Anchor.RightBottom) ): pos.setX(pos.x() - self.width()) # MODIFY Y POSITION # align y-top if ( anchor & (XPopupWidget.Anchor.LeftTop | XPopupWidget.Anchor.RightTop) ): pos.setY(pos.y() - pad) # align y-center elif ( anchor & (XPopupWidget.Anchor.LeftCenter | XPopupWidget.Anchor.RightCenter) ): pos.setY(pos.y() - self.height() / 2) # align y-bottom elif ( anchor & (XPopupWidget.Anchor.LeftBottom | XPopupWidget.Anchor.RightBottom) ): pos.setY(pos.y() - self.height() + pad) # align y-padded elif ( anchor & (XPopupWidget.Anchor.BottomLeft | XPopupWidget.Anchor.BottomCenter | XPopupWidget.Anchor.BottomRight) ): pos.setY(pos.y() - self.height()) self.adjustMask() self.move(pos) self.update() self.setUpdatesEnabled(True) if self.isAnimated(): anim = QPropertyAnimation(self, 'windowOpacity') anim.setParent(self) anim.setStartValue(0.0) anim.setEndValue(self.windowOpacity()) anim.setDuration(500) anim.finished.connect(anim.deleteLater) self.setWindowOpacity(0.0) else: anim = None self.show() if self.currentMode() != XPopupWidget.Mode.ToolTip: self.activateWindow() widget = self.centralWidget() if widget: self.centralWidget().setFocus() if anim: anim.start() if not self.signalsBlocked(): self.shown.emit() return True
def slideIn(self, index, direction=Direction.Automatic): """ Slides in the panel at the inputed index in the given direction for this widget. :param index | <int> direction | <XStackedWidget.Direction> :return <bool> | success """ # do not allow multiple slides while it is active if self._active: return False # determine the proper index to calculate invert = False if self.count() <= index: if not self.wrap(): return False index = self.count() % index invert = True elif index < 0: if not self.wrap(): return False index = self.count() + index invert = True # define the direction information if index == self.currentIndex(): return False elif self.currentIndex() < index: if direction == XStackedWidget.Direction.Automatic: if self.isVerticalMode(): direction = XStackedWidget.Direction.BottomToTop else: direction = XStackedWidget.Direction.RightToLeft else: if direction == XStackedWidget.Direction.Automatic: if self.isVerticalMode(): direction = XStackedWidget.Direction.TopToBottom else: direction = XStackedWidget.Direction.LeftToRight # invert the animation if we are wrapping if invert: if direction == XStackedWidget.Direction.BottomToTop: direction = XStackedWidget.Direction.TopToBottom elif direction == XStackedWidget.Direction.TopToBottom: direction = XStackedWidget.Direction.BottomToTop elif direction == XStackedWidget.Direction.LeftToRight: direction = XStackedWidget.Direction.RightToLeft else: direction = XStackedWidget.Direction.LeftToRight self._active = True offset_x = self.frameRect().width() offset_y = self.frameRect().height() next_widget = self.widget(index) curr_widget = self.widget(self.currentIndex()) next_widget.setGeometry(0, 0, offset_x, offset_y) if direction == XStackedWidget.Direction.BottomToTop: offset_x = 0 offset_y = -offset_y elif direction == XStackedWidget.Direction.TopToBottom: offset_x = 0 elif direction == XStackedWidget.Direction.RightToLeft: offset_x = -offset_x offset_y = 0 elif direction == XStackedWidget.Direction.LeftToRight: offset_y = 0 next_point = next_widget.pos() curr_point = curr_widget.pos() self._nextIndex = index self._lastIndex = self.currentIndex() self._lastPoint = QPoint(curr_point) next_widget.move(next_point.x() - offset_x, next_point.y() - offset_y) next_widget.raise_() next_widget.show() curr_anim = QPropertyAnimation(curr_widget, 'pos') curr_anim.setDuration(self.speed()) curr_anim.setEasingCurve(self.animationType()) curr_anim.setStartValue(curr_point) curr_anim.setEndValue( QPoint(curr_point.x() + offset_x, curr_point.y() + offset_y)) next_anim = QPropertyAnimation(next_widget, 'pos') next_anim.setDuration(self.speed()) next_anim.setEasingCurve(self.animationType()) next_anim.setStartValue( QPoint(next_point.x() - offset_x, next_point.y() - offset_y)) next_anim.setEndValue(next_point) anim_group = QParallelAnimationGroup(self) anim_group.addAnimation(curr_anim) anim_group.addAnimation(next_anim) anim_group.finished.connect(self._finishAnimation) anim_group.finished.connect(anim_group.deleteLater) anim_group.start() return True