Skip to content

Commit 25b3bc0

Browse files
Fix all keyboard tests
1 parent 1c500a0 commit 25b3bc0

7 files changed

+57
-262
lines changed

internal_filesystem/lib/mpos/ui/keyboard.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
keyboard.set_textarea(my_textarea)
1414
keyboard.align(lv.ALIGN.BOTTOM_MID, 0, 0)
1515
16-
# Or use factory function for drop-in replacement
17-
from mpos.ui.keyboard import create_keyboard
18-
keyboard = create_keyboard(parent_obj, custom=True)
1916
"""
2017

2118
import lvgl as lv
@@ -41,10 +38,10 @@ class MposKeyboard:
4138

4239
# Keyboard modes - use USER modes for our API
4340
# We'll also register to standard modes to catch LVGL's internal switches
44-
CUSTOM_MODE_LOWERCASE = lv.keyboard.MODE.USER_1
45-
CUSTOM_MODE_UPPERCASE = lv.keyboard.MODE.USER_2
46-
CUSTOM_MODE_NUMBERS = lv.keyboard.MODE.USER_3
47-
CUSTOM_MODE_SPECIALS = lv.keyboard.MODE.USER_4
41+
MODE_LOWERCASE = lv.keyboard.MODE.USER_1
42+
MODE_UPPERCASE = lv.keyboard.MODE.USER_2
43+
MODE_NUMBERS = lv.keyboard.MODE.USER_3
44+
MODE_SPECIALS = lv.keyboard.MODE.USER_4
4845

4946
# Lowercase letters
5047
_lowercase_map = [
@@ -84,10 +81,10 @@ class MposKeyboard:
8481

8582
# Map modes to their layouts
8683
mode_info = {
87-
CUSTOM_MODE_LOWERCASE: (_lowercase_map, _lowercase_ctrl),
88-
CUSTOM_MODE_UPPERCASE: (_uppercase_map, _uppercase_ctrl),
89-
CUSTOM_MODE_NUMBERS: (_numbers_map, _numbers_ctrl),
90-
CUSTOM_MODE_SPECIALS: (_specials_map, _specials_ctrl),
84+
MODE_LOWERCASE: (_lowercase_map, _lowercase_ctrl),
85+
MODE_UPPERCASE: (_uppercase_map, _uppercase_ctrl),
86+
MODE_NUMBERS: (_numbers_map, _numbers_ctrl),
87+
MODE_SPECIALS: (_specials_map, _specials_ctrl),
9188
}
9289

9390
_current_mode = None
@@ -99,7 +96,7 @@ def __init__(self, parent):
9996
# Store textarea reference (we DON'T pass it to LVGL to avoid double-typing)
10097
self._textarea = None
10198

102-
self.set_mode(self.CUSTOM_MODE_LOWERCASE)
99+
self.set_mode(self.MODE_LOWERCASE)
103100

104101
self._keyboard.add_event_cb(self._handle_events, lv.EVENT.ALL, None)
105102
# Apply theme fix for light mode visibility
@@ -141,19 +138,19 @@ def _handle_events(self, event):
141138
new_text = current_text[:-1]
142139
elif text == lv.SYMBOL.UP:
143140
# Switch to uppercase
144-
self.set_mode(self.CUSTOM_MODE_UPPERCASE)
141+
self.set_mode(self.MODE_UPPERCASE)
145142
return # Don't modify text
146143
elif text == lv.SYMBOL.DOWN or text == self.LABEL_LETTERS:
147144
# Switch to lowercase
148-
self.set_mode(self.CUSTOM_MODE_LOWERCASE)
145+
self.set_mode(self.MODE_LOWERCASE)
149146
return # Don't modify text
150147
elif text == self.LABEL_NUMBERS_SPECIALS:
151148
# Switch to numbers/specials
152-
self.set_mode(self.CUSTOM_MODE_NUMBERS)
149+
self.set_mode(self.MODE_NUMBERS)
153150
return # Don't modify text
154151
elif text == self.LABEL_SPECIALS:
155152
# Switch to additional specials
156-
self.set_mode(self.CUSTOM_MODE_SPECIALS)
153+
self.set_mode(self.MODE_SPECIALS)
157154
return # Don't modify text
158155
elif text == self.LABEL_SPACE:
159156
# Space bar

tests/test_graphical_custom_keyboard.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import lvgl as lv
1414
import sys
1515
import os
16-
from mpos.ui.keyboard import MposKeyboard, create_keyboard
16+
from mpos.ui.keyboard import MposKeyboard
1717
from graphical_test_helper import (
1818
wait_for_render,
1919
capture_screenshot,
@@ -86,18 +86,17 @@ def _simulate_button_press(self, keyboard, button_index):
8686
Returns:
8787
str: Text of the pressed button
8888
"""
89-
lvgl_keyboard = keyboard.get_lvgl_obj()
9089

