Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
rm-hull committed Jan 27, 2017
1 parent a43d154 commit 2c1bea6
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
8 changes: 3 additions & 5 deletions luma/led_matrix/legacy.py
Expand Up @@ -1382,11 +1382,9 @@ def text(draw, xy, text, fill=None, font=None):
x += 1


def show_message(device, msg, y_offset=0, fill=None, font=None):
def show_message(device, msg, y_offset=0, delay=0.03, fill=None, font=None):
font = font or DEFAULT_FONT
with canvas(device) as draw:
w, h = textsize(msg, font)

w, h = textsize(msg, font)
x = device.width
virtual = viewport(device, width=w + x + x, height=h)

Expand All @@ -1396,5 +1394,5 @@ def show_message(device, msg, y_offset=0, fill=None, font=None):
i = 0
while i < w + x:
virtual.set_position((i, 0))
time.sleep(delay)
i += 1
time.sleep(0.03)
Binary file added tests/reference/show_message.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 37 additions & 1 deletion tests/test_legacy.py
Expand Up @@ -4,12 +4,23 @@
# See LICENSE.rst for details.


import hashlib
import os.path
from tempfile import NamedTemporaryFile
from PIL import Image

try:
from unittest.mock import call, Mock
except ImportError:
from mock import call, Mock

from luma.led_matrix.legacy import text, textsize, proportional, CP437_FONT, LCD_FONT
from luma.core.emulator import gifanim
from luma.led_matrix.legacy import text, show_message, textsize, proportional, CP437_FONT, LCD_FONT


def md5(fname):
with open(fname, 'rb') as fp:
return hashlib.md5(fp.read()).hexdigest()


def test_textsize():
Expand Down Expand Up @@ -39,3 +50,28 @@ def test_text_char():
call((5, 8), fill='white'),
call((6, 8), fill='white')
])


def test_show_message():
reference = os.path.abspath(os.path.join(
os.path.dirname(__file__),
'reference',
'show_message.gif'))

fname = NamedTemporaryFile(suffix=".gif").name
device = gifanim(width=40, height=8, transform="none", filename=fname)

show_message(device, "Hello world!", delay=0, fill="white")

device.write_animation()

ref = Image.open(reference)
act = Image.open(fname)

try:
while True:
assert ref == act
ref.seek(ref.tell() + 1)
act.seek(act.tell() + 1)
except EOFError:
pass

0 comments on commit 2c1bea6

Please sign in to comment.