def __init__(self, inspectorActionGroup, parent=None): super(InspectorSelectionPane, self).__init__(parent=parent) # self.setFrameShape(QtWidgets.QFrame.Box) self.menuButton = QtWidgets.QPushButton(NO_INSPECTOR_LABEL) self.menuButton.setMinimumWidth(10) inspectorMenu = QtWidgets.QMenu("Change Inspector", parent=self.menuButton) for action in inspectorActionGroup.actions(): inspectorMenu.addAction(action) self.menuButton.setMenu(inspectorMenu) self.messageLabel = QtWidgets.QLabel("") self.messageLabel.setObjectName("message_label") self.messageLabel.setFrameStyle(QtWidgets.QFrame.Panel) self.messageLabel.setFrameShadow(QtWidgets.QFrame.Sunken) self.messageLabel.setTextInteractionFlags(Qt.TextSelectableByMouse) self.mainLayout = QtWidgets.QHBoxLayout() self.mainLayout.setContentsMargins(DOCK_MARGIN, DOCK_MARGIN, DOCK_MARGIN, DOCK_MARGIN) self.setLayout(self.mainLayout) self.mainLayout.addWidget(self.menuButton, stretch=0) self.mainLayout.addWidget(self.messageLabel, stretch=1) setWidgetSizePolicy(self.menuButton, hor=QtWidgets.QSizePolicy.Minimum) setWidgetSizePolicy(self.messageLabel, hor=QtWidgets.QSizePolicy.Ignored) setWidgetSizePolicy(self, hor=QtWidgets.QSizePolicy.MinimumExpanding, ver=QtWidgets.QSizePolicy.Fixed)
def contextMenuEvent(self, event): """ Creates and executes the context menu for the tree view """ menu = QtWidgets.QMenu(self) for action in self.actions(): menu.addAction(action) openAsMenu = QtWidgets.QMenu(parent=menu) openAsMenu.setTitle("Open Item As") openAsMenu.aboutToShow.connect( lambda: self._populateOpenAsMenu(openAsMenu)) menu.insertMenu(self.closeItemAction, openAsMenu) # Insert before "Close Item" entry. menu.exec_(event.globalPos())
def showContextMenu(self, pos): """ Shows the context menu at position pos. """ contextMenu = QtWidgets.QMenu() addInspectorActionsToMenu(contextMenu, self.execInspectorDialogAction, self.inspectorActionGroup) contextMenu.exec_(self.mapToGlobal(pos))
def mouseClickEvent(self, mouseClickEvent): """ Handles (PyQtGraph) mouse click events. Overrides the middle mouse click to reset using the settings in the config tree. Opens the context menu if a right mouse button was clicked. (We can't simply use setContextMenuPolicy(Qt.ActionsContextMenu because the PlotItem class does not derive from QWidget). :param mouseClickEvent: pyqtgraph.GraphicsScene.mouseEvents.MouseClickEvent """ if mouseClickEvent.button() in self.resetRangeMouseButtons: self.emitResetColorScaleSignal() mouseClickEvent.accept() elif mouseClickEvent.button() == QtCore.Qt.RightButton: contextMenu = QtWidgets.QMenu() for action in self.actions(): contextMenu.addAction(action) screenPos = mouseClickEvent.screenPos( ) # Screenpos is a QPointF, convert to QPoint. screenX = round(screenPos.x()) screenY = round(screenPos.y()) contextMenu.exec_(QtCore.QPoint(screenX, screenY)) else: super(ArgosColorLegendItem, self).mouseClickEvent(mouseClickEvent)
def contextMenuEvent(self, event): """ Creates and executes the context menu for the tree view """ menu = QtWidgets.QMenu(self) for action in self.actions(): menu.addAction(action) openAsMenu = self.createOpenAsMenu(parent=menu) menu.insertMenu(self.closeItemAction, openAsMenu) menu.exec_(event.globalPos())
def mouseClickEvent(self, mouseClickEvent): """ Handles (PyQtGraph) mouse click events. Opens the context menu if a right mouse button was clicked. (We can't simply use setContextMenuPolicy(Qt.ActionsContextMenu because the PlotItem class does not derive from QWidget). :param mouseClickEvent: pyqtgraph.GraphicsScene.mouseEvents.MouseClickEvent """ if mouseClickEvent.button() == QtCore.Qt.RightButton: contextMenu = QtWidgets.QMenu() for action in self.actions(): contextMenu.addAction(action) screenPos = mouseClickEvent.screenPos() # Screenpos is a QPointF, convert to QPoint. screenX = round(screenPos.x()) screenY = round(screenPos.y()) contextMenu.exec_(QtCore.QPoint(screenX, screenY))
def __init__(self, execInspectorDialogAction, inspectorActionGroup, parent=None): super(InspectorSelectionPane, self).__init__(parent=parent) #self.setFrameShape(QtWidgets.QFrame.Box) self.layout = QtWidgets.QHBoxLayout() self.setLayout(self.layout) # self.label = QtWidgets.QLabel("Current inspector") # self.layout.addWidget(self.label) self.menuButton = QtWidgets.QPushButton("No inspector") self.layout.addWidget(self.menuButton) inspectorMenu = QtWidgets.QMenu("Change Inspector", parent=self.menuButton) addInspectorActionsToMenu(inspectorMenu, execInspectorDialogAction, inspectorActionGroup) self.menuButton.setMenu(inspectorMenu) sizePolicy = self.sizePolicy() sizePolicy.setVerticalPolicy(QtWidgets.QSizePolicy.Fixed) self.setSizePolicy(sizePolicy)
def createOpenAsMenu(self, parent=None): """ Creates the submenu for the Open As choice """ openAsMenu = QtWidgets.QMenu(parent=parent) openAsMenu.setTitle("Open Item As") registry = globalRtiRegistry() for rtiRegItem in registry.items: #rtiRegItem.tryImportClass() def createTrigger(): """Function to create a closure with the regItem""" _rtiRegItem = rtiRegItem # keep reference in closure return lambda: self.reloadFileOfCurrentItem(_rtiRegItem) action = QtWidgets.QAction( "{}".format(rtiRegItem.name), self, enabled=bool(rtiRegItem.successfullyImported is not False), triggered=createTrigger()) openAsMenu.addAction(action) return openAsMenu
def __init__(self, configTreeModel, parent=None): """ Constructor. :param parent: """ super(ConfigWidget, self).__init__(parent=parent) # Actions that change the reset mode of the reset button self.modeActionGroup = QtWidgets.QActionGroup(self) self.modeActionGroup.setExclusive(True) self.modeAllAction = QtWidgets.QAction("Reset All", self.modeActionGroup) self.modeAllAction.setToolTip( "Changes button reset mode to reset all settings") self.modeAllAction.setCheckable(True) self.modeAllAction.triggered.connect( lambda: self.setResetMode(ResetMode.All)) self.modeRangeAction = QtWidgets.QAction("Reset Ranges", self.modeActionGroup) self.modeRangeAction.setToolTip( "Changes button reset mode to reset axes") self.modeRangeAction.setCheckable(True) self.modeRangeAction.triggered.connect( lambda: self.setResetMode(ResetMode.Ranges)) # Sanity check that actions have been added to action group assert self.modeActionGroup.actions( ), "Sanity check. resetActionGroup is empty" # Actions that actually reset the settings self.resetAllAction = QtWidgets.QAction("Reset All", self) self.resetAllAction.setToolTip("Resets all settings.") self.resetAllAction.setIcon( QtGui.QIcon(os.path.join(icons_directory(), 'reset-l.svg'))) self.resetAllAction.setShortcut("Ctrl+=") self.resetRangesAction = QtWidgets.QAction("Reset Ranges", self) self.resetRangesAction.setToolTip( "Resets range of all plots, color scales, table column/row sizes etc." ) self.resetRangesAction.setIcon( QtGui.QIcon(os.path.join(icons_directory(), 'reset-l.svg'))) self.resetRangesAction.setShortcut("Ctrl+0") self.resetButtonMenu = QtWidgets.QMenu() self.resetButtonMenu.addAction(self.resetAllAction) self.resetButtonMenu.addAction(self.resetRangesAction) self.resetButtonMenu.addSection("Default") self.resetButtonMenu.addAction(self.modeAllAction) self.resetButtonMenu.addAction(self.modeRangeAction) # Widgets self.mainLayout = QtWidgets.QVBoxLayout(self) self.mainLayout.setSpacing(5) self.mainLayout.setContentsMargins(DOCK_MARGIN, DOCK_MARGIN, DOCK_MARGIN, DOCK_MARGIN) self.configTreeView = ConfigTreeView(configTreeModel, parent=self) self.mainLayout.addWidget(self.configTreeView) self.buttonLayout = QtWidgets.QHBoxLayout() self.mainLayout.addLayout(self.buttonLayout) self.autoCheckBox = QtWidgets.QCheckBox("Auto") self.autoCheckBox.setToolTip( "Auto reset when a new item or axis is selected.") self.autoCheckBox.setChecked(True) self.resetButton = QtWidgets.QToolButton() self.resetButton.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) self.resetButton.setDefaultAction(self.resetButtonMenu.defaultAction()) self.resetButton.setPopupMode(QtWidgets.QToolButton.MenuButtonPopup) self.resetButton.setMenu(self.resetButtonMenu) # Set font size to the same as used for push buttons dummyButton = QtWidgets.QPushButton("dummy") fontSize = dummyButton.font().pointSize() del dummyButton logger.debug( "Setting QToolButtons font size to: {} point".format(fontSize)) font = self.resetButton.font() font.setPointSizeF(fontSize) self.resetButton.setFont(font) self.buttonLayout.addStretch() self.buttonLayout.addWidget(self.autoCheckBox) self.buttonLayout.addWidget(self.resetButton) self.buttonLayout.addStretch() self.autoCheckBox.stateChanged.connect(self.setAutoReset) self.resetRangesAction.triggered.connect( self.configTreeView.resetAllRanges) self.resetAllAction.triggered.connect( self.configTreeView.resetAllSettings) self.setResetMode(self.configTreeView.resetMode)