-
Notifications
You must be signed in to change notification settings - Fork 7
Fix param.Action (#9). #32
Changes from all commits
43cca53
90738f2
a068347
17762af
bdb94a0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -174,6 +174,9 @@ def __call__(self, parameterized, doc=None, plots=[], **params): | |
def on_msg(self, msg): | ||
p_name = msg['p_name'] | ||
p_obj = self.parameterized.params(p_name) | ||
if isinstance(p_obj, param.Action): | ||
getattr(self.parameterized, p_name)(self.parameterized) | ||
return | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Other widgets won't be refreshed - is that a problem? What if the callback alters another parameter value? (I decided not to get into this now, deferring it to 'dependencies between parameters and code'...) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
+1 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds fine. |
||
w = self._widgets[p_name] | ||
self._queue.append((w, p_obj, p_name, None, None, msg['value'])) | ||
self.change_event() | ||
|
@@ -258,10 +261,6 @@ def _make_widget(self, p_name): | |
value = getattr(self.parameterized, p_name) | ||
|
||
kw = dict(value=value) | ||
if isinstance(p_obj, param.Action): | ||
def action_cb(button): | ||
getattr(self.parameterized, p_name)(self.parameterized) | ||
kw['value'] = action_cb | ||
|
||
kw['title'] = p_name | ||
|
||
|
@@ -289,12 +288,17 @@ def action_cb(button): | |
|
||
if hasattr(p_obj, 'callbacks'): | ||
p_obj.callbacks[id(self.parameterized)] = functools.partial(self._update_trait, p_name) | ||
elif isinstance(w, (Button, Toggle)): | ||
elif isinstance(w, Toggle): | ||
if self.p.mode in ['server', 'raw']: | ||
w.on_change('active', functools.partial(self.on_change, w, p_obj, p_name)) | ||
else: | ||
js_callback = self._get_customjs('active', p_name) | ||
w.js_on_change('active', js_callback) | ||
elif isinstance(w, Button): | ||
if self.p.mode in ['server', 'raw']: | ||
w.on_click(functools.partial(value,self.parameterized)) | ||
else: | ||
w.js_on_click(self._get_customjs('active', p_name)) | ||
elif not p_obj.constant: | ||
if self.p.mode in ['server', 'raw']: | ||
cb = functools.partial(self.on_change, w, p_obj, p_name) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -225,6 +225,10 @@ def _handle_msg(self, msg): | |
with StandardOutput() as stdout: | ||
self._on_msg(msg) | ||
except Exception as e: | ||
# TODO: isn't this cutting out info needed to understand what's gone wrong? | ||
# Since it's only going to the js console, maybe we could just show everything | ||
# (error = traceback.format_exc() or something like that)? Separately we do need a mechanism | ||
# to report reasonable messages to users, though. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All true, if we can find a way to make tracebacks readable on the JS console I'd be very happy to change this (and port the change back to holoviews). |
||
frame =traceback.extract_tb(sys.exc_info()[2])[-2] | ||
fname,lineno,fn,text = frame | ||
error_kwargs = dict(type=type(e).__name__, fn=fn, fname=fname, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good example, thanks.