def displayflights(topline, bottomline):
    device.contrast(0)
    if device.height >= 16:
        font = make_font("code2000.ttf", 12)
    else:
        font = make_font("pixelmix.ttf", 8)

    image_composition = ImageComposition(device)

    try:
        #	    while True:
        synchroniser = Synchroniser()
        ci_top = ComposableImage(TextImage(device, topline, font).image,
                                 position=(0, 1))
        ci_bottom = ComposableImage(TextImage(device, bottomline, font).image,
                                    position=(0, 16))
        closest = Scroller(image_composition, ci_top, 10, synchroniser)
        furthest = Scroller(image_composition, ci_bottom, 10, synchroniser)
        cycles = 0

        while cycles < 3:
            closest.tick()
            furthest.tick()
            time.sleep(0.025)
            cycles = furthest.get_cycles()
            with canvas(device, background=image_composition()) as draw:
                image_composition.refresh()
#	                    draw.rectangle(device.bounding_box, outline="white")

#	            del closest
#	            del furthest

    except KeyboardInterrupt:
        pass
Exemple #2
0
def test_refresh():
    ic = ImageComposition(dummy())
    ic_img_before = list(ic().getdata())
    img = Image.new("RGB", (25, 25))
    draw = ImageDraw.Draw(img)
    draw.rectangle((10, 10, 20, 20), outline="white")
    del draw
    ci = ComposableImage(img)
    ic.add_image(ci)
    ic.refresh()
    assert ic_img_before != list(ic().getdata())
Exemple #3
0
## Main
## Connects to the display and makes it update forever until ended by the user with a ctrl-c
###
DisplayParser = cmdline.create_parser(
    description='Dynamically connect to either a vritual or physical display.')
device = cmdline.create_device(
    DisplayParser.parse_args([
        '--display',
        str(Args.Display), '--interface', 'spi', '--width', '256', '--rotate',
        str(Args.Rotation), '--max-frames',
        str(Args.maxframes)
    ]))
if Args.Display == 'gifanim':
    device._filename = str(Args.filename)

image_composition = ImageComposition(device)
board = boardFixed(image_composition, Args.Delay, device)
FontTime = ImageFont.truetype(
    "%s/resources/time.otf" % (os.path.dirname(
        os.path.abspath(inspect.getfile(inspect.currentframe())))), 16)
device.contrast(255)
energyMode = "normal"
StartUpDate = datetime.now().date()


# Draws the clock and tells the rest of the display next frame wanted.
def display():
    board.tick()
    msgTime = str(datetime.now().strftime("%H:%M" if (
        Args.TimeFormat == 24) else "%I:%M"))
    with canvas(device, background=image_composition()) as draw:
Exemple #4
0
def test_image_remove_image_none():
    ic = ImageComposition(dummy())
    with pytest.raises(AssertionError):
        ic.remove_image(None)
Exemple #5
0
def test_image_composition_ctor():
    ic = ImageComposition(dummy())
    assert isinstance(ic(), PIL.Image.Image)
Exemple #6
0
def test_refresh_no_images():
    ic = ImageComposition(dummy())
    ic_img_before = list(ic().getdata())
    ic.refresh()
    assert ic_img_before == list(ic().getdata())
Exemple #7
0
def test_image_count():
    ic = ImageComposition(dummy())
    img1 = ComposableImage(Image.new("RGB", (1, 1)))
    img2 = ComposableImage(Image.new("RGB", (1, 1)))
    img3 = ComposableImage(Image.new("RGB", (1, 1)))
    ic.add_image(img1)
    ic.add_image(img2)
    ic.add_image(img3)
    assert len(ic.composed_images) == 3
    ic.remove_image(img3)
    assert len(ic.composed_images) == 2
    ic.remove_image(img2)
    assert len(ic.composed_images) == 1
    ic.remove_image(img1)
    assert len(ic.composed_images) == 0
def make_font(name, size):
    font_path = os.path.abspath(
        os.path.join(os.path.dirname(__file__), 'fonts', name))
    return ImageFont.truetype(font_path, size)


# ------- main

device = get_device()

if device.height >= 16:
    font = make_font("code2000.ttf", 12)
else:
    font = make_font("pixelmix.ttf", 8)

image_composition = ImageComposition(device)

try:
    while True:
        for title in titles:
            synchroniser = Synchroniser()
            ci_song = ComposableImage(TextImage(device, title[0], font).image,
                                      position=(0, 1))
            ci_artist = ComposableImage(TextImage(device, title[1],
                                                  font).image,
                                        position=(0, 30))
            song = Scroller(image_composition, ci_song, 100, synchroniser)
            artist = Scroller(image_composition, ci_artist, 100, synchroniser)
            cycles = 0

            while cycles < 3: