mirror of
https://github.com/RYDE-WORK/ballistica.git
synced 2026-02-05 23:13:46 +08:00
add standard emojis and some screen messages
This commit is contained in:
parent
448eafd13f
commit
9b041fe51a
@ -37,6 +37,8 @@ class Keyboard:
|
|||||||
and the user can select which one they want to use.
|
and the user can select which one they want to use.
|
||||||
On-screen keyboard uses chars from active ba.Keyboard.
|
On-screen keyboard uses chars from active ba.Keyboard.
|
||||||
Attributes:
|
Attributes:
|
||||||
|
name
|
||||||
|
Displays when user selecting this keyboard.
|
||||||
chars
|
chars
|
||||||
Used for row/column lengths.
|
Used for row/column lengths.
|
||||||
pages
|
pages
|
||||||
@ -45,6 +47,7 @@ class Keyboard:
|
|||||||
The 'num' page.
|
The 'num' page.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
name: str
|
||||||
chars: List[Tuple[str, ...]]
|
chars: List[Tuple[str, ...]]
|
||||||
pages: Dict[str, Tuple[str, ...]]
|
pages: Dict[str, Tuple[str, ...]]
|
||||||
nums: Tuple[str, ...]
|
nums: Tuple[str, ...]
|
||||||
|
|||||||
@ -228,6 +228,12 @@ class OnScreenKeyboardWindow(ba.Window):
|
|||||||
color=key_color_dark,
|
color=key_color_dark,
|
||||||
label=ba.Lstr(resource='spaceKeyText'),
|
label=ba.Lstr(resource='spaceKeyText'),
|
||||||
on_activate_call=ba.Call(self._type_char, ' '))
|
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
|
btn2 = self._space_button
|
||||||
btn3 = self._emoji_button
|
btn3 = self._emoji_button
|
||||||
ba.widget(edit=btn1, right_widget=btn2, left_widget=btn3)
|
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(
|
self._keyboard_index = (self._keyboard_index + 1) % len(
|
||||||
ba.app.metascan.keyboards)
|
ba.app.metascan.keyboards)
|
||||||
self._load_keyboard()
|
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:
|
def _shift(self) -> None:
|
||||||
ba.playsound(self._click_sound)
|
ba.playsound(self._click_sound)
|
||||||
|
|||||||
@ -30,15 +30,44 @@ from typing import TYPE_CHECKING
|
|||||||
import ba
|
import ba
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
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
|
# ba_meta export keyboard
|
||||||
class EnglishKeyboard(ba.Keyboard):
|
class EnglishKeyboard(ba.Keyboard):
|
||||||
"""Default English keyboard."""
|
"""Default English keyboard."""
|
||||||
|
name = 'English'
|
||||||
chars = [('q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p'),
|
chars = [('q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p'),
|
||||||
('a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l'),
|
('a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l'),
|
||||||
('z', 'x', 'c', 'v', 'b', 'n', 'm')]
|
('z', 'x', 'c', 'v', 'b', 'n', 'm')]
|
||||||
nums = ('1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '/', ':',
|
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)))
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user