def show_context_menu(self, widget, pos, pause=0): QTest.mouseMove(widget, pos) yield pause QTest.mouseClick(widget, Qt.RightButton, Qt.NoModifier, pos) yield pause ev = QMouseEvent(QEvent.ContextMenu, pos, Qt.RightButton, Qt.NoButton, Qt.NoModifier) QApplication.postEvent(widget, ev) yield self.wait_for_popup()
def layoutScale(self, update_geometry=True): """ Recalculate the scale's geometry and layout based on the current geometry and fonts. :param bool update_geometry: Notify the layout system and call update to redraw the scale """ bd0, bd1 = self.getBorderDistHint() if self.__data.borderDist[0] > bd0: bd0 = self.__data.borderDist[0] if self.__data.borderDist[1] > bd1: bd1 = self.__data.borderDist[1] colorBarWidth = 0 if self.__data.colorBar.isEnabled and self.__data.colorBar.interval.isValid(): colorBarWidth = self.__data.colorBar.width + self.__data.spacing r = self.contentsRect() if self.__data.scaleDraw.orientation() == Qt.Vertical: y = r.top() + bd0 length = r.height() - (bd0 + bd1) if self.__data.scaleDraw.alignment() == QwtScaleDraw.LeftScale: x = r.right() - 1.0 - self.__data.margin - colorBarWidth else: x = r.left() + self.__data.margin + colorBarWidth else: x = r.left() + bd0 length = r.width() - (bd0 + bd1) if self.__data.scaleDraw.alignment() == QwtScaleDraw.BottomScale: y = r.top() + self.__data.margin + colorBarWidth else: y = r.bottom() - 1.0 - self.__data.margin - colorBarWidth self.__data.scaleDraw.move(x, y) self.__data.scaleDraw.setLength(length) extent = np.ceil(self.__data.scaleDraw.extent(self.font())) self.__data.titleOffset = ( self.__data.margin + self.__data.spacing + colorBarWidth + extent ) if update_geometry: self.updateGeometry() # for some reason updateGeometry does not send a LayoutRequest # event when the parent is not visible and has no layout widget = self.parentWidget() if widget and not widget.isVisible() and widget.layout() is None: if widget.testAttribute(Qt.WA_WState_Polished): QApplication.postEvent( self.parentWidget(), QEvent(QEvent.LayoutRequest) ) self.update()
def eventFilter(self, object, event): if event.type() == QEvent.FocusIn: self.__showCursor(True) if event.type() == QEvent.FocusOut: self.__showCursor(False) if event.type() == QEvent.Paint: QApplication.postEvent(self, QEvent(QEvent.User)) elif event.type() == QEvent.MouseButtonPress: self.__select(event.pos()) return True elif event.type() == QEvent.MouseMove: self.__move(event.pos()) return True if event.type() == QEvent.KeyPress: delta = 5 key = event.key() if key == Qt.Key_Up: self.__shiftCurveCursor(True) return True elif key == Qt.Key_Down: self.__shiftCurveCursor(False) return True elif key == Qt.Key_Right or key == Qt.Key_Plus: if self.__selectedCurve: self.__shiftPointCursor(True) else: self.__shiftCurveCursor(True) return True elif key == Qt.Key_Left or key == Qt.Key_Minus: if self.__selectedCurve: self.__shiftPointCursor(False) else: self.__shiftCurveCursor(True) return True if key == Qt.Key_1: self.__moveBy(-delta, delta) elif key == Qt.Key_2: self.__moveBy(0, delta) elif key == Qt.Key_3: self.__moveBy(delta, delta) elif key == Qt.Key_4: self.__moveBy(-delta, 0) elif key == Qt.Key_6: self.__moveBy(delta, 0) elif key == Qt.Key_7: self.__moveBy(-delta, -delta) elif key == Qt.Key_8: self.__moveBy(0, -delta) elif key == Qt.Key_9: self.__moveBy(delta, -delta) return False
def eventFilter(self, object_, event): """ Handle QEvent.ChildRemoved andQEvent.LayoutRequest events for the contentsWidget(). :param QObject object: Object to be filtered :param QEvent event: Event :return: Forwarded to QwtAbstractLegend.eventFilter() """ if object_ is self.__data.view.contentsWidget: if event.type() == QEvent.ChildRemoved: ce = event # TODO: cast to QChildEvent if ce.child().isWidgetType(): w = ce.child() # TODO: cast to QWidget self.__data.itemMap.removeWidget(w) elif event.type() == QEvent.LayoutRequest: self.__data.view.layoutContents() if self.parentWidget( ) and self.parentWidget().layout() is None: QApplication.postEvent(self.parentWidget(), QEvent(QEvent.LayoutRequest)) return QwtAbstractLegend.eventFilter(self, object_, event)