def drawBlankSignage(device, width, height, departureStation):
    global stationRenderCount, pauseCount

    with canvas(device) as draw:
        welcomeSize = draw.textsize("Welcome to", fontBold)

    with canvas(device) as draw:
        stationSize = draw.textsize(departureStation, fontBold)

    device.clear()

    virtualViewport = viewport(device, width=width, height=height)

    rowOne = snapshot(width,
                      10,
                      renderWelcomeTo((width - welcomeSize[0]) / 2),
                      interval=config["refreshTime"])
    rowTwo = snapshot(width,
                      10,
                      renderDepartureStation(departureStation,
                                             (width - stationSize[0]) / 2),
                      interval=config["refreshTime"])
    rowThree = snapshot(width, 10, renderDots, interval=config["refreshTime"])
    rowTime = hotspot(width, 14, renderTime)

    if len(virtualViewport._hotspots) > 0:
        for vhotspot, xy in virtualViewport._hotspots:
            virtualViewport.remove_hotspot(vhotspot, xy)

    virtualViewport.add_hotspot(rowOne, (0, 0))
    virtualViewport.add_hotspot(rowTwo, (0, 12))
    virtualViewport.add_hotspot(rowThree, (0, 24))
    virtualViewport.add_hotspot(rowTime, (0, 50))

    return virtualViewport
Esempio n. 2
0
def test_viewport_hotspot():
    img_path = get_reference_image('hotspot.png')

    with open(img_path, 'rb') as p:
        reference = Image.open(p)
        device = dummy()
        virtual = viewport(device, 200, 200)

        def draw_fn(draw, width, height):
            baseline_data.primitives(device, draw)

        widget = hotspot(device.width, device.height, draw_fn)

        virtual.add_hotspot(widget, (19, 56))
        virtual.set_position((28, 30))
        virtual.remove_hotspot(widget, (19, 56))

        assert_identical_image(reference, device.image, img_path)
Esempio n. 3
0
def test_viewport_dithering():
    img_path = get_reference_image('hotspot_dither.png')

    with open(img_path, 'rb') as p:
        reference = Image.open(p)
        device = dummy(mode="1")
        virtual = viewport(device, 200, 200, mode='RGBA', dither=True)

        def draw_fn(draw, width, height):
            draw.rectangle((0, 0, width / 2, height / 2), fill="red")
            draw.rectangle((width / 2, 0, width, height / 2), fill="yellow")
            draw.rectangle((0, height / 2, width / 2, height), fill="blue")
            draw.rectangle((width / 2, height / 2, width, height),
                           fill="white")

        widget = hotspot(device.width, device.height, draw_fn)

        virtual.add_hotspot(widget, (19, 56))
        virtual.set_position((28, 30))
        virtual.remove_hotspot(widget, (19, 56))

        assert_identical_image(reference, device.image, img_path)
def drawSignage(device, width, height, data):
    global stationRenderCount, pauseCount

    device.clear()

    virtualViewport = viewport(device, width=width, height=height)

    status = "Exp 00:00"
    callingAt = "Calling at:"

    departures, firstDepartureDestinations, departureStation = data

    with canvas(device) as draw:
        w, h = draw.textsize(callingAt, font)

    callingWidth = w
    width = virtualViewport.width

    # First measure the text size
    with canvas(device) as draw:
        w, h = draw.textsize(status, font)
        pw, ph = draw.textsize("Plat 88", font)

    rowOneA = snapshot(width - w - pw - 5,
                       10,
                       renderDestination(departures[0], fontBold),
                       interval=config["refreshTime"])
    rowOneB = snapshot(w, 10, renderServiceStatus(departures[0]), interval=10)
    rowOneC = snapshot(pw,
                       10,
                       renderPlatform(departures[0]),
                       interval=config["refreshTime"])
    rowTwoA = snapshot(callingWidth,
                       10,
                       renderCallingAt,
                       interval=config["refreshTime"])
    rowTwoB = snapshot(width - callingWidth,
                       10,
                       renderStations(", ".join(firstDepartureDestinations)),
                       interval=0.1)

    if (len(departures) > 1):
        rowThreeA = snapshot(width - w - pw,
                             10,
                             renderDestination(departures[1], font),
                             interval=config["refreshTime"])
        rowThreeB = snapshot(w,
                             10,
                             renderServiceStatus(departures[1]),
                             interval=config["refreshTime"])
        rowThreeC = snapshot(pw,
                             10,
                             renderPlatform(departures[1]),
                             interval=config["refreshTime"])

    if (len(departures) > 2):
        rowFourA = snapshot(width - w - pw,
                            10,
                            renderDestination(departures[2], font),
                            interval=10)
        rowFourB = snapshot(w,
                            10,
                            renderServiceStatus(departures[2]),
                            interval=10)
        rowFourC = snapshot(pw,
                            10,
                            renderPlatform(departures[2]),
                            interval=config["refreshTime"])

    rowTime = hotspot(width, 14, renderTime)

    if len(virtualViewport._hotspots) > 0:
        for vhotspot, xy in virtualViewport._hotspots:
            virtualViewport.remove_hotspot(vhotspot, xy)

    stationRenderCount = 0
    pauseCount = 0

    virtualViewport.add_hotspot(rowOneA, (0, 0))
    virtualViewport.add_hotspot(rowOneB, (width - w, 0))
    virtualViewport.add_hotspot(rowOneC, (width - w - pw, 0))
    virtualViewport.add_hotspot(rowTwoA, (0, 12))
    virtualViewport.add_hotspot(rowTwoB, (callingWidth, 12))

    if (len(departures) > 1):
        virtualViewport.add_hotspot(rowThreeA, (0, 24))
        virtualViewport.add_hotspot(rowThreeB, (width - w, 24))
        virtualViewport.add_hotspot(rowThreeC, (width - w - pw, 24))

    if (len(departures) > 2):
        virtualViewport.add_hotspot(rowFourA, (0, 36))
        virtualViewport.add_hotspot(rowFourB, (width - w, 36))
        virtualViewport.add_hotspot(rowFourC, (width - w - pw, 36))

    virtualViewport.add_hotspot(rowTime, (0, 50))

    return virtualViewport