def toolbar(name, group=None, callable=None): """ Returns the action with the given name for toolbar use. Toolbar use means that there is an icon without text. Needed configuration keys: icon, action Ignored keys: text Parameters: name -- The name of the action. group -- The QActionGroup to add this action to. callable -- The callable to call when the action is triggered. Can be used to override the action in the definition or provide one. """ global toolbar_actions action = toolbar_actions.get(name, None) if action is None: # Create the toolbar action and insert it into the toolbar_actions dict global parent global action_definitions config = action_definitions.get(name, None) if config is None: return None #Without the config no action can be created if group is None: action = KAction(parent) else: action = KAction(group) # Will result in a KeyError when the icon is not set in the config. # This is slightly wanted behaviour, as the icon is needed for a # toolbar action. 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"]) toolbar_actions["name"] = action return action
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
def menu(name): """ Returns the action with the given name for menu use. Menu use that the action has a text and might have an icon. Needed configuration keys: text, action Optional keys: icon Parameters: name -- The name of the action, """ global menu_actions action = menu_actions.get(name, None) if action is None: # Create the toolbar action and insert it into the toolbar_actions dict global parent global action_definitions config = action_definitions.get(name, None) if config is None: return None #Without the config no action can be created action = KAction(parent) if "icon" in config: action.setIcon(KIcon(config["icon"])) if "checkable" in config: action.setCheckable(True) # Will result in a KeyError when the text is not set in the config. # This is slightly wanted behaviour, as the text is needed for a # menu action. action.setText(config["text"]) # Same exception is wanted here. action.triggered.connect(config["action"]) menu_actions["name"] = action return action