'Set active handle based on the location of the mouse event'

def _set_active_handle(self, event):

    (c_idx, c_dist) = self._corner_handles.closest(event.x, event.y)
    (e_idx, e_dist) = self._edge_handles.closest(event.x, event.y)
    (m_idx, m_dist) = self._center_handle.closest(event.x, event.y)
    if (u'move' in self.state):
        self.active_handle = u'C'
        self._extents_on_press = self.extents
    elif (m_dist < (self.maxdist * 2)):
        self.active_handle = u'C'
    elif ((c_dist > self.maxdist) and (e_dist > self.maxdist)):
        self.active_handle = None
        return
    elif (c_dist < e_dist):
        self.active_handle = self._corner_order[c_idx]
    else:
        self.active_handle = self._edge_order[e_idx]
    (x1, x2, y1, y2) = self.extents
    if (self.active_handle in [u'W', u'SW', u'NW']):
        (x1, x2) = (x2, event.xdata)
    if (self.active_handle in [u'N', u'NW', u'NE']):
        (y1, y2) = (y2, event.ydata)
    self._extents_on_press = (x1, x2, y1, y2)
