bastd.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 7
 6# (see https://ballistica.net/wiki/meta-tag-system)
 7
 8from __future__ import annotations
 9
10from typing import TYPE_CHECKING
11
12import ba
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 ba.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 keyboard
44class EnglishKeyboard(ba.Keyboard):
45    """Default English keyboard."""
46    name = 'English'
47    chars = [('q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p'),
48             ('a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l'),
49             ('z', 'x', 'c', 'v', 'b', 'n', 'm')]
50    nums = ('1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '/', ':',
51            ';', '(', ')', '$', '&', '@', '"', '.', ',', '?', '!', '\'', '_')
52    pages: dict[str, tuple[str, ...]] = {
53        f'emoji{i}': tuple(page)
54        for i, page in enumerate(generate_emojis(len(nums)))
55    }
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 ba.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 ba.Keyboard pages

class EnglishKeyboard(ba._keyboard.Keyboard):
45class EnglishKeyboard(ba.Keyboard):
46    """Default English keyboard."""
47    name = 'English'
48    chars = [('q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p'),
49             ('a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l'),
50             ('z', 'x', 'c', 'v', 'b', 'n', 'm')]
51    nums = ('1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '/', ':',
52            ';', '(', ')', '$', '&', '@', '"', '.', ',', '?', '!', '\'', '_')
53    pages: dict[str, tuple[str, ...]] = {
54        f'emoji{i}': tuple(page)
55        for i, page in enumerate(generate_emojis(len(nums)))
56    }

Default English keyboard.

EnglishKeyboard()
name: str = 'English'

Displays when user selecting this keyboard.

chars: list[tuple[str, ...]] = [('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: tuple[str, ...] = ('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.