<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def handle_new_selection(self, models):
 """Handles the selection for generic widgets This is a helper method for generic widgets that want to modify the selection. These widgets can pass a list of newly selected (or clicked on) models. The method looks at the previous selection, the passed models and the list of pressed (modifier) keys: * If no modifier key is pressed, the previous selection is cleared and the new selection is set to the passed models * If the extend-selection modifier key is pressed, elements of `models` that are _not_ in the previous selection are selected, those that are in the previous selection are deselected :param models: The list of models that are newly selected/clicked on """

        models = self._check_model_types(models)

        if extend_selection():
            already_selected_elements = models & self._selected
            newly_selected_elements = models - self._selected
            self._selected.difference_update(already_selected_elements)
            self._selected.update(newly_selected_elements)
        else:
            self._selected = models
        self._selected = reduce_to_parent_states(self._selected)