File: multi_target.py

package info (click to toggle)
orange3 3.40.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 15,908 kB
  • sloc: python: 162,745; ansic: 622; makefile: 322; sh: 93; cpp: 77
file content (28 lines) | stat: -rw-r--r-- 930 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from functools import wraps

from Orange.widgets.utils.messages import UnboundMsg

multiple_targets_msg = "Multiple targets are not supported."
_multiple_targets_data = UnboundMsg(multiple_targets_msg)


def check_multiple_targets_input(f):
    """
    Wrapper for widget's set_data method that checks if the input
    has multiple targets and shows an error if it does.

    :param f: widget's `set_data` method to wrap
    :return: wrapped method that handles multiple targets data inputs
    """

    @wraps(f)
    def new_f(widget, data, *args, **kwargs):
        widget.Error.add_message("multiple_targets_data",
                                 _multiple_targets_data)
        widget.Error.multiple_targets_data.clear()
        if data is not None and len(data.domain.class_vars) > 1:
            widget.Error.multiple_targets_data()
            data = None
        return f(widget, data, *args, **kwargs)

    return new_f