bauiv1lib.keyboard.englishkeyboard

Defines a default keyboards.

 1# Released under the MIT License. See LICENSE for details.
 2#
 3"""Defines a default keyboards."""
 4
 5# ba_meta require api 8
 6# (see https://ballistica.net/wiki/meta-tag-system)
 7
 8from __future__ import annotations
 9
10from typing import TYPE_CHECKING
11
12import bauiv1 as bui
13
14if TYPE_CHECKING:
15    from typing import Iterable
16
17
18def split(chars: Iterable[str], maxlen: int) -> list[list[str]]:
19    """Returns char groups with a fixed number of elements"""
20    result = []
21    shatter: list[str] = []
22    for i in chars:
23        if len(shatter) < maxlen:
24            shatter.append(i)
25        else:
26            result.append(shatter)
27            shatter = [i]
28    if shatter:
29        while len(shatter) < maxlen:
30            shatter.append('')
31        result.append(shatter)
32    return result
33
34
35def generate_emojis(maxlen: int) -> list[list[str]]:
36    """Generates a lot of UTF8 emojis prepared for bui.Keyboard pages"""
37    all_emojis = split([chr(i) for i in range(0x1F601, 0x1F650)], maxlen)
38    all_emojis += split([chr(i) for i in range(0x2702, 0x27B1)], maxlen)
39    all_emojis += split([chr(i) for i in range(0x1F680, 0x1F6C1)], maxlen)
40    return all_emojis
41
42
43# ba_meta export bauiv1.Keyboard
44class EnglishKeyboard(bui.Keyboard):
45    """Default English keyboard."""
46
47    name = 'English'
48    chars = [
49        ('q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p'),
50        ('a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l'),
51        ('z', 'x', 'c', 'v', 'b', 'n', 'm'),
52    ]
53    nums = (
54        '1',
55        '2',
56        '3',
57        '4',
58        '5',
59        '6',
60        '7',
61        '8',
62        '9',
63        '0',
64        '-',
65        '/',
66        ':',
67        ';',
68        '(',
69        ')',
70        '$',
71        '&',
72        '@',
73        '"',
74        '.',
75        ',',
76        '?',
77        '!',
78        '\'',
79        '_',
80    )
81    pages: dict[str, tuple[str, ...]] = {
82        f'emoji{i}': tuple(page)
83        for i, page in enumerate(generate_emojis(len(nums)))
84    }
def split(chars: Iterable[str], maxlen: int) -> list[list[str]]:
19def split(chars: Iterable[str], maxlen: int) -> list[list[str]]:
20    """Returns char groups with a fixed number of elements"""
21    result = []
22    shatter: list[str] = []
23    for i in chars:
24        if len(shatter) < maxlen:
25            shatter.append(i)
26        else:
27            result.append(shatter)
28            shatter = [i]
29    if shatter:
30        while len(shatter) < maxlen:
31            shatter.append('')
32        result.append(shatter)
33    return result

Returns char groups with a fixed number of elements

def generate_emojis(maxlen: int) -> list[list[str]]:
36def generate_emojis(maxlen: int) -> list[list[str]]:
37    """Generates a lot of UTF8 emojis prepared for bui.Keyboard pages"""
38    all_emojis = split([chr(i) for i in range(0x1F601, 0x1F650)], maxlen)
39    all_emojis += split([chr(i) for i in range(0x2702, 0x27B1)], maxlen)
40    all_emojis += split([chr(i) for i in range(0x1F680, 0x1F6C1)], maxlen)
41    return all_emojis

Generates a lot of UTF8 emojis prepared for bui.Keyboard pages

class EnglishKeyboard(bauiv1._keyboard.Keyboard):
45class EnglishKeyboard(bui.Keyboard):
46    """Default English keyboard."""
47
48    name = 'English'
49    chars = [
50        ('q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p'),
51        ('a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l'),
52        ('z', 'x', 'c', 'v', 'b', 'n', 'm'),
53    ]
54    nums = (
55        '1',
56        '2',
57        '3',
58        '4',
59        '5',
60        '6',
61        '7',
62        '8',
63        '9',
64        '0',
65        '-',
66        '/',
67        ':',
68        ';',
69        '(',
70        ')',
71        '$',
72        '&',
73        '@',
74        '"',
75        '.',
76        ',',
77        '?',
78        '!',
79        '\'',
80        '_',
81    )
82    pages: dict[str, tuple[str, ...]] = {
83        f'emoji{i}': tuple(page)
84        for i, page in enumerate(generate_emojis(len(nums)))
85    }

Default English keyboard.

name = 'English'

Displays when user selecting this keyboard.

chars = [('q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p'), ('a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l'), ('z', 'x', 'c', 'v', 'b', 'n', 'm')]

Used for row/column lengths.

nums = ('1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '/', ':', ';', '(', ')', '$', '&', '@', '"', '.', ',', '?', '!', "'", '_')

The 'num' page.

pages: dict[str, tuple[str, ...]] = {'emoji0': ('😁', '😂', '😃', '😄', '😅', '😆', '😇', '😈', '😉', '😊', '😋', '😌', '😍', '😎', '😏', '😐', '😑', '😒', '😓', '😔', '😕', '😖', '😗', '😘', '😙', '😚'), 'emoji1': ('😛', '😜', '😝', '😞', '😟', '😠', '😡', '😢', '😣', '😤', '😥', '😦', '😧', '😨', '😩', '😪', '😫', '😬', '😭', '😮', '😯', '😰', '😱', '😲', '😳', '😴'), 'emoji2': ('😵', '😶', '😷', '😸', '😹', '😺', '😻', '😼', '😽', '😾', '😿', '🙀', '🙁', '🙂', '🙃', '🙄', '🙅', '🙆', '🙇', '🙈', '🙉', '🙊', '🙋', '🙌', '🙍', '🙎'), 'emoji3': ('🙏', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ''), 'emoji4': ('✂', '✃', '✄', '✅', '✆', '✇', '✈', '✉', '✊', '✋', '✌', '✍', '✎', '✏', '✐', '✑', '✒', '✓', '✔', '✕', '✖', '✗', '✘', '✙', '✚', '✛'), 'emoji5': ('✜', '✝', '✞', '✟', '✠', '✡', '✢', '✣', '✤', '✥', '✦', '✧', '✨', '✩', '✪', '✫', '✬', '✭', '✮', '✯', '✰', '✱', '✲', '✳', '✴', '✵'), 'emoji6': ('✶', '✷', '✸', '✹', '✺', '✻', '✼', '✽', '✾', '✿', '❀', '❁', '❂', '❃', '❄', '❅', '❆', '❇', '❈', '❉', '❊', '❋', '❌', '❍', '❎', '❏'), 'emoji7': ('❐', '❑', '❒', '❓', '❔', '❕', '❖', '❗', '❘', '❙', '❚', '❛', '❜', '❝', '❞', '❟', '❠', '❡', '❢', '❣', '❤', '❥', '❦', '❧', '❨', '❩'), 'emoji8': ('❪', '❫', '❬', '❭', '❮', '❯', '❰', '❱', '❲', '❳', '❴', '❵', '❶', '❷', '❸', '❹', '❺', '❻', '❼', '❽', '❾', '❿', '➀', '➁', '➂', '➃'), 'emoji9': ('➄', '➅', '➆', '➇', '➈', '➉', '➊', '➋', '➌', '➍', '➎', '➏', '➐', '➑', '➒', '➓', '➔', '➕', '➖', '➗', '➘', '➙', '➚', '➛', '➜', '➝'), 'emoji10': ('➞', '➟', '➠', '➡', '➢', '➣', '➤', '➥', '➦', '➧', '➨', '➩', '➪', '➫', '➬', '➭', '➮', '➯', '➰', '', '', '', '', '', '', ''), 'emoji11': ('🚀', '🚁', '🚂', '🚃', '🚄', '🚅', '🚆', '🚇', '🚈', '🚉', '🚊', '🚋', '🚌', '🚍', '🚎', '🚏', '🚐', '🚑', '🚒', '🚓', '🚔', '🚕', '🚖', '🚗', '🚘', '🚙'), 'emoji12': ('🚚', '🚛', '🚜', '🚝', '🚞', '🚟', '🚠', '🚡', '🚢', '🚣', '🚤', '🚥', '🚦', '🚧', '🚨', '🚩', '🚪', '🚫', '🚬', '🚭', '🚮', '🚯', '🚰', '🚱', '🚲', '🚳'), 'emoji13': ('🚴', '🚵', '🚶', '🚷', '🚸', '🚹', '🚺', '🚻', '🚼', '🚽', '🚾', '🚿', '🛀', '', '', '', '', '', '', '', '', '', '', '', '', '')}

Extra chars like emojis.