Skip to content

ValueError: object not in sequence #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
DJDevon3 opened this issue Jan 7, 2024 · 3 comments
Closed

ValueError: object not in sequence #1

DJDevon3 opened this issue Jan 7, 2024 · 3 comments

Comments

@DJDevon3
Copy link
Contributor

DJDevon3 commented Jan 7, 2024

Circuit Python 9.2.7 (maybe I should upgrade?) Adafruit ESP32-S3 Feather with 3.5" TFT Featherwing

import board
import displayio
import digitalio
import terminalio
from adafruit_display_text import label
from adafruit_bitmap_font import bitmap_font
from adafruit_hx8357 import HX8357
import adafruit_stmpe610
from soft_keyboard.soft_keyboard import SoftKeyboard, PRINTABLE_CHARACTERS

# 3.5" TFT Featherwing is 480x320
displayio.release_displays()
DISPLAY_WIDTH = 480
DISPLAY_HEIGHT = 320

# Initialize TFT Display
spi = board.SPI()
tft_cs = board.D9
tft_dc = board.D10
display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs)
display = HX8357(display_bus, width=DISPLAY_WIDTH, height=DISPLAY_HEIGHT)
display.rotation = 0
_touch_flip = (False, True)

# Initialize 3.5" TFT Featherwing Touchscreen
ts_cs_pin = digitalio.DigitalInOut(board.D6)
touchscreen = adafruit_stmpe610.Adafruit_STMPE610_SPI(
    board.SPI(),
    ts_cs_pin,
    calibration=((231, 3703), (287, 3787)),
    size=(display.width, display.height),
    disp_rotation=display.rotation,
    touch_flip=_touch_flip,
)

forkawesome_font = bitmap_font.load_font("/fonts/forkawesome-12.pcf")

input_lbl = label.Label(terminalio.FONT, scale=2, text="", color=0xffffff, background_color=0x00000)
input_lbl.x = 10
input_lbl.y = 10

# Create groups
main_group = displayio.Group()
main_group.append(input_lbl)

display.root_group = main_group

soft_kbd = SoftKeyboard(2, 100, DISPLAY_WIDTH-2, DISPLAY_HEIGHT-100, terminalio.FONT, forkawesome_font)

main_group.append(soft_kbd)

print(f"size: {soft_kbd.width}, {soft_kbd.height}")
print(f"cell size: {soft_kbd.layout.cell_size_pixels}")

while True:
    p = touchscreen.touch_point

    # print(p)
    key_value = soft_kbd.check_touches(p)
    if key_value in PRINTABLE_CHARACTERS:
        input_lbl.text += key_value
    elif key_value == 42:  # 0x2a backspace key
        input_lbl.text = input_lbl.text[:-1]
Traceback (most recent call last):
  File "code.py", line 53, in <module>
  File "/lib/soft_keyboard/soft_keyboard.py", line 90, in __init__
  File "/lib/adafruit_displayio_layout/layouts/grid_layout.py", line 116, in layout_cells
  File "/lib/adafruit_displayio_layout/layouts/grid_layout.py", line 307, in _layout_cells
ValueError: object not in sequence

It's unable to get past soft_kbd = SoftKeyboard(2, 100, DISPLAY_WIDTH-2, DISPLAY_HEIGHT-100, terminalio.FONT, forkawesome_font)

Using zip download from your CircuitPython_SoftKeyboard repo as of about 5 hours ago.

Using PR #92 you made for grid_layout.py To my knowledge that's the most recent commit of grid_layout.

I attempted to integrate it into feather weather and got that error... and slimmed it all the way down to this point and still can't past the object not in sequence.

@FoamyGuy
Copy link
Owner

FoamyGuy commented Jan 16, 2024

@DJDevon3 It appears that I mistakenly left an extra divider line removal routine in GridLayout. Likely when it changed from displayio.Shape to vectorio.Rectangle for drawing the lines.

It turns out that my pyportal actually had an older version of GridLayout on it while I was working on this library and I did not realize that. The version I had didn't contain the same problem so it went unnoticed.

I've added a new commit adafruit/Adafruit_CircuitPython_DisplayIO_Layout@baeccd1 to the branch from #92 which addresses that problem by removing the extra divider line removal.

You can download the updated zip from that branch page here: https://github.com/FoamyGuy/Adafruit_CircuitPython_DisplayIO_Layout/tree/gridlayout_cell_contains

This version seems to work with version 8.2.7 as well as the other versions I tested. On a Feather S3 with 3.5" TFT Wing.

@DJDevon3
Copy link
Contributor Author

That did the trick. Have it working with the json file now. Shift works well too. Can use your mode switches for adding special characters and more features. I'll help tidy up the simpletest example too so you can have fun with 1D-Chomper this week. Thank you!

@DJDevon3
Copy link
Contributor Author

After using the json method for a day discovered that the performance difference I saw on your stream is coming from reading and enumerating through the json file itself. I'm seeing the same slower grid line loading now too. Using hard coded label appends within code.py is much faster but json is far more convenient especially for multiple custom layouts. Will have to remain a cost for convenience but would like to note that a performance gain is possible with hard coded labels vs json loads (and enough psram). Your built-in debouncing also now prevents double key presses which makes the user experience more enjoyable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants