#!/usr/bin/python3
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Pango

CHARS = {
    'A': ['  #  ','## ##','#####','#   #','#   #'],
    'B': ['#### ','#   #','#### ','#   #','#### '],
    'C': [' ####','#    ','#    ','#    ',' ####'],
    'D': ['#### ','#   #','#   #','#   #','#### '],
    'E': ['#####','#    ','#### ','#    ','#####'],
    'F': ['#####','#    ','#### ','#    ','#    '],
    'G': [' ####','#    ','# ###','#   #',' ####'],
    'H': ['#   #','#   #','#####','#   #','#   #'],
    'I': ['#####','  #  ','  #  ','  #  ','#####'],
    'J': ['#####','    #','    #','#   #',' ### '],
    'K': ['#   #','#  # ','##   ','#  # ','#   #'],
    'L': ['#    ','#    ','#    ','#    ','#####'],
    'M': ['#   #','## ##','# # #','#   #','#   #'],
    'N': ['#   #','##  #','# # #','#  ##','#   #'],
    'O': [' ### ','#   #','#   #','#   #',' ### '],
    'P': ['#### ','#   #','#### ','#    ','#    '],
    'Q': [' ### ','#   #','# # #','#  # ',' ## #'],
    'R': ['#### ','#   #','#### ','#  # ','#   #'],
    'S': [' ####','#    ',' ### ','    #','#### '],
    'T': ['#####','  #  ','  #  ','  #  ','  #  '],
    'U': ['#   #','#   #','#   #','#   #',' ### '],
    'V': ['#   #','#   #','#   #',' # # ','  #  '],
    'W': ['#   #','#   #','# # #','## ##','#   #'],
    'X': ['#   #',' # # ','  #  ',' # # ','#   #'],
    'Y': ['#   #',' # # ','  #  ','  #  ','  #  '],
    'Z': ['#####','   # ','  #  ',' #   ','#####'],
    '0': [' ### ','#  ##','# # #','##  #',' ### '],
    '1': ['  #  ',' ##  ','  #  ','  #  ','#####'],
    '2': [' ### ','#   #','  ## ',' #   ','#####'],
    '3': ['#### ','    #',' ### ','    #','#### '],
    '4': ['#   #','#   #','#####','    #','    #'],
    '5': ['#####','#    ','#### ','    #','#### '],
    '6': [' ### ','#    ','#### ','#   #',' ### '],
    '7': ['#####','    #','   # ','  #  ',' #   '],
    '8': [' ### ','#   #',' ### ','#   #',' ### '],
    '9': [' ### ','#   #',' ####','    #',' ### '],
    ' ': ['     ','     ','     ','     ','     '],
    '!': ['  #  ','  #  ','  #  ','     ','  #  '],
    '.': ['     ','     ','     ','     ','  #  '],
    '?': [' ### ','#   #','  ## ','     ','  #  '],
}

def to_ascii(text):
    text = text.upper()
    rows = ['', '', '', '', '']
    for ch in text:
        pat = CHARS.get(ch, CHARS.get(' ', ['     ']*5))
        for i in range(5):
            rows[i] += pat[i] + '  '
    return '\n'.join(rows)

class App(Gtk.Window):
    def __init__(self):
        super().__init__(title='ASCII Art Generator')
        self.set_default_size(700, 400)
        vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6)
        vbox.set_margin_top(10); vbox.set_margin_bottom(10)
        vbox.set_margin_start(10); vbox.set_margin_end(10)
        self.add(vbox)
        hbox = Gtk.Box(spacing=6)
        self.entry = Gtk.Entry(); self.entry.set_placeholder_text('Enter text...')
        self.entry.connect('changed', self.on_change)
        btn = Gtk.Button(label='Convert')
        btn.connect('clicked', self.on_change)
        hbox.pack_start(self.entry, True, True, 0)
        hbox.pack_start(btn, False, False, 0)
        vbox.pack_start(hbox, False, False, 0)
        sw = Gtk.ScrolledWindow()
        self.tv = Gtk.TextView(); self.tv.set_editable(False)
        font = self.tv.get_pango_context().load_font(
            Pango.FontDescription('Monospace 10'))
        self.tv.override_font(Pango.FontDescription('Monospace 10'))
        sw.add(self.tv)
        vbox.pack_start(sw, True, True, 0)
    def on_change(self, *_):
        t = self.entry.get_text()
        self.tv.get_buffer().set_text(to_ascii(t) if t else '')

win = App()
win.connect('destroy', Gtk.main_quit)
win.show_all()
Gtk.main()
