示例#1
0
def keypress(char):
    """Handles the event when a user presses a key.

    Checks if there is a function with the right name; otherwise
    it prints an error message.

    char: string, letter to draw
    """
    # if we're still drawing the previous letter, bail out
    if bob.busy:
        return
    else:
        bob.busy = True

    # figure out which function to call, and call it
    try:
        name = 'draw_' + char
        func = getattr(letters, name)
    except AttributeError:
        print("I don't know how to draw an", char)
        bob.busy = False
        return

    func(bob, size)

    letters.skip(bob, size/2)
    bob.busy = False
示例#2
0
def keypress(char):
    """Handles the event when a user presses a key.
    Checks if there is a function with the right name; otherwise
    it prints an error message.
    char: string, letter to draw
    """
    # if we're still drawing the previous letter, bail out
    if bob.busy:
        return
    else:
        bob.busy = True

    # figure out which function to call, and call it
    try:
        name = 'draw_' + char
        func = getattr(letters, name)
    except AttributeError:
        print("I don't know how to draw an", char)
        bob.busy = False
        return

    func(bob, size)

    letters.skip(bob, size/2)
    bob.busy = False
示例#3
0
def keypress(char):
    """Obsługuje zdarzenie po naciśnięciu klawisza przez użytkownika.

    Sprawdzenie, czy istnieje funkcja o właściwej nazwie. W przeciwnym razie
    wyświetlany jest komunikat o błędzie.

    char: łańcuch, litera do narysowania
    """
    # W wypadku rysowania w dalszym ciągu poprzedniej litery stosowany jest wariant awaryjny
    if bob.busy:
        return
    else:
        bob.busy = True

    # Określenie funkcji do wywołania i wykonanie tej operacji
    try:
        name = 'draw_' + char
        func = getattr(letters, name)
    except AttributeError:
        print("Nie wiem, jak narysować znak ", char)
        bob.busy = False
        return

    func(bob, size)

    letters.skip(bob, size / 2)
    bob.busy = False