Python decorators are fun to use, but I appear to have hit a wall due to the way arguments are passed to decorators. Here I have a decorator defined as part of a base class
It might be easier to just pull the decorator out of the SubSytem
class:
(Note that I'm assuming that the self
that calls setport
is the same self
that you wish to use to call updateGUIField
.)
def UpdateGUI(fun): #function decorator
def wrapper(self,*args):
self.updateGUIField(*args)
return fun(self,*args)
return wrapper
class SubSystem(object):
def updateGUIField(self, name, value):
# if name in self.gui:
# if type(self.gui[name]) == System.Windows.Controls.CheckBox:
# self.gui[name].IsChecked = value #update checkbox on ui
# elif type(self.gui[name]) == System.Windows.Controls.Slider:
# self.gui[name].Value = value # update slider on ui
print(name,value)
class DO(SubSystem):
@UpdateGUI
def setport(self, port, value):
"""Sets the value of Digital Output port "port"."""
pass
do=DO()
do.setport('p','v')
# ('p', 'v')