    def get_nearest_widget(self, target_widget, direction):
        """
        Find the nearest enabled widget to the specified target widget, bearing in mind direction of travel.

        Direction of travel is defined to be the movement from current Layout to next.  This is important
        for the case where we wrap back to the beginning or end of the Layouts - and so should still only
        look for the widgets nearest the top/bottom (depending on direction of travel).

        This function may return None if there is no match (e.g. all widgets are disabled).

        :param target_widget: the target widget to match.
        :param direction: The direction of travel across Layouts.
        """
        best_distance = 999999999
        match = None
        for i, column in enumerate(self._columns):
            indexed_column = list(enumerate(column))
            if direction < 0:
                indexed_column = reversed(indexed_column)
            # Force this to be a list for python 2/3 compatibility.
            live_widgets = list(filter(lambda x: x[1].is_tab_stop and not x[1].disabled, indexed_column))
            try:
                j, candidate = live_widgets[0]
                new_distance = _euclidian_distance(target_widget, candidate)
                if new_distance < best_distance:
                    best_distance = new_distance
                    match = candidate, i, j
            except IndexError:
                pass
        return match
Find the nearest enabled widget to the specified target widget, bearing in mind direction of travel.

Direction of travel is defined to be the movement from current Layout to next.  This is important
for the case where we wrap back to the beginning or end of the Layouts - and so should still only
look for the widgets nearest the top/bottom (depending on direction of travel).

This function may return None if there is no match (e.g. all widgets are disabled).

:param target_widget: the target widget to match.
:param direction: The direction of travel across Layouts.
asciimatics/widgets/layout.py