# Path: pyDEA/core/utils/dea_utils.py
# def create_bounds(constraints, categories):
#     ''' Creates proper data structures after parsing all constraints.
# 
#         Args:
#             constraints (list of str): list of constraints to parse.
#             categories (set of str): set of current categories.
# 
#         Returns:
#             dict of str to tuple of double,
#                 double or dict of tuple of str,
#                 str to tuple of double, double:
#                 dictionary with parsed values of constraints.
# 
#         Raises:
#             ValueError: if some of the constraints cannot be parsed.
# 
#         Example:
#             >>> categories = set(['I1', 'I2', 'O1', 'O2'])
#             >>> constraints = ['I1 <= 10', 'I1 >= 2', 'O1 >= 3', 'O2 <= 7']
#             >>> create_bounds(constraints, categories)
#             >>> {'I1': (2, 10), 'O1': (3, None), 'O2': (None, 7)}
#             >>> ratio_bounds = ['I1/I2 <= 10', 'I1/I2 >= 1',
#                                 'O2/O1 >= 0.2', 'O1/O2 <= 0.5']
#             >>> create_bounds(ratio_bounds, categories)
#             >>> {('I1', 'I2'): (1, 10), ('O2', 'O1'): (0.2, None),
#                  ('O1', 'O2'): (None, 0.5)}
#     '''
#     new_bounds_lb = dict()
#     new_bounds_ub = dict()
#     for constraint in constraints:
#         lq = parse_constraint(constraint, '<=', new_bounds_lb, new_bounds_ub,
#                               categories)
#         gq = parse_constraint(constraint, '>=', new_bounds_lb, new_bounds_ub,
#                               categories)
#         if not (lq or gq):
#             raise ValueError('Cannot parse constraint: {0}'.format(
#                              constraint))
# 
#     new_bounds = dict()
#     for lb_key, lb_value in new_bounds_lb.items():
#         new_bounds[lb_key] = lb_value, new_bounds_ub.get(lb_key, None)
# 
#     for up_key, up_value in new_bounds_ub.items():
#         new_bounds[up_key] = new_bounds_lb.get(up_key, None), up_value
# 
#     assert new_bounds
#     return new_bounds
# 
# def contraint_is_price_ratio_type(bounds_key):
#     ''' Checks if given parameter is a tuple with two elements. In the case of price
#         ratio weight restrictions key of bounds dictionary will be a tuple with two
#         elements.
# 
#         Args:
#             tuple of str: tuple with elements.
# 
#         Returns:
#             bool: true if given element is a tuple with two elements, false otherwise.
#     '''
#     return isinstance(bounds_key, tuple) and len(bounds_key) == 2


from tkinter import Text, NONE, N, W, E, S, HORIZONTAL, END, TclError
from tkinter import StringVar, LEFT
from tkinter.ttk import Frame, Label, Scrollbar
from pyDEA.core.utils.dea_utils import create_bounds, contraint_is_price_ratio_type
        self.text.insert(END, weight + '\n')

    def validate_weights(self):
        ''' Checks if all weight restrictions are valid.

            Returns:
                bool: True if all weight restrictions are valid,
                    False otherwise.
        '''
        self.text.config(foreground='black')
        if self.error_tag_exists:
            try:
                self.text.tag_remove('error', 'error.first', 'error.last')
            except TclError:
                # there is no error tag
                pass

        self.error_tag_exists = False
        self.errors_strvar.set('')
        errors = []
        all_constraints = []
        for count, line in enumerate(self.text.get('1.0', 'end-1c').splitlines()):
            # Iterate lines
            if line:
                weight_as_list = []
                weight_as_list.append(line)
                try:
                    bounds = create_bounds(weight_as_list, self.current_categories)
                    assert len(bounds) == 1
                    key, value = bounds.popitem()

# Path: pyDEA/core/utils/dea_utils.py
# def create_bounds(constraints, categories):
#     ''' Creates proper data structures after parsing all constraints.
# 
#         Args:
#             constraints (list of str): list of constraints to parse.
#             categories (set of str): set of current categories.
# 
#         Returns:
#             dict of str to tuple of double,
#                 double or dict of tuple of str,
#                 str to tuple of double, double:
#                 dictionary with parsed values of constraints.
# 
#         Raises:
#             ValueError: if some of the constraints cannot be parsed.
# 
#         Example:
#             >>> categories = set(['I1', 'I2', 'O1', 'O2'])
#             >>> constraints = ['I1 <= 10', 'I1 >= 2', 'O1 >= 3', 'O2 <= 7']
#             >>> create_bounds(constraints, categories)
#             >>> {'I1': (2, 10), 'O1': (3, None), 'O2': (None, 7)}
#             >>> ratio_bounds = ['I1/I2 <= 10', 'I1/I2 >= 1',
#                                 'O2/O1 >= 0.2', 'O1/O2 <= 0.5']
#             >>> create_bounds(ratio_bounds, categories)
#             >>> {('I1', 'I2'): (1, 10), ('O2', 'O1'): (0.2, None),
#                  ('O1', 'O2'): (None, 0.5)}
#     '''
#     new_bounds_lb = dict()
#     new_bounds_ub = dict()
#     for constraint in constraints:
#         lq = parse_constraint(constraint, '<=', new_bounds_lb, new_bounds_ub,
#                               categories)
#         gq = parse_constraint(constraint, '>=', new_bounds_lb, new_bounds_ub,
#                               categories)
#         if not (lq or gq):
#             raise ValueError('Cannot parse constraint: {0}'.format(
#                              constraint))
# 
#     new_bounds = dict()
#     for lb_key, lb_value in new_bounds_lb.items():
#         new_bounds[lb_key] = lb_value, new_bounds_ub.get(lb_key, None)
# 
#     for up_key, up_value in new_bounds_ub.items():
#         new_bounds[up_key] = new_bounds_lb.get(up_key, None), up_value
# 
#     assert new_bounds
#     return new_bounds
# 
# def contraint_is_price_ratio_type(bounds_key):
#     ''' Checks if given parameter is a tuple with two elements. In the case of price
#         ratio weight restrictions key of bounds dictionary will be a tuple with two
#         elements.
# 
#         Args:
#             tuple of str: tuple with elements.
# 
#         Returns:
#             bool: true if given element is a tuple with two elements, false otherwise.
#     '''
#     return isinstance(bounds_key, tuple) and len(bounds_key) == 2


# Path: pyDEA/core/gui_modules/text_for_weights_gui.py
from tkinter import Text, NONE, N, W, E, S, HORIZONTAL, END, TclError
from tkinter import StringVar, LEFT
from tkinter.ttk import Frame, Label, Scrollbar
from pyDEA.core.utils.dea_utils import create_bounds, contraint_is_price_ratio_type

        self.text.insert(END, weight + '\n')

    def validate_weights(self):
        ''' Checks if all weight restrictions are valid.

            Returns:
                bool: True if all weight restrictions are valid,
                    False otherwise.
        '''
        self.text.config(foreground='black')
        if self.error_tag_exists:
            try:
                self.text.tag_remove('error', 'error.first', 'error.last')
            except TclError:
                # there is no error tag
                pass

        self.error_tag_exists = False
        self.errors_strvar.set('')
        errors = []
        all_constraints = []
        for count, line in enumerate(self.text.get('1.0', 'end-1c').splitlines()):
            # Iterate lines
            if line:
                weight_as_list = []
                weight_as_list.append(line)
                try:
                    bounds = create_bounds(weight_as_list, self.current_categories)
                    assert len(bounds) == 1
                    key, value = bounds.popitem()

                    is_price_ratio = contraint_is_price_ratio_type(key)