You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
933 B
29 lines
933 B
3 years ago
|
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()
|