9190
# Get button text before pressing
92-
button_text = lvgl_keyboard.get_button_text(button_index)
91+
button_text = keyboard.get_button_text(button_index)
9392

9493
# Simulate button press by setting it as selected and sending event
9594
# Note: This is a bit of a hack since we can't directly click in tests
9695
# We'll trigger the VALUE_CHANGED event which is what happens on click
9796

9897
# The keyboard has an internal handler that responds to VALUE_CHANGED
9998
# We need to manually trigger it
100-
lvgl_keyboard.send_event(lv.EVENT.VALUE_CHANGED, None)
99+
keyboard.send_event(lv.EVENT.VALUE_CHANGED, None)
101100

102101
wait_for_render(5)
103102

@@ -217,8 +216,7 @@ def test_keyboard_visibility_light_mode(self):
217216
screen, keyboard, textarea = self._create_test_keyboard_scene()
218217

219218
# Get button background color
220-
lvgl_keyboard = keyboard.get_lvgl_obj()
221-
bg_color = lvgl_keyboard.get_style_bg_color(lv.PART.ITEMS)
219+
bg_color = keyboard.get_style_bg_color(lv.PART.ITEMS)
222220

223221
# Extract RGB (similar to keyboard styling test)
224222
try:
@@ -273,7 +271,7 @@ def test_keyboard_with_standard_comparison(self):
273271
ta_standard.set_one_line(True)
274272

275273
# Create standard keyboard (hidden initially)
276-
keyboard_standard = create_keyboard(screen, custom=False)
274+
keyboard_standard = MposKeyboard(screen)
277275
keyboard_standard.set_textarea(ta_standard)
278276
keyboard_standard.align(lv.ALIGN.BOTTOM_MID, 0, 0)
279277
keyboard_standard.set_style_min_height(145, 0)
@@ -301,7 +299,7 @@ def test_keyboard_with_standard_comparison(self):
301299
ta_custom.set_placeholder_text("Custom")
302300
ta_custom.set_one_line(True)
303301

304-
keyboard_custom = create_keyboard(screen2, custom=True)
302+
keyboard_custom = MposKeyboard(screen2)
305303
keyboard_custom.set_textarea(ta_custom)
306304
keyboard_custom.align(lv.ALIGN.BOTTOM_MID, 0, 0)
307305

tests/test_graphical_custom_keyboard_basic.py

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
import unittest
1212
import lvgl as lv
13-
from mpos.ui.keyboard import MposKeyboard, create_keyboard
13+
from mpos.ui.keyboard import MposKeyboard
1414

1515

1616
class TestMposKeyboard(unittest.TestCase):
@@ -44,34 +44,9 @@ def test_keyboard_creation(self):
4444

4545
# Verify keyboard exists
4646
self.assertIsNotNone(keyboard)
47-
self.assertIsNotNone(keyboard.get_lvgl_obj())
4847

4948
print("Keyboard created successfully")
5049

51-
def test_keyboard_factory_custom(self):
52-
"""Test factory function creates custom keyboard."""
53-
print("Testing factory function with custom=True...")
54-
55-
keyboard = create_keyboard(self.screen, custom=True)
56-
57-
# Verify it's a MposKeyboard instance
58-
self.assertIsInstance(keyboard, MposKeyboard)
59-
60-
print("Factory created MposKeyboard successfully")
61-
62-
def test_keyboard_factory_standard(self):
63-
"""Test factory function creates standard keyboard."""
64-
print("Testing factory function with custom=False...")
65-
66-
keyboard = create_keyboard(self.screen, custom=False)
67-
68-
# Verify it's an LVGL keyboard (not MposKeyboard)
69-
self.assertFalse(isinstance(keyboard, MposKeyboard),
70-
"Factory with custom=False should not create MposKeyboard")
71-
# It should be an lv.keyboard instance
72-
self.assertEqual(type(keyboard).__name__, 'keyboard')
73-
74-
print("Factory created standard keyboard successfully")
7550

7651
def test_set_textarea(self):
7752
"""Test setting textarea association."""

tests/test_graphical_keyboard_abc_click_bug.py

Lines changed: 0 additions & 162 deletions
This file was deleted.

0 commit comments

Comments
 (0)