Example #1
0
def createAction(parentWidget,
                 text=None,
                 slot=None,
                 shortcut=None,
                 shortcutContext=QtCore.Qt.WidgetShortcut,
                 icon=None,
                 menu=None,
                 tip=None,
                 checkable=False,
                 signal="triggered()"):
    action = QtGui.QAction(parentWidget)
    if text is not None:
        action.setText(text)
    if icon is not None:
        action.setIcon(icon)
    if menu is not None:
        action.setMenu(menu)
    if shortcut:
        if isinstance(shortcut, list):
            action.setShortcuts(shortcut)
        else:
            action.setShortcut(shortcut)
        action.setShortcutContext(shortcutContext)
    if tip is not None:
        action.setToolTip(tip)
        action.setStatusTip(tip)
    if slot is not None:
        QtCore.QObject.connect(action, QtCore.SIGNAL(signal), slot)
    action.setCheckable(checkable)
    return action
Example #2
0
    def __init__(self,
                 text=None,
                 icon=None,
                 tip=None,
                 shortcut=None,
                 shortcutContext=QtCore.Qt.WidgetShortcut,
                 menu=None,
                 checkable=False,
                 separator=False,
                 selectionBased=False,
                 signal="triggered()",
                 enabled=True,
                 isValidFn=None,
                 runFn=None,
                 parent=None):

        super(Action, self).__init__(parent)

        if text:
            self.setText(text)

        if icon:
            self.setIcon(icon)

        if tip:
            self.setToolTip(tip)
            self.setStatusTip(tip)

        if shortcut:
            if isinstance(shortcut, list):
                shortcuts = [QtGui.QKeySequence(key) for key in shortcut]
                self.setShortcuts(shortcuts)
            else:
                self.setShortcut(QtGui.QKeySequence(shortcut))
            self.setShortcutContext(shortcutContext)

        if menu:
            self.setMenu(menu)

        self.setCheckable(checkable)
        self.setEnabled(enabled)
        self.setSeparator(separator)

        self.__selectionBased = selectionBased
        self.__isValidFn = isValidFn
        self.__runFn = runFn

        self.connect(self, QtCore.SIGNAL(signal), self.run)

        self.__subActions = []