Skip to content

Commit

Permalink
Add automated input summaries
Browse files Browse the repository at this point in the history
  • Loading branch information
janezd committed Mar 4, 2021
1 parent b9bf557 commit 7f78f23
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions orangewidget/utils/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,34 @@ def set_train_data(self, data):
explicitly connected in the dialog (default: `False`)
"""
def __init__(self, name, type, id=None, doc=None, replaces=None, *,
multiple=False, default=False, explicit=False):
multiple=False, default=False, explicit=False,
auto_summary=None):
flags = self.get_flags(multiple, default, explicit, False)
super().__init__(name, type, "", flags, id, doc, replaces or [])
self.auto_summary = auto_summary
self._seq_id = next(_counter)

def __call__(self, method):
"""
Decorator that stores decorated method's name in the signal's
`handler` attribute. The method is returned unchanged.
"""
def set_summary(widget, value, *args, **kwargs):
if self.auto_summary:
info = widget.info
if value is None:
info.set_input_summary(info.NoInput)
else:
summary, details = summarize(value)
if summary is not None:
info.set_input_summary(summary, details)
return method(widget, value, *args, **kwargs)

if self.handler:
raise ValueError("Input {} is already bound to method {}".
format(self.name, self.handler))
self.handler = method.__name__
return method
return set_summary


class Output(OutputSignal, _Signal):
Expand Down Expand Up @@ -285,13 +298,15 @@ def set_default_auto_summary(cls):
set that signal's auto_summary to True, so that it's value will be
shown in the status.
"""
outputs = getmembers(cls.Outputs, Output)
if any(output.auto_summary for _, output in outputs):
return
for _, output in outputs:
if output.auto_summary is None:
output.auto_summary = \
bool(output.flags & Default) or len(outputs) == 1
for signal_cls, signal_type in ((cls.Inputs, Input),
(cls.Outputs, Output)):
signals = getmembers(signal_cls, signal_type)
if any(signal.auto_summary for _, signal in signals):
continue
for _, signal in signals:
if signal.auto_summary is None:
signal.auto_summary = \
bool(signal.flags & Default) or len(signals) == 1


class AttributeList(list):
Expand Down

0 comments on commit 7f78f23

Please sign in to comment.