'whenever a key is pressed'

def key_press_callback(self, event):

    if (not event.inaxes):
        return
    if (event.key == 't'):
        self.showverts = (not self.showverts)
        self.line.set_visible(self.showverts)
        if (not self.showverts):
            self._ind = None
    elif (event.key == 'd'):
        ind = self.get_ind_under_point(event)
        if (ind is not None):
            self.poly.xy = [tup for (i, tup) in enumerate(self.poly.xy) if (i != ind)]
            self.line.set_data(zip(*self.poly.xy))
    elif (event.key == 'i'):
        xys = self.poly.get_transform().transform(self.poly.xy)
        p = (event.x, event.y)
        for i in range((len(xys) - 1)):
            s0 = xys[i]
            s1 = xys[(i + 1)]
            d = dist_point_to_segment(p, s0, s1)
            if (d <= self.epsilon):
                self.poly.xy = np.array(((list(self.poly.xy[:i]) + [(event.xdata, event.ydata)]) + list(self.poly.xy[i:])))
                self.line.set_data(zip(*self.poly.xy))
                break
    self.canvas.draw()
