def _setupHelpActions(self): actionsgroup = QtWidgets.QActionGroup(self) # About icon = qtsupport.geticon('about.svg', __name__) QtWidgets.QAction( icon, self.tr('&About'), actionsgroup, objectName='aboutAction', toolTip=self.tr('Show program information'), statusTip=self.tr('Show program information'), triggered=lambda: self.aboutdialog.exec_()) # AboutQt icon = QtGui.QIcon(':/qt-project.org/qmessagebox/images/qtlogo-64.png') # @COMPATIBILITY: Qt4 --> Qt5 if not icon.availableSizes(): icon = QtGui.QIcon(':/trolltech/qmessagebox/images/qtlogo-64.png') if not icon.availableSizes(): icon = QtGui.QIcon.fromTheme('qtlogo-64') QtWidgets.QAction( icon, self.tr('About &Qt'), actionsgroup, objectName='aboutQtAction', toolTip=self.tr('Show information about Qt'), statusTip=self.tr('Show information about Qt'), triggered=lambda: QtWidgets.QMessageBox.aboutQt(self)) return actionsgroup
def _setupViewActions(self): style = self.style() actions = QtWidgets.QActionGroup(self) icon = style.standardIcon(QtWidgets.QStyle.SP_DialogResetButton) QtWidgets.QAction(icon, self.tr('Reset'), actions, objectName='resetAction', statusTip=self.tr('Reset'), triggered=self.onReset) QtWidgets.QAction(actions).setSeparator(True) icon = QtGui.QIcon( ':/trolltech/dialogs/qprintpreviewdialog/images/zoom-in-32.png') QtWidgets.QAction(icon, self.tr('Zoom In'), actions, objectName='zoomInAction', statusTip=self.tr('Zoom In'), shortcut=self.tr('Ctrl++'), triggered=lambda: self.graphicsview.scale(1.2, 1.2)) icon = QtGui.QIcon( ':/trolltech/dialogs/qprintpreviewdialog/images/zoom-out-32.png') QtWidgets.QAction( icon, self.tr('Zoom Out'), actions, objectName='zoomOutAction', statusTip=self.tr('Zoom Out'), shortcut=self.tr('Ctrl+-'), triggered=lambda: self.graphicsview.scale(1 / 1.2, 1 / 1.2)) icon = QtGui.QIcon( ':/trolltech/dialogs/qprintpreviewdialog/images/page-setup-24.png') QtWidgets.QAction(icon, self.tr('Zoom 1:1'), actions, objectName='zoomResetAction', statusTip=self.tr('Zoom 1:1'), triggered=lambda: self.graphicsview.setTransform( QtGui.QTransform(1, 0, 0, -1, 0, 0))) icon = QtGui.QIcon( ':/trolltech/dialogs/qprintpreviewdialog/images/fit-page-32.png') QtWidgets.QAction( icon, self.tr('Zoom Fit'), actions, objectName='zoomFitAction', statusTip=self.tr('Zoom Fit'), #checkable=True, triggered=lambda: self.graphicsview.fitInView( self.graphicsview.sceneRect(), QtCore.Qt.KeepAspectRatio)) return actions
def _setupHelpActions(self): actions = QtWidgets.QActionGroup(self) icon = QtGui.QIcon( ':/trolltech/styles/commonstyle/images/fileinfo-32.png') QtWidgets.QAction(icon, 'About', actions, triggered=self.about) icon = QtGui.QIcon(':/trolltech/qmessagebox/images/qtlogo-64.png') QtWidgets.QAction(icon, 'About Qt', actions, triggered=QtWidgets.QApplication.aboutQt) return actions
def _setupActions(self): actions = super(LayerManager, self)._setupActions() icon = QtGui.QIcon( ':/trolltech/styles/commonstyle/images/viewdetailed-128.png') QtWidgets.QAction(icon, self.tr('Select all'), actions, objectName='selectAllAction', statusTip=self.tr('Select all'), shortcut=self.tr('Ctrl-A'), triggered=self.view.selectAll) # connect actions action = actions.findChild(QtWidgets.QAction, 'moveToTopAction') action.triggered.connect(self.moveSelectionToTop) action = actions.findChild(QtWidgets.QAction, 'moveUpAction') action.triggered.connect(self.moveSelectionUp) action = actions.findChild(QtWidgets.QAction, 'moveDownAction') action.triggered.connect(self.moveSelectionDown) action = actions.findChild(QtWidgets.QAction, 'moveToBottomAction') action.triggered.connect(self.moveSelectionToBottom) action = actions.findChild(QtWidgets.QAction, 'removeLayerAction') action.triggered.connect(self.removeSelectedLayers) action = actions.findChild(QtWidgets.QAction, 'showLayerAction') action.triggered.connect(self.checkSelectedItems) action = actions.findChild(QtWidgets.QAction, 'hideLayerAction') action.triggered.connect(self.uncheckSelectedItems) return actions
def setViewContextActions(widget): assert (widget.contextMenuPolicy() == QtCore.Qt.ActionsContextMenu), \ 'menu policy is not "QtCore.Qt.ActionsContextMenu"' #if widget.contextMenuPolicy() != QtCore.Qt.ActionsContextMenu: # widget.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu) icon = geticon('copy.svg', __name__) action = QtWidgets.QAction( icon, widget.tr('&Copy'), widget, objectName='copyAction', shortcut=widget.tr('Ctrl+C'), toolTip=widget.tr('Copy selected items'), triggered=lambda: copySelectedItems(widget)) widget.addAction(action) #':/trolltech/dialogs/qprintpreviewdialog/images/view-page-multi-32.png' icon = QtGui.QIcon( ':/trolltech/styles/commonstyle/images/viewlist-128.png') action = QtWidgets.QAction( icon, widget.tr('Select &All'), widget, objectName='selectAllAction', #shortcut=widget.tr('Ctrl+A'), toolTip=widget.tr('Select all items'), triggered=lambda: selectAllItems(widget)) widget.addAction(action) icon = widget.style().standardIcon(QtWidgets.QStyle.SP_DialogSaveButton) action = QtWidgets.QAction( icon, widget.tr('&Save As'), widget, objectName='saveAsAction', shortcut=widget.tr('Ctrl+S'), statusTip=widget.tr('Save as'), triggered=lambda: exportTable(widget.model())) widget.addAction(action) icon = QtGui.QIcon( ':/trolltech/dialogs/qprintpreviewdialog/images/print-32.png') action = QtWidgets.QAction( icon, widget.tr('&Print'), widget, objectName='printAction', shortcut=widget.tr('Ctrl+P'), statusTip=widget.tr('Print'), triggered=lambda: printObject(widget)) widget.addAction(action)
def geticon(name, package=None): '''Build and return requested icon. It is assumed that icon files are located in the "images" subfolder of the package. .. seealso:: :func:`gsdview.utils.getresource` ''' iconfile = utils.getresource(os.path.join('images', name), package) return QtGui.QIcon(iconfile)
def _newModeAction(self, mode, parent): if isinstance(mode.icon, string_types): icon = QtGui.QIcon(mode.icon) elif isinstance(mode.icon, QtWidgets.QStyle.StandardPixmap): style = QtWidgets.QApplication.style() icon = style.standardIcon(mode.icon) else: icon = mode.icon action = QtWidgets.QAction( icon, self.tr(mode.label), parent, statusTip=self.tr(mode.label), checkable=True) action.triggered.connect(lambda: self.modeChanged.emit(self.mode)) return action
def _setupFileActions(self): style = self.style() actions = QtWidgets.QActionGroup(self) icon = style.standardIcon(QtWidgets.QStyle.SP_DialogOpenButton) QtWidgets.QAction(icon, self.tr('&Open'), actions, objectName='openAction', shortcut=self.tr('Ctrl+O'), statusTip=self.tr('Open'), triggered=self.onOpen) icon = style.standardIcon(QtWidgets.QStyle.SP_DialogSaveButton) QtWidgets.QAction(icon, self.tr('&Save As'), actions, objectName='saveAsAction', shortcut=self.tr('Ctrl+S'), statusTip=self.tr('Save as'), triggered=self.onSave) icon = QtGui.QIcon( ':/trolltech/dialogs/qprintpreviewdialog/images/print-32.png') QtWidgets.QAction(icon, self.tr('&Print'), actions, objectName='printAction', shortcut=self.tr('Ctrl+P'), statusTip=self.tr('Print'), triggered=self.onPrint) QtWidgets.QAction(actions).setSeparator(True) icon = style.standardIcon(QtWidgets.QStyle.SP_DialogCancelButton) QtWidgets.QAction(icon, self.tr('&Quit'), actions, objectName='exitAction', shortcut=self.tr('Ctrl+Q'), statusTip=self.tr('Quit'), triggered=self.close) return actions
def _setupActions(self): qstype = QtWidgets.QApplication.style() # Setup actions self.actions = QtWidgets.QActionGroup(self) # Save As icon = qstype.standardIcon(QtWidgets.QStyle.SP_DialogSaveButton) self.actionSaveAs = QtWidgets.QAction( icon, self.tr('&Save As'), self, shortcut=self.tr('Ctrl+S'), statusTip=self.tr('Save text to file'), triggered=self.save) self.actions.addAction(self.actionSaveAs) # Clear icon = QtGui.QIcon(':/trolltech/styles/commonstyle/images/' 'standardbutton-clear-32.png') self.actionClear = QtWidgets.QAction( icon, self.tr('&Clear'), self, shortcut=self.tr('Shift+F5'), statusTip=self.tr('Clear the text'), triggered=self.clear) self.actions.addAction(self.actionClear) # Close icon = qstype.standardIcon(QtWidgets.QStyle.SP_DialogCloseButton) self.actionHide = QtWidgets.QAction( icon, self.tr('&Hide'), self, shortcut=self.tr('Ctrl+W'), statusTip=self.tr('Hide the text pane'), triggered=self.paneHideRequest) self.actions.addAction(self.actionHide)
class MouseMode(QtCore.QObject): '''Base class for mouse mode desctiptors. Qt Graphics Framework mouse mode descriptors define some basic property for mouse related matters: - cursor - dragmode - eventFilter - name - label - icon The first three properties (not to be intender as python progremming language property) are strongly characterizing of the way the mouse works. In particular the eventFilter method is used to filter all events coming from graphics scenes an graphics views. .. note:: in order to work properly the eventFilter should be installed on both graphics scene and view and also on the scrollbars of the graphics view. So please always use the register method of MouseManager for a proper installaton of al event filters. ''' dragmode = QtWidgets.QGraphicsView.NoDrag cursor = None icon = QtGui.QIcon() label = '' name = '' def eventFilter(self, obj, event): '''Basic implementation of the eventFilter method. The dafault implementation makes some basic operation such setting the mouse cursor anc dispatch the event to specific methods: - sceneEventFilter - viewEventFilter - scrollbarEventFilter In most of the cases derived classes only need to specialize one or more of this specific methods. ''' if isinstance(obj, QtWidgets.QGraphicsScene): return self.sceneEventFilter(obj, event) elif isinstance(obj, QtWidgets.QGraphicsView): if event.type() == QtCore.QEvent.Enter: obj.setDragMode(self.dragmode) if self.cursor: obj.setCursor(self.cursor) else: obj.unsetCursor() return self.viewEventFilter(obj, event) elif isinstance(obj, QtWidgets.QScrollBar): return self.scrollbarEventFilter(obj, event) else: return False def sceneEventFilter(self, obj, event): return False def viewEventFilter(self, obj, event): return False def scrollbarEventFilter(self, obj, event): return False
def __init__(self, parent, **kwargs): '''Constructs a QtWindowListMenu object. The *parent* parameter is passed to the QMenu constructor. Although this parameter has the conventional default of 0, you will normally want to explicitly provide a parent object, since the later adding of this menu object to an action container (e.g. QMenuBar) does not cause a reparenting. The container is normally the natural choice for *parent*. ''' super(QtWindowListMenu, self).__init__(parent, **kwargs) self.mdi = None self.setTitle(self.tr('&Windows')) self.aboutToShow.connect(self.syncWithMdiArea) self._stdGroup = QtWidgets.QActionGroup(self, exclusive=False) self._winGroup = QtWidgets.QActionGroup(self, exclusive=True) #, triggered=self.activateWindow) # @COMPATIBILITY: pyside 1.2.2 self._winGroup.triggered.connect(self.activateWindow) # Create the standard menu items. # @Note: Creation order must match the StandardAction enum values ;-) QtWidgets.QAction(self.tr('Cl&ose'), self._stdGroup, shortcut=self.tr('Ctrl+F4'), statusTip=self.tr('Close the active window')) QtWidgets.QAction(self.tr('Close &All'), self._stdGroup, statusTip=self.tr('Close all the windows')) act = self._stdGroup.addAction('') act.setSeparator(True) QtWidgets.QAction(self.tr('&Tile'), self._stdGroup, statusTip=self.tr('Tile the windows')) QtWidgets.QAction(self.tr('&Cascade'), self._stdGroup, statusTip=self.tr('Cascade the windows')) act = self._stdGroup.addAction('') act.setSeparator(True) QtWidgets.QAction( self.tr('Ne&xt'), self._stdGroup, statusTip=self.tr('Move the focus to the next window')) QtWidgets.QAction( self.tr('Pre&vious'), self._stdGroup, statusTip=self.tr('Move the focus to the previous window')) act = self._stdGroup.addAction('') act.setSeparator(True) self.addActions(self._stdGroup.actions()) self._winMap = {} # QMap<QAction *, QMdiSubWindow *> self._iconMap = {} # QMap<const QMdiSubWindow *, QIcon> self._defIcon = QtGui.QIcon()
def _setupActions(self): style = QtWidgets.QApplication.style() actions = QtWidgets.QActionGroup(self) icon = QtGui.QIcon(':/trolltech/styles/commonstyle/images/up-128.png') QtWidgets.QAction(icon, self.tr('Move to top'), actions, objectName='moveToTopAction', statusTip=self.tr('Move to top'), shortcut=self.tr('Ctrl+PgUp')) icon = style.standardIcon(QtWidgets.QStyle.SP_ArrowUp) QtWidgets.QAction(icon, self.tr('Move up'), actions, objectName='moveUpAction', statusTip=self.tr('Move up'), shortcut=self.tr('Ctrl+Up')) icon = style.standardIcon(QtWidgets.QStyle.SP_ArrowDown) QtWidgets.QAction(icon, self.tr('Move down'), actions, objectName='moveDownAction', statusTip=self.tr('Move down'), shortcut=self.tr('Ctrl+Down')) icon = QtGui.QIcon( ':/trolltech/styles/commonstyle/images/down-128.png') QtWidgets.QAction(icon, self.tr('Move to bottom'), actions, objectName='moveToBottomAction', statusTip=self.tr('Move to bottom'), shortcut=self.tr('Ctrl+PgDown')) #~ #'standardbutton-closetab-16.png' icon = QtGui.QIcon(':/trolltech/styles/commonstyle/images/' 'standardbutton-cancel-128.png') QtWidgets.QAction(icon, self.tr('Remove'), actions, objectName='removeLayerAction', statusTip=self.tr('Remove'), shortcut=self.tr('Del')) icon = QtGui.QIcon( ':/trolltech/styles/commonstyle/images/standardbutton-yes-128.png') QtWidgets.QAction(icon, self.tr('Show'), actions, objectName='showLayerAction', statusTip=self.tr('Show the layer')) icon = QtGui.QIcon( ':/trolltech/styles/commonstyle/images/standardbutton-no-128.png') QtWidgets.QAction(icon, self.tr('Hide'), actions, objectName='hideLayerAction', statusTip=self.tr('Hide the layer')) return actions