mirror of
https://github.com/RYDE-WORK/ballistica.git
synced 2026-02-05 15:03:33 +08:00
Syncing latest changes between public/private.
This commit is contained in:
commit
400488cc66
@ -26,6 +26,8 @@ from typing import TYPE_CHECKING, cast
|
|||||||
|
|
||||||
import _ba
|
import _ba
|
||||||
import ba
|
import ba
|
||||||
|
from ba import charstr
|
||||||
|
from ba import SpecialChar as SpCh
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from typing import List, Tuple, Optional
|
from typing import List, Tuple, Optional
|
||||||
@ -36,6 +38,7 @@ class OnScreenKeyboardWindow(ba.Window):
|
|||||||
|
|
||||||
def __init__(self, textwidget: ba.Widget, label: str, max_chars: int):
|
def __init__(self, textwidget: ba.Widget, label: str, max_chars: int):
|
||||||
# pylint: disable=too-many-locals
|
# pylint: disable=too-many-locals
|
||||||
|
# pylint: disable=too-many-statements
|
||||||
self._target_text = textwidget
|
self._target_text = textwidget
|
||||||
self._width = 700
|
self._width = 700
|
||||||
self._height = 400
|
self._height = 400
|
||||||
@ -86,9 +89,12 @@ class OnScreenKeyboardWindow(ba.Window):
|
|||||||
always_show_carat=True)
|
always_show_carat=True)
|
||||||
|
|
||||||
self._shift_button = None
|
self._shift_button = None
|
||||||
|
self._double_press_shift = False
|
||||||
self._num_mode_button = None
|
self._num_mode_button = None
|
||||||
|
self._emoji_button = None
|
||||||
self._char_keys: List[ba.Widget] = []
|
self._char_keys: List[ba.Widget] = []
|
||||||
self._mode = 'normal'
|
self._mode = 'normal'
|
||||||
|
self._last_mode = 'normal'
|
||||||
|
|
||||||
v = self._height - 180
|
v = self._height - 180
|
||||||
key_width = 46
|
key_width = 46
|
||||||
@ -125,7 +131,7 @@ class OnScreenKeyboardWindow(ba.Window):
|
|||||||
autoselect=True,
|
autoselect=True,
|
||||||
textcolor=key_textcolor,
|
textcolor=key_textcolor,
|
||||||
color=key_color_dark,
|
color=key_color_dark,
|
||||||
label=ba.charstr(ba.SpecialChar.SHIFT),
|
label=charstr(SpCh.SHIFT),
|
||||||
enable_sound=False,
|
enable_sound=False,
|
||||||
extra_touch_border_scale=0.3,
|
extra_touch_border_scale=0.3,
|
||||||
button_type='square',
|
button_type='square',
|
||||||
@ -157,7 +163,7 @@ class OnScreenKeyboardWindow(ba.Window):
|
|||||||
repeat=True,
|
repeat=True,
|
||||||
textcolor=key_textcolor,
|
textcolor=key_textcolor,
|
||||||
color=key_color_dark,
|
color=key_color_dark,
|
||||||
label=ba.charstr(ba.SpecialChar.DELETE),
|
label=charstr(SpCh.DELETE),
|
||||||
button_type='square',
|
button_type='square',
|
||||||
on_activate_call=self._del)
|
on_activate_call=self._del)
|
||||||
v -= (key_height + 9)
|
v -= (key_height + 9)
|
||||||
@ -176,6 +182,19 @@ class OnScreenKeyboardWindow(ba.Window):
|
|||||||
color=key_color_dark,
|
color=key_color_dark,
|
||||||
label='',
|
label='',
|
||||||
)
|
)
|
||||||
|
if self._emoji_button is None:
|
||||||
|
self._emoji_button = ba.buttonwidget(
|
||||||
|
parent=self._root_widget,
|
||||||
|
position=(56, v - 8),
|
||||||
|
size=(key_width, key_height + 5),
|
||||||
|
autoselect=True,
|
||||||
|
enable_sound=False,
|
||||||
|
textcolor=key_textcolor,
|
||||||
|
color=key_color_dark,
|
||||||
|
label=charstr(SpCh.LOGO_FLAT),
|
||||||
|
extra_touch_border_scale=0.3,
|
||||||
|
button_type='square',
|
||||||
|
)
|
||||||
btn1 = self._num_mode_button
|
btn1 = self._num_mode_button
|
||||||
btn2 = ba.buttonwidget(parent=self._root_widget,
|
btn2 = ba.buttonwidget(parent=self._root_widget,
|
||||||
position=(210, v - 12),
|
position=(210, v - 12),
|
||||||
@ -188,10 +207,12 @@ class OnScreenKeyboardWindow(ba.Window):
|
|||||||
label=ba.Lstr(resource='spaceKeyText'),
|
label=ba.Lstr(resource='spaceKeyText'),
|
||||||
on_activate_call=ba.Call(
|
on_activate_call=ba.Call(
|
||||||
self._type_char, ' '))
|
self._type_char, ' '))
|
||||||
ba.widget(edit=btn1, right_widget=btn2)
|
btn3 = self._emoji_button
|
||||||
|
ba.widget(edit=btn1, right_widget=btn2, left_widget=btn3)
|
||||||
ba.widget(edit=btn2,
|
ba.widget(edit=btn2,
|
||||||
left_widget=btn1,
|
left_widget=btn1,
|
||||||
right_widget=self._done_button)
|
right_widget=self._done_button)
|
||||||
|
ba.widget(edit=btn3, left_widget=btn1)
|
||||||
ba.widget(edit=self._done_button, left_widget=btn2)
|
ba.widget(edit=self._done_button, left_widget=btn2)
|
||||||
|
|
||||||
ba.containerwidget(edit=self._root_widget,
|
ba.containerwidget(edit=self._root_widget,
|
||||||
@ -212,11 +233,15 @@ class OnScreenKeyboardWindow(ba.Window):
|
|||||||
ba.buttonwidget(edit=self._shift_button,
|
ba.buttonwidget(edit=self._shift_button,
|
||||||
color=self._key_color_lit
|
color=self._key_color_lit
|
||||||
if self._mode == 'caps' else self._key_color_dark,
|
if self._mode == 'caps' else self._key_color_dark,
|
||||||
label=ba.charstr(ba.SpecialChar.SHIFT),
|
label=charstr(SpCh.SHIFT),
|
||||||
on_activate_call=self._shift)
|
on_activate_call=self._shift)
|
||||||
ba.buttonwidget(edit=self._num_mode_button,
|
ba.buttonwidget(edit=self._num_mode_button,
|
||||||
label='123#&*',
|
label='123#&*',
|
||||||
on_activate_call=self._num_mode)
|
on_activate_call=self._num_mode)
|
||||||
|
ba.buttonwidget(edit=self._emoji_button,
|
||||||
|
color=self._key_color_dark,
|
||||||
|
label=charstr(SpCh.LOGO_FLAT),
|
||||||
|
on_activate_call=self._emoji_mode)
|
||||||
elif self._mode == 'num':
|
elif self._mode == 'num':
|
||||||
chars = [
|
chars = [
|
||||||
'1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '/',
|
'1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '/',
|
||||||
@ -230,6 +255,32 @@ class OnScreenKeyboardWindow(ba.Window):
|
|||||||
ba.buttonwidget(edit=self._num_mode_button,
|
ba.buttonwidget(edit=self._num_mode_button,
|
||||||
label='abc',
|
label='abc',
|
||||||
on_activate_call=self._abc_mode)
|
on_activate_call=self._abc_mode)
|
||||||
|
ba.buttonwidget(edit=self._emoji_button,
|
||||||
|
color=self._key_color_dark,
|
||||||
|
label=charstr(SpCh.LOGO_FLAT),
|
||||||
|
on_activate_call=self._emoji_mode)
|
||||||
|
|
||||||
|
elif self._mode in ['emoji', 'emoji2']:
|
||||||
|
chars = [
|
||||||
|
'💣', '💥', '🙂', '😄', '😆', '😅', '😂', '☺', '😀', '😉', '😇', '😎',
|
||||||
|
'😰', '😠', '😈', '😨', '😛', '😜', '😝', '😐', '😑', '😵', '😬', '😡',
|
||||||
|
'😌', '😍'
|
||||||
|
]
|
||||||
|
if self._mode == 'emoji2':
|
||||||
|
chars = [
|
||||||
|
'😔', '😥', '😭', '😖', '😓', '😉', '😴', '😷', '👋', '💯', '🙏', '💪',
|
||||||
|
'👀', '💬', '💀', '☠', '💩', '👻', '👽', '👾', '❤', '💛', '💚', '💙',
|
||||||
|
'💜', '💔'
|
||||||
|
]
|
||||||
|
ba.buttonwidget(edit=self._shift_button,
|
||||||
|
color=self._key_color_lit if self._mode == 'emoji2'
|
||||||
|
else self._key_color_dark,
|
||||||
|
label=charstr(SpCh.SHIFT),
|
||||||
|
on_activate_call=self._emoji_mode_2)
|
||||||
|
ba.buttonwidget(edit=self._emoji_button,
|
||||||
|
color=self._key_color_lit,
|
||||||
|
label=charstr(SpCh.LOGO_FLAT),
|
||||||
|
on_activate_call=self._emoji_mode)
|
||||||
|
|
||||||
for i, btn in enumerate(self._char_keys):
|
for i, btn in enumerate(self._char_keys):
|
||||||
assert chars is not None
|
assert chars is not None
|
||||||
@ -251,12 +302,33 @@ class OnScreenKeyboardWindow(ba.Window):
|
|||||||
self._mode = 'num'
|
self._mode = 'num'
|
||||||
self._refresh()
|
self._refresh()
|
||||||
|
|
||||||
|
def _emoji_mode(self) -> None:
|
||||||
|
ba.playsound(self._click_sound)
|
||||||
|
if self._mode in ['normal', 'caps', 'num']:
|
||||||
|
self._last_mode = self._mode
|
||||||
|
self._mode = 'emoji'
|
||||||
|
elif self._mode == 'emoji' or self._mode == 'emoji2':
|
||||||
|
self._mode = self._last_mode
|
||||||
|
self._refresh()
|
||||||
|
|
||||||
|
def _emoji_mode_2(self) -> None:
|
||||||
|
ba.playsound(self._click_sound)
|
||||||
|
if self._mode == 'emoji':
|
||||||
|
self._mode = 'emoji2'
|
||||||
|
elif self._mode == 'emoji2':
|
||||||
|
self._mode = 'emoji'
|
||||||
|
self._refresh()
|
||||||
|
|
||||||
def _shift(self) -> None:
|
def _shift(self) -> None:
|
||||||
ba.playsound(self._click_sound)
|
ba.playsound(self._click_sound)
|
||||||
if self._mode == 'normal':
|
if self._mode == 'normal':
|
||||||
self._mode = 'caps'
|
self._mode = 'caps'
|
||||||
|
self._double_press_shift = False
|
||||||
elif self._mode == 'caps':
|
elif self._mode == 'caps':
|
||||||
self._mode = 'normal'
|
if not self._double_press_shift:
|
||||||
|
self._double_press_shift = True
|
||||||
|
else:
|
||||||
|
self._mode = 'normal'
|
||||||
self._refresh()
|
self._refresh()
|
||||||
|
|
||||||
def _del(self) -> None:
|
def _del(self) -> None:
|
||||||
@ -273,8 +345,9 @@ class OnScreenKeyboardWindow(ba.Window):
|
|||||||
txt = cast(str, ba.textwidget(query=self._text_field))
|
txt = cast(str, ba.textwidget(query=self._text_field))
|
||||||
txt += char
|
txt += char
|
||||||
ba.textwidget(edit=self._text_field, text=txt)
|
ba.textwidget(edit=self._text_field, text=txt)
|
||||||
# if we were caps, go back
|
# if we were caps,
|
||||||
if self._mode == 'caps':
|
# go back only if not Shift is pressed twice
|
||||||
|
if self._mode == 'caps' and not self._double_press_shift:
|
||||||
self._mode = 'normal'
|
self._mode = 'normal'
|
||||||
self._refresh()
|
self._refresh()
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user