adafruit / Adafruit_CircuitPython_Display_Text

Library to display text using displayio
MIT License
57 stars 38 forks source link

Update scale to remove self._scale that conflicts with Blinka #117

Closed kmatch98 closed 3 years ago

kmatch98 commented 3 years ago

Removing usage of self._scale in bitmap_label that is causing conflict with Blinka displayio.Group library's internal variable with the same name.

I verified the code on a PyPortal and also on Blinka.

This is targeted to resolve this issue on Adafruit_Blinka_Displayio https://github.com/adafruit/Adafruit_Blinka_Displayio/issues/45.

Blinka: Currently released version

image

Blinka: Version with this PR

image

Test code with Blinka and pygamedisplay:

import sys

sys.path.append("./lib")

import displayio
import time
import random
import terminalio
from adafruit_blinka import board
from blinka_displayio_pygamedisplay import PyGameDisplay

# The key here is "auto_refresh=False". Failing to do so will create a new thread
# for the rendering, and macOS (or the Python implementation for it) can only be
# performed on the main (UI) thread.
display = PyGameDisplay(width=320, height=240, auto_refresh=False)

# This is a trial of the switch_round_horizontal
# for use on the PyPortal
#
#from adafruit_display_text import label
from adafruit_display_text import bitmap_label as label

# Make the display context
splash = displayio.Group(max_size=10)
display.show(splash)

WIDTH = 320
HEIGHT = 240

# Draw a black background
bg_bitmap = displayio.Bitmap(WIDTH, HEIGHT , 1)
bg_palette = displayio.Palette(1)
bg_palette[0] = 0x000000
splash.append(displayio.TileGrid(bg_bitmap, pixel_shader=bg_palette))

test_label1 = label.Label(terminalio.FONT, text="Scale", scale=1, color=0xFFFFFF, x=8, y=8)
print("Test1 : before append to splash")
print(f"  Scale {test_label1.scale}")
splash.append(test_label1)
print("Test1 : after append to splash")
print(f"  Scale {test_label1.scale}")
print("test_label1.bounding_box: {}".format(test_label1.bounding_box))

print()
test_label2 = label.Label(terminalio.FONT, text="Scale", scale=2, color=0xFFFFFF, x=8, y=38)
print("Test2 : before append to splash")
print(f"  Scale {test_label2.scale}")
splash.append(test_label2)
print("Test2 : after append to splash")
print(f"  Scale {test_label2.scale}")
print("test_label2.bounding_box: {}".format(test_label2.bounding_box))

print()
test_label3 = label.Label(terminalio.FONT, text="Scale", scale=3, color=0xFFFFFF, x=8, y=88)
print("Test3 : before append to splash")
print(f"  Scale {test_label3.scale}")
splash.append(test_label3)
print("Test3 : after append to splash")
print(f"  Scale {test_label3.scale}")
print("test_label3.bounding_box: {}".format(test_label3.bounding_box))

while display.running:
    display.refresh()
lesamouraipourpre commented 3 years ago

Using a slightly modified script (attached) which also tests anchored_position and anchor_point, I've verified the code on PyPortal and my SH1107 OLED. test_bitmap_label.py

screenshot_pygame screenshot_oled

kmatch98 commented 3 years ago

@lesamouraipourpre Looks like it works fine. (But initially it had me confused with the smaller sized display in the second photo.) Thanks for the testing and for the earlier PR on label.py!