Simulate an ASCII cow saying text.

    :type text: string
    :param text: The text to print out.

    :type align: string
    :param algin: Where to align the cow. Can be 'left', 'centre' or 'right'
7898
def cowsay(text='', align='centre'):
    

    # Make align lowercase
    align = align.lower()

    # Set the cowtext
    cowtext = str(text)

    # Set top part of speech bubble to the length of the text plus 2
    topbar = ' ' * (len(text) + 2)

    # Set bottom part of speech bubble to the length of the text plus 2
    bottombar = ' ' * (len(text) + 2)

    # If align is centre
    if align in ["center", "centre"]:
        # Set the spacing before the cow to the length of half of the length of topbar plus 1
        spacing = " " * (int(len(topbar) / 2) + 1)

    # If align is left
    elif align == 'left':
        # Set spacing to a single space
        spacing = ' '

    # If align is right
    elif align == 'right':
        # Set the spacing to the length of the text plus 2
        spacing = " " * (len(text) + 2)

    else:
        # Raise a runtime warning
        raise ValueError("Invalid alignment provided.")

    # Print the top bar
    print(topbar)

    # Print the text
    print('( ' + repr(str(cowtext)) + ' )')

    # Print the bottom bar
    print(bottombar)

    # Print the cow with the spacing
    print(spacing + r'o   ^__^ ')
    print(spacing + r' o  (oO)\_______')
    print(spacing + r'    (__)\       )\/\ ')
    print(spacing + r'     U  ||----w | ')
    print(spacing + r'        ||     || ')
255156
def text_align(alignment)
      Kernel.raise ArgumentError, "Unknown alignment constant: #{alignment}" unless ALIGN_TYPE_NAMES.key?(alignment.to_i)
      primitive "text-align #{ALIGN_TYPE_NAMES[alignment.to_i]}"
    end
1256605
def draw_text(self, content):
        """"""

        wx2pango_alignment = {
            "left": pango.ALIGN_LEFT,
            "center": pango.ALIGN_CENTER,
            "right": pango.ALIGN_RIGHT,
        }

        cell_attributes = self.code_array.cell_attributes[self.key]

        angle = cell_attributes["angle"]

        if angle in [-90, 90]:
            rect = self.rect[1], self.rect[0], self.rect[3], self.rect[2]
        else:
            rect = self.rect

        # Text color attributes
        self.context.set_source_rgb(*self._get_text_color())

        ptx = pangocairo.CairoContext(self.context)
        pango_layout = ptx.create_layout()
        self.set_font(pango_layout)

        pango_layout.set_wrap(pango.WRAP_WORD_CHAR)

        pango_layout.set_width(int(round((rect[2] - 4.0) * pango.SCALE)))

        try:
            markup = cell_attributes["markup"]
        except KeyError:
            # Old file
            markup = False

        if markup:
            with warnings.catch_warnings(record=True) as warning_lines:
                warnings.resetwarnings()
                warnings.simplefilter("always")
                pango_layout.set_markup(unicode(content))

                if warning_lines:
                    w2unicode = lambda m: unicode(m.message)
                    msg = u"\n".join(map(w2unicode, warning_lines))
                    pango_layout.set_text(msg)
        else:
            pango_layout.set_text(unicode(content))

        alignment = cell_attributes["justification"]
        pango_layout.set_alignment(wx2pango_alignment[alignment])

        # Shift text for vertical alignment
        extents = pango_layout.get_pixel_extents()

        downshift = 0

        if cell_attributes["vertical_align"] == "bottom":
            downshift = rect[3] - extents[1][3] - 4

        elif cell_attributes["vertical_align"] == "middle":
            downshift = int((rect[3] - extents[1][3]) / 2) - 2

        self.context.save()

        self._rotate_cell(angle, rect)
        self.context.translate(0, downshift)

        # Spell check underline drawing
        if SpellChecker is not None and self.spell_check:
            text = unicode(pango_layout.get_text())
            lang = config["spell_lang"]
            for start, stop in self._check_spelling(text, lang=lang):
                self._draw_error_underline(ptx, pango_layout, start, stop-1)

        ptx.update_layout(pango_layout)
        ptx.show_layout(pango_layout)

        self.context.restore()
17545
def text(self, x, y, text, attr=None):
        '''
        self.pos(x, y)
        self.write_color(text, attr)
1105526
def ascii(text):
    
    if not isinstance(text, unicode):
        text = unicode(text)
    return unicodedata.normalize('NFKD', text).encode('ascii', 'ignore')
468993
def center_str(txt, font_name, font_size, offset=0):
    """"""
    return -(text_width(txt, font_name, font_size) / 2.0) + offset
12232
def optimally_align_text(x, y, texts, expand, renderer=None, ax=None,
                         direction='xy'):
    
    if ax is None:
        ax = plt.gca()
    if renderer is None:
        r = ax.get_figure().canvas.get_renderer()
    else:
        r = renderer
    bboxes = get_bboxes(texts, r, expand)
    if 'x' not in direction:
        ha = ['']
    else:
        ha = ['left', 'right', 'center']
    if 'y' not in direction:
        va = ['']
    else:
        va = ['bottom', 'top', 'center']
    alignment = list(product(ha, va))
    for i, text in enumerate(texts):
        counts = []
        for h, v in alignment:
            if h:
                text.set_ha(h)
            if v:
                text.set_va(v)
            bbox = text.get_window_extent(r).expanded(*expand).\
                transformed(ax.transData.inverted())
            c = get_points_inside_bbox(x, y, bbox)
            counts.append(len(c) + bbox.count_overlaps(bboxes) - 1)
        a = np.argmin(counts)
        if 'x' in direction:
            text.set_ha(alignment[a][0])
        if 'y' in direction:
            text.set_va(alignment[a][1])
        bboxes[i] = text.get_window_extent(r).expanded(*expand).\
            transformed(ax.transData.inverted())
    return texts
548433
def println(self, text=""):
        
        if self.word_wrap:
            # find directives in complete text
            directives = ansi_color.find_directives(text, self)

            # strip ansi from text
            clean_text = ansi_color.strip_ansi_codes(text)

            # wrap clean text
            clean_lines = self.tw.wrap(clean_text)

            # print wrapped text
            index = 0
            for line in clean_lines:
                line_length = len(line)
                y = 0
                while y < line_length:
                    method, args = directives[index]
                    if method == self.putch:
                        y += 1
                    method(*args)
                    index += 1
                self.newline()
        else:
            self.puts(text)
            self.newline()
726754
def html(self, label, *msg):
        
        lbl = "[" + label + "] "
        txt = lbl + " " + " ".join(list(msg))
        if self.notebook is True:
            html = HTML(txt)
            display(lbl + html)
        else:
            print(lbl + txt)
176865
def text args, key_args
      anchor, font, justify, text =
      key_args.values_at(*%w{anchor font justify text})
       # width handled by handle_generic_config
      
      proc do |tkaroid, cos_r, sin_r|
        x = tkaroid.x
        y = tkaroid.y
        params = tkaroid.params

        xv, yv = args.map {|arg| arg[params] rescue arg}
        coords = [
          x + xv * cos_r - yv * sin_r,
          y + xv * sin_r + yv * cos_r
        ]
        
        config = {}
        handle_generic_config(config, params, key_args)

        if anchor
          config[:anchor] = anchor[params] rescue anchor
        end
        if font
          config[:font] = font[params] rescue font
        end
        if justify
          config[:justify] = justify[params] rescue justify
        end
        if text
          config[:text] = text[params] rescue text
        end

        [TkcText, coords, config]
      end
    end
861587
def to_ascii_equivalent(text):
    

    if text is None:
        return None
    elif isinstance(text, binary_type):
        text = text.decode(DEFAULT_ENCODING)
    elif not isinstance(text, text_type):
        text = text_type(text)

    text = EMPTY_STR.join(_ASCII_PUNCTUATION_MAP.get(c, c) for c in text)
    return EMPTY_STR.join(c for c in unicodedata.normalize('NFD', text) if unicodedata.category(c) != 'Mn')
496665
def with_text(self, text, markdown=None):
        '''
        '''
        self._text = text
        self._markdown = markdown or False

        return self
562069
def text(self, text):
        
        tc = self._tc
        tc.clear_content()
        p = tc.add_p()
        r = p.add_r()
        r.text = text
1001058
def line(self, text=''):
        ''''''
        self.out.write(text)
        self.out.write('\n')
449548
def SelectGlyph(aFont, message="Select a glyph:", title='FontParts'):
    
    return dispatcher["SelectGlyph"](aFont=aFont, message=message, title=title)
796836
def fmt_text(text, bg = None, fg = None, attr = None, plain = False):
        
        if not plain:
            if fg is not None:
                text = TEXT_FORMATING['fg'][fg] + text
            if bg is not None:
                text = TEXT_FORMATING['bg'][bg] + text
            if attr is not None:
                text = TEXT_FORMATING['attr'][attr] + text
            if (fg is not None) or (bg is not None) or (attr is not None):
                text += TEXT_FORMATING['rst']
        return text
289982
def text(self, x, y, text):
        
        for i, char in enumerate(text):
            self.point(x + i, y, char)