FoamyGuy / Blinka_Displayio_PyGameDisplay

Blinka makes her debut on the big screen! With this library you can use CircuitPython displayio code on PC and Raspberry Pi to output to a PyGame window instead of a hardware display connected to I2C or SPI. This makes it easy to to use displayio elements on HDMI and other large format screens.
MIT License
9 stars 9 forks source link

No examples or code work; what is hiding in plain sight? #18

Open reticulatingsplines opened 11 months ago

reticulatingsplines commented 11 months ago

Hey there,

I have to be missing something painfully obvious, because I've spent a few hours now meticulously crawling through this library and its dependencies with no answer to my own problem nor any idea how any of the examples would ever work.

Essentially, the first thing that the PyGameDisplay code does is set _INIT_SEQUENCE to None...

# imports

__version__ = "2.3.0"
__repo__ = "https://github.com/foamyguy/Foamyguy_CircuitPython_Blinka_Displayio_PyGameDisplay.git"

import time
import threading
from dataclasses import astuple
import displayio
import pygame
from PIL import Image

_INIT_SEQUENCE = None

...but when a PyGameDisplay instance is created, it initiates its parent class from the Blinka displayio library using this value, None, for _INIT_SEQUENCE...

super().__init__(None, _INIT_SEQUENCE, width=width, height=height, **kwargs)

...and then its parent class's init tries to evaluate the length of init_sequence, which is defined as our provided _INIT_SEQUENCE, i.e. None...

while i < len(init_sequence):
            cmd = init_sequence[i : i + 1]
            data_size = init_sequence[i + 1]
            delay = (data_size & DELAY) != 0
            data_size &= ~DELAY

...and you immediately get an exception. Am I not clued in to some need to edit a seemingly private variable, _INIT_SEQUENCE, in the PyGameDisplay library? I doubt it, so if this is really meant to be None, how has this code ever worked?

ry755 commented 11 months ago

Changing _INIT_SEQUENCE to an empty string ("") instead of None gets past the exception, but the PyGame window never shows up so something else still seems to be broken. When running the example in the README with this change applied, it exits immediately without ever creating the PyGame window.

FoamyGuy commented 11 months ago

@ry755 and @reticulatingsplines This library is incompatible with the newest versions of Blinka_DisplayIO.

For now, in order to use it you'll need to use version 0.11.1 or prior of Blinka_DisplayIO.

I created and merged #19 to add a warning to the readme about this, as well as update the requirements.txt file to indicate the compatible version.

bablokb commented 10 months ago

Has this already been uploaded to pypi? When I try a clean install, it still pulls in 1.1.0 of Blinka_DisplayIO.

FoamyGuy commented 10 months ago

@bablokb No, sorry. It appears I forgot to make the release when I merged that PR to pin the version.

I've made it just now: https://github.com/FoamyGuy/Blinka_Displayio_PyGameDisplay/releases/tag/2.4.0 I believe that should result in the new one being used by default on a pip install. You may need to explicitly uninstall the newer version of Blinka_DisplayIO that it would have installed before this change, I'm not certain.

Let me know if you have further issues.

I'm hoping to swing back around and take another crack at getting this working with the newer Blinka_DisplayIO soon as well but can't promise any solid timeline ATM.

If anyone reading this is interested in helping out It'd be much appreciated, knowledge of pygame and/or color profile manipulation like RGB565 are the most relevant skill sets but I'm happy to get help from anyone really.

bablokb commented 10 months ago

This fixes it. I now have issues with importing terminalio, but this might be related to PIL. Too late to investigate today.

bablokb commented 10 months ago

Pillow 10.1 is the culprit, 9.4 works (there were some changes to ImageFont.load_default()). The current version of Blinka_DisplayIO has a fix for that (in fontio.py, loading a specific font), but the old version uses load_default() and fails. The old version would need a change to the requirements-file I suppose, but there isn't even a branch for the old version so I am not sure if this is feasible.

Would it be possible that this package already pulls in the correct PIL-version before Blinka_DisplayIO just takes the newest one?

tyeth commented 9 months ago

Hey, new to pillow and PIL and PyGame, and wondered about the missing terminalio, but also vectorio and bitmaptools. Should I file a separate issue?

FoamyGuy commented 9 months ago

@tyeth Yes you can open an issue if you'd like. I believe Blinka_DisplayIO does not currently have implementations for vectorio or bitmaptools if that is the case I think they would need to be implemented in there and then could be used by this library.

bablokb commented 9 months ago

I always use this project here to prototype my UIs and I also miss vectorio (which is far more efficient than adafruit_display_shapes). But vectorio is implemented in C, while Blinka_DisplayIO is pure Python.

My "solution" was to clone adafruit_display_shapes.rect.Rect to vectorio.Rectangle and just change the interface to match the orginal. I never created a pull-request for Blinka, because I did not bother to port Circle and I was not sure if a PR would be accepted anyhow (it does add dependencies to Blinka that are not currently there).

tyeth commented 9 months ago

Thanks for your inspiration @bablokb , I had a quick play and got my circle displayio_shapes working, although my old (archaic?) colour changing code (setting circle.color_index = 6) no longer worked and I'm new to using fill / getting my weird palette working with the correct background colour, but was a pleasant relief to see the thing running the same code and outputting similar output visually to my real sensor devices. Need to resolve my fonts, palettes n pixel_shaders, and the margins/spacing (seemed weird when running the percentage bar demo with adjusted sizes, in addition to running my other code but mine may be fonts and lack of terminal which usually occupies 50% of screen).

FoamyGuy commented 9 months ago

@bablokb and @tyeth https://github.com/adafruit/Adafruit_Blinka_Displayio/pull/122 is open in Blinka DisplayIO repo now that adds vectorio implementation for it which I've tested successfully with this library.