Skip to content

Commit 19c15ba

Browse files
Try to fix layout switching
1 parent 189d4a8 commit 19c15ba

File tree

3 files changed

+368
-9
lines changed

3 files changed

+368
-9
lines changed

internal_filesystem/lib/mpos/ui/keyboard.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,13 @@ def __init__(self, parent):
6262
# Configure layouts
6363
self._setup_layouts()
6464

65-
# Set default mode to lowercase
65+
# Initialize ALL keyboard mode maps (prevents LVGL from using default maps)
6666
self._keyboard.set_map(self.MODE_LOWERCASE, self._lowercase_map, self._lowercase_ctrl)
67+
self._keyboard.set_map(self.MODE_UPPERCASE, self._uppercase_map, self._uppercase_ctrl)
68+
self._keyboard.set_map(self.MODE_NUMBERS, self._numbers_map, self._numbers_ctrl)
69+
self._keyboard.set_map(self.MODE_SPECIALS, self._specials_map, self._specials_ctrl)
70+
71+
# Set default mode to lowercase
6772
self._keyboard.set_mode(self.MODE_LOWERCASE)
6873

6974
# Add event handler for custom behavior
@@ -134,6 +139,11 @@ def _handle_events(self, event):
134139
if text is None:
135140
return
136141

142+
# Stop event propagation to prevent LVGL's default mode-switching behavior
143+
# This is critical to prevent LVGL from switching to its default TEXT_LOWER,
144+
# TEXT_UPPER, NUMBER modes when it sees mode-switching buttons
145+
event.stop_processing()
146+
137147
# Get current textarea content (from our own reference, not LVGL's)
138148
ta = self._textarea
139149
if not ta:
@@ -149,26 +159,22 @@ def _handle_events(self, event):
149159

150160
elif text == lv.SYMBOL.UP:
151161
# Switch to uppercase
152-
self._keyboard.set_map(self.MODE_UPPERCASE, self._uppercase_map, self._uppercase_ctrl)
153-
self._keyboard.set_mode(self.MODE_UPPERCASE)
162+
self.set_mode(self.MODE_UPPERCASE)
154163
return # Don't modify text
155164

156165
elif text == lv.SYMBOL.DOWN or text == self.LABEL_LETTERS:
157166
# Switch to lowercase
158-
self._keyboard.set_map(self.MODE_LOWERCASE, self._lowercase_map, self._lowercase_ctrl)
159-
self._keyboard.set_mode(self.MODE_LOWERCASE)
167+
self.set_mode(self.MODE_LOWERCASE)
160168
return # Don't modify text
161169

162170
elif text == self.LABEL_NUMBERS_SPECIALS:
163171
# Switch to numbers/specials
164-
self._keyboard.set_map(self.MODE_NUMBERS, self._numbers_map, self._numbers_ctrl)
165-
self._keyboard.set_mode(self.MODE_NUMBERS)
172+
self.set_mode(self.MODE_NUMBERS)
166173
return # Don't modify text
167174

168175
elif text == self.LABEL_SPECIALS:
169176
# Switch to additional specials
170-
self._keyboard.set_map(self.MODE_SPECIALS, self._specials_map, self._specials_ctrl)
171-
self._keyboard.set_mode(self.MODE_SPECIALS)
177+
self.set_mode(self.MODE_SPECIALS)
172178
return # Don't modify text
173179

174180
elif text == self.LABEL_SPACE:

tests/manual_test_abc_button.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
"""
2+
Manual test for the "abc" button bug.
3+
4+
This test creates a keyboard and lets you manually switch modes to observe the bug.
5+
6+
Run with: ./scripts/run_desktop.sh tests/manual_test_abc_button.py
7+
8+
Steps to reproduce the bug:
9+
1. Keyboard starts in lowercase mode
10+
2. Click "?123" button to switch to numbers mode
11+
3. Click "abc" button to switch back to lowercase
12+
4. OBSERVE: Does it show "?123" (correct) or "1#" (wrong/default LVGL)?
13+
"""
14+
15+
import lvgl as lv
16+
from mpos.ui.keyboard import MposKeyboard
17+
18+
# Get active screen
19+
screen = lv.screen_active()
20+
screen.clean()
21+
22+
# Create title
23+
title = lv.label(screen)
24+
title.set_text("ABC Button Test")
25+
title.align(lv.ALIGN.TOP_MID, 0, 5)
26+
27+
# Create instructions
28+
instructions = lv.label(screen)
29+
instructions.set_text(
30+
"1. Start in lowercase (has ?123 button)\n"
31+
"2. Click '?123' to switch to numbers\n"
32+
"3. Click 'abc' to switch back\n"
33+
"4. CHECK: Do you see '?123' or '1#'?\n"
34+
" - '?123' = CORRECT (custom keyboard)\n"
35+
" - '1#' = BUG (default LVGL keyboard)"
36+
)
37+
instructions.set_style_text_align(lv.TEXT_ALIGN.LEFT, 0)
38+
instructions.align(lv.ALIGN.TOP_LEFT, 10, 30)
39+
40+
# Create textarea
41+
textarea = lv.textarea(screen)
42+
textarea.set_size(280, 30)
43+
textarea.set_one_line(True)
44+
textarea.align(lv.ALIGN.TOP_MID, 0, 120)
45+
textarea.set_placeholder_text("Type here...")
46+
47+
# Create keyboard
48+
keyboard = MposKeyboard(screen)
49+
keyboard.set_textarea(textarea)
50+
keyboard.align(lv.ALIGN.BOTTOM_MID, 0, 0)
51+
52+
print("\n" + "="*60)
53+
print("ABC Button Bug Test")
54+
print("="*60)
55+
print("Instructions:")
56+
print("1. Keyboard starts in LOWERCASE mode")
57+
print(" - Look for '?123' button (bottom left area)")
58+
print("2. Click '?123' to switch to NUMBERS mode")
59+
print(" - Should show numbers 1,2,3, etc.")
60+
print(" - Should have 'abc' button (bottom left)")
61+
print("3. Click 'abc' to return to lowercase")
62+
print("4. CRITICAL CHECK:")
63+
print(" - If you see '?123' button → CORRECT (custom keyboard)")
64+
print(" - If you see '1#' button → BUG (default LVGL keyboard)")
65+
print("="*60 + "\n")

0 commit comments

Comments
 (0)