def chop_text(dc, text, max_size):
    """
    Chops the input `text` if its size does not fit in `max_size`, by cutting the
    text and adding ellipsis at the end.

    :param `dc`: a `wx.DC` device context;
    :param `text`: the text to chop;
    :param `max_size`: the maximum size in which the text should fit.
    """

    # first check if the text fits with no problems
    x, y = dc.GetMultiLineTextExtent(text)

    if x <= max_size:
        return text

    for i in range(len(text)):
        s = text[:i] + '...'

        x, y = dc.GetTextExtent(s)
        last_good_length = i

        if x > max_size:
            return text[:last_good_length-1] + "..."

    return '...'