add standard emojis and some screen messages

This commit is contained in:
Roman Trapeznikov 2020-08-03 11:11:29 +03:00
parent 448eafd13f
commit 9b041fe51a
No known key found for this signature in database
GPG Key ID: 827DD41DACE1E018
3 changed files with 46 additions and 2 deletions

View File

@ -37,6 +37,8 @@ class Keyboard:
and the user can select which one they want to use.
On-screen keyboard uses chars from active ba.Keyboard.
Attributes:
name
Displays when user selecting this keyboard.
chars
Used for row/column lengths.
pages
@ -45,6 +47,7 @@ class Keyboard:
The 'num' page.
"""
name: str
chars: List[Tuple[str, ...]]
pages: Dict[str, Tuple[str, ...]]
nums: Tuple[str, ...]

View File

@ -228,6 +228,12 @@ class OnScreenKeyboardWindow(ba.Window):
color=key_color_dark,
label=ba.Lstr(resource='spaceKeyText'),
on_activate_call=ba.Call(self._type_char, ' '))
ba.textwidget(parent=self._root_widget,
h_align='center',
position=(210, v - 70),
size=(key_width * 6.1, key_height + 15),
text='Double press space to change keyboard',
scale=0.75)
btn2 = self._space_button
btn3 = self._emoji_button
ba.widget(edit=btn1, right_widget=btn2, left_widget=btn3)
@ -317,6 +323,12 @@ class OnScreenKeyboardWindow(ba.Window):
self._keyboard_index = (self._keyboard_index + 1) % len(
ba.app.metascan.keyboards)
self._load_keyboard()
if len(ba.app.metascan.keyboards) < 2:
ba.playsound(ba.getsound('error'))
ba.screenmessage('No other keyboards available', color=(1, 0, 0))
else:
ba.screenmessage(f'Switching keyboard to "{self._keyboard.name}"',
color=(0, 1, 0))
def _shift(self) -> None:
ba.playsound(self._click_sound)

View File

@ -30,15 +30,44 @@ from typing import TYPE_CHECKING
import ba
if TYPE_CHECKING:
from typing import Dict, Tuple
from typing import Iterable, List, Tuple, Dict
def split(chars: Iterable[str], maxlen: int) -> List[List[str]]:
"""Returns char groups with a fixed number of elements"""
result = []
shatter: List[str] = []
for i in chars:
if len(shatter) < maxlen:
shatter.append(i)
else:
result.append(shatter)
shatter = [i]
if shatter:
while len(shatter) < maxlen:
shatter.append('')
result.append(shatter)
return result
def generate_emojis(maxlen: int) -> List[List[str]]:
"""Generates a lot of UTF8 emojis prepared for ba.Keyboard pages"""
all_emojis = split([chr(i) for i in range(0x1F601, 0x1F650)], maxlen)
all_emojis += split([chr(i) for i in range(0x2702, 0x27B1)], maxlen)
all_emojis += split([chr(i) for i in range(0x1F680, 0x1F6C1)], maxlen)
return all_emojis
# ba_meta export keyboard
class EnglishKeyboard(ba.Keyboard):
"""Default English keyboard."""
name = 'English'
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')]
nums = ('1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '/', ':',
';', '(', ')', '$', '&', '@', '"', '.', ',', '?', '!', '\'', '_')
pages: Dict[str, Tuple[str, ...]] = {}
pages: Dict[str, Tuple[str, ...]] = {
f'emoji{i}': tuple(page)
for i, page in enumerate(generate_emojis(len(nums)))
}