import FreeCADGui as Gui global ahb_commands ahb_commands = {} class AHB_CommandWrapper: def __init__(self, command_name): self.command_name = command_name def __getattr__(self, attrName): instance = ahb_commands[self.command_name] result = getattr(instance, attrName) if callable(result): # replace self def f(*args, **kwargs): return result.__func__(instance, *args, **kwargs) return f else: return result @staticmethod def addGuiCommand(command_name, command_instance): #print(("adding" if not command_name in ahb_commands else "updating") + " command " + command_name) ahb_commands.update({ command_name: command_instance }) Gui.addCommand(command_name, AHB_CommandWrapper(command_name)) @staticmethod def listGuiCommands(): return ahb_commands.keys()