示例#1
0
def main():
    colors = ["red", "green", "blue", "yellow", "magenta", "cyan"]
    hist = history(device)

    while True:

        # Phase 1: Redraw on a fresh canvas each loop
        for idx, color in enumerate(colors):
            with canvas(hist) as draw:
                render_box(draw, idx, color)

            hist.savepoint()
            time.sleep(1)

        while len(hist) > 0:
            # Drop every other save point
            hist.restore(drop=1)
            time.sleep(1)

        # Phase 2: Notice the difference with the above?
        # ... redraw on the *same* canvas
        c = canvas(hist)
        for idx, color in enumerate(colors):
            with c as draw:
                render_box(draw, idx, color)

            hist.savepoint()
            time.sleep(1)

        while len(hist) > 0:
            hist.restore()
            time.sleep(1)
示例#2
0
def test_drop_and_restore():
    device = dummy()
    hist = history(device)

    copies = []
    for i in range(10):
        with canvas(hist) as draw:
            draw.text((10, 10), text="Hello {0}".format(i), fill="white")
        hist.savepoint()
        copies.append(device.image)

    hist.restore()
    assert device.image == copies[9]
    hist.restore(drop=2)
    assert device.image == copies[6]
    hist.restore(drop=4)
    assert device.image == copies[1]
    assert len(hist) == 1
示例#3
0
def test_save_and_restore_reverts_image():
    device = dummy()
    hist = history(device)

    with canvas(hist) as draw:
        baseline_data.primitives(hist, draw)

    img1 = device.image
    hist.savepoint()
    assert len(hist) == 1

    with canvas(hist) as draw:
        draw.text((10, 10), text="Hello", fill="white")

    img2 = device.image
    assert img1 != img2
    hist.restore()
    img3 = device.image
    assert img1 == img3
    assert len(hist) == 0
示例#4
0
def test_restore_throws_error_when_empty():
    device = dummy()
    hist = history(device)
    assert len(hist) == 0
    with pytest.raises(IndexError):
        hist.restore()