param icon indicating copy to clipboard operation
param copied to clipboard

Add some pattern to allow preprocessing parameter value on change

Open philippjfr opened this issue 6 years ago • 2 comments

In some cases you want to be able to define a @param.depends decorator which watches a parameter and then modifies it. This currently leads to recursion, it may therefore be nice if we had a recursion flag, e.g. to allow doing things like:

@param.depends('polys', watch=True, recursion=False)
def _init_polys(self):
    self.polys = self.polys.options(color='red')

Alternative suggestions to achieve the same thing would be welcome.

philippjfr avatar May 02 '19 10:05 philippjfr

Actually this proposal is probably not sufficient for my purpose, what I really would need is a preempt keyword which basically says "execute me, cancel any existing events and process new events triggered by me but don't call me a second time". Fairly complex and maybe better expressed as a parameter preprocessor, something like:

@param.preprocess('polys')
def _preprocess_polys(self, polys):
    return self.polys.options(color='red')

philippjfr avatar May 02 '19 10:05 philippjfr

How about a context manager?

@param.depends('polys', watch=True)
def _init_polys(self):
    with param.watching_disabled():
        self.polys = self.polys.options(color='red')

jbednar avatar May 02 '19 13:05 jbednar