Exemple #1
0
def kaction(name, actionCollection=None, callable=None):
    # Create the toolbar action and insert it into the toolbar_actions dict
    global parent
    global action_definitions
    global action_groups

    config = action_definitions.get(name, None)

    if config is None:
        print "ERR: No config for action:", name
        return None #Without the config no action can be created

    action = KAction(parent)

    if "group" in config:
        group_name = config["group"]
        if group_name in action_groups:
            group = action_groups[group_name]
        else:
            group = QtGui.QActionGroup(parent)
            action_groups[group_name] = group

        action.setActionGroup(group)

    if "icon" in config:
        action.setIcon(KIcon(config["icon"]))

    if "checkable" in config:
        action.setCheckable(True)

    # Same exception is wanted here. As an alternative one can specify a callable as a parameter.
    if callable is not None:
        action.triggered.connect(callable)
    else:
        action.triggered.connect(config["action"])

    if "text" in config:
        action.setText(config["text"])

    if "tooltip" in config:
        action.setToolTip(config["tooltip"])

    if "whatsthis" in config:
        action.setWhatsThis(config["whatsthis"])

    if actionCollection is not None:
        actionCollection.addAction(name, action)

    return action