示例#1
0
 def testChildrenDraw(self):
     layout = Layout((200, 200))
     child = LayoutSub()
     layout.addLayout(child)
     otherChild = layout.addLayer(packingMode='v')
     otherChild.addLayout(LayoutSub())
     otherChild.addLayout(LayoutSub())
     self.writeImage(layout, "testChildrenDraw.gif")
示例#2
0
    def testWrite(self):
        layout = Layout((200, 200))
        layout1 = layout.addLayer(packingBias=1)
        layout2 = layout.addLayer(packingBias=3)

        self.setImage(layout1, 0xff0000, "1")
        self.setImage(layout2, 0x0088ff, "2")
        self.setImage(layout, 0x000000, "L")
        self.writeImage(layout, "test-packingBias.png")
示例#3
0
 def testChildrenSetImage(self):
     layout = Layout((200, 200))
     child = LayoutSub()
     otherChild = layout.addLayer(packingMode='v')
     otherChild.addLayout(LayoutSub())
     otherChild.addLayout(LayoutSub())
     layout.addLayout(child)
     img = child.draw()
     child.setImage(img)
     self.writeImage(layout, "testChildrenSetImage.gif")
示例#4
0
 def testDeepPackingBias(self):
     layout = Layout((200, 300), packingMode='v')
     layout1 = layout.addLayer(packingMode='h')
     layout2 = layout.addLayer()
     layout11 = layout1.addLayer(packingBias=1)
     layout12 = layout1.addLayer(packingBias=3)
     self.assertEqual((200, 150), layout2.size)
     self.setImage(layout11, 0xff0000, "Layout 11")
     self.setImage(layout12, 0x0088ff, "Layout 12")
     self.setImage(layout2, 0xaa0088, "Layout 2")
     self.writeImage(layout, "testDeepPackingBias.png")
示例#5
0
    def test_getChildSlotTotalAndBiasStart(self):
        layout = Layout((100, 100))
        self.assertEqual(0, layout._getChildSlotTotal())

        layout.addLayer(packingBias=3)
        self.assertEqual(3, layout._getChildSlotTotal())

        layout.addLayer(packingBias=3)
        self.assertEqual(6, layout._getChildSlotTotal())

        self.assertEqual(0, layout._getChildSlotStart(0))
        self.assertEqual(3, layout._getChildSlotStart(1))
示例#6
0
    def testIssue37(self):
        i_res = (250, 122)
        layout = Layout(i_res, packingMode='v', rotation=Rotation.LEFT)
        _ratesLayer = layout.addLayer()
        _time = layout.addLayer()
        _attrs = _ratesLayer.addLayer(packingBias=1)
        _rates = _ratesLayer.addLayer(packingBias=3)

        self.assertEqual((30, 125), _attrs.size)
        self.assertEqual((90, 125), _rates.size)
        self.assertEqual((122, 125), _time.size)
        self.assertEqual(0, _ratesLayer._showSparePixels())
示例#7
0
    def test_spacersWidth(self):
        layout = Layout((400, 200), border=1)
        layout.addLayer()
        layout.addLayer()
        # VERIFIED correct unit test
        self.assertEqual(0, layout._showSparePixels())
        # VERIFIED correct unit test
        self.assertEqual(2, layout._sumSpacersWidth())

        layout.addLayer()
        self.assertEqual(2, layout._sumSpacersWidth())
        self.assertEqual(0, layout._showSparePixels())
示例#8
0
    def test_calcSlotWidthBorder5(self):
        layout = Layout((400, 200), border=5)

        # No Layers added yet
        self.assertEqual((390, 190), layout._calcSlotSize())
        layout.addLayer()
        self.assertEqual((390, 190), layout._calcSlotSize())
        layout.addLayer()
        self.assertEqual((192, 190), layout._calcSlotSize())
def layoutWithLayers(
        size,
        count,
        border=0,
        packingMode='h',
        rotation=Rotation.UP
):
    layout = Layout(
        size,
        packingMode=packingMode,
        border=border,
        rotation=rotation
    )
    [layout.addLayer() for i in range(count)]
    return layout
示例#10
0
    def testPackingBiasHorizontal3_1(self):
        layout = Layout((200, 10), packingMode='h', border=(0, 0))
        layout1 = layout.addLayer(packingBias=3)
        self.assertEqual((200, 10), layout1.size)

        layout2 = layout.addLayer(packingBias=1)

        self.assertEqual((150, 10), layout1.size)
        self.assertEqual((50, 10), layout2.size)
        self.assertEqual((0, 0), layout1.topLeft)
        self.assertEqual((150, 0), layout2.topLeft)

        self.setImage(layout1, 0xff0000, "layout1")
        self.setImage(layout2, 0x0088ff, "layout2")
        self.setImage(layout, 0x000000, "layout")
        self.writeImage(layout, "testPackingBiasHorizontal3_1.png")
示例#11
0
    def testPackingBiasVertical1_3(self):

        layout = Layout((10, 200), packingMode='v', border=(0, 0))
        layout1 = layout.addLayer(packingBias=1)
        self.assertEqual((10, 200), layout1.size)

        layout2 = layout.addLayer(packingBias=3)

        self.assertEqual((10, 50), layout1.size)
        self.assertEqual((10, 150), layout2.size)
        self.assertEqual((0, 0), layout1.topLeft)
        self.assertEqual((0, 50), layout2.topLeft)
        self.setImage(layout1, 0xff0000, "1")
        self.setImage(layout2, 0x0088ff, "2")
        self.setImage(layout, 0x000000, "L")
        self.writeImage(layout, "testPackingBiasVertical1_3.png")
示例#12
0
    def testAdd2ChildrenHorizontalPacking(self):
        layout = Layout((200, 100), 'h', border=2)
        img = self.NewImage(layout)
        draw = self.NewDraw(img)
        draw.text((2, 50), "main layout 1", 2)
        layout.setImage(img)
        layer1 = layout.addLayer()

        img = self.NewImage(layer1)
        draw = self.NewDraw(img)
        draw.text((2, 50), "layer 1-1", 2)
        layer1.setImage(img)

        self.assertEqual((196, 96), layer1.size)
        self.drawAndWrite(layer1, 'Add2ChildrenHorizontalPacking1.png')

        layer2 = layout.addLayer()
        img = self.NewImage(layer2)
        draw = self.NewDraw(img)
        draw.text((2, 50), "layer 1-2", 2)
        layer2.setImage(img)

        self.assertEqual((97, 96), layer1.size)
        self.assertEqual((97, 96), layer2.size)
        self.drawAndWrite(layer2, 'Add2ChildrenHorizontalPacking2.png')
        self.drawAndWrite(layout, 'Add2ChildrenHorizontalPacking.png')
    def test_getChildSlotTotalAndBiasStart(self):
        layout = Layout((100, 100))
        self.assertEqual(0, layout._getChildSlotTotal())

        layout1 = layout.addLayer(packingMode='h')
        self.assertEqual(1, layout._getChildSlotTotal())
        self.assertEqual((100, 100), layout.size)
        self.assertEqual((100, 100), layout1.size)

        layout11 = layout1.addLayer()
        layout12 = layout1.addLayer()
        self.assertEqual((100, 100), layout.size)
        self.assertEqual((100, 100), layout1.size)
        self.assertEqual((50, 100), layout11.size)
        self.assertEqual((50, 100), layout12.size)

        layout2 = layout.addLayer(packingMode='v')
        self.assertEqual((100, 100), layout.size)
        self.assertEqual((50, 100), layout1.size)
        self.assertEqual((50, 100), layout2.size)
        self.assertEqual((25, 100), layout11.size)
        self.assertEqual((25, 100), layout12.size)

        layout21 = layout2.addLayer()
        layout22 = layout2.addLayer()

        self.assertEqual((100, 100), layout.size)
        self.assertEqual((50, 100), layout1.size)
        self.assertEqual((25, 100), layout11.size)
        self.assertEqual((25, 100), layout12.size)
        self.assertEqual((50, 100), layout2.size)
        self.assertEqual((50, 50), layout21.size)
        self.assertEqual((50, 50), layout22.size)
        layouts = (layout11, layout12, layout21, layout22)
        [
            self._setImage(layout, (0x40*index, 0xff, 0xff), str(layout._id))
            for index, layout in enumerate(layouts)
        ]
        self.writeImage(layout, "test-alternatePackingMode.png")
示例#14
0
from rpi_inky_layout import Layout, Rotation
from PIL import Image, ImageDraw
# Uncomment if you want to test on your Pi/Inky combo.
# from inky.auto import auto

topLayout = Layout((400, 100), packingMode='h', border=(1, 2))

# Uncomment if you want to test on your Pi/Inky combo.
# board = auto()
# topLayout = Layout(board.resolution, 'h', (0, 0))

sublayout1 = topLayout.addLayer()
sublayout2 = topLayout.addLayer()
sublayout3 = topLayout.addLayer()
sublayout31 = sublayout3.addLayer()
sublayout32 = sublayout3.addLayer()

mode = "P"
bgColour = 0
image31 = Image.new(mode, sublayout31.size, bgColour)
draw = ImageDraw.Draw(image31)
draw.text(tuple(s / 2 for s in sublayout31.size), "Hello", 1)
sublayout31.setImage(image31)

image32 = Image.new(mode, sublayout32.size, bgColour)
draw = ImageDraw.Draw(image32)
draw.text(tuple(s / 2 for s in sublayout32.size), "World!", 1)
sublayout32.setImage(image32)

topLayout.draw()
topLayout.write("hello-world.png")
示例#15
0
def childlessLayout(size=(200, 100), border=0, packingMode='h'):
    return Layout(size, packingMode=packingMode, border=border)
示例#16
0
 def test_calcSlotWidthBorder4(self):
     layout = Layout((400, 200), border=4)
     layout.addLayer()
     self.assertEqual((392, 192), layout._calcSlotSize())
     layout.addLayer()
     self.assertEqual((194, 192), layout._calcSlotSize())
 def testCreateLayoutRotatedRight(self):
     layout = Layout((200, 100), rotation=Rotation.RIGHT)
     self.assertEqual((100, 200), layout.size)
     self.assertEqual(90, layout.rotation_degrees)
 def testCreateLayoutRotatedDown(self):
     layout = Layout((200, 100), rotation=Rotation.DOWN)
     self.assertEqual((200, 100), layout.size)
     self.assertEqual(180, layout.rotation_degrees)
 def testCreateLayoutRotatedLeft(self):
     layout = Layout((200, 100), rotation=Rotation.LEFT)
     self.assertEqual((100, 200), layout.size)
     self.assertEqual(270, layout.rotation_degrees)
 def testCreateLayoutRotatedUp(self):
     layout = Layout((200, 100), rotation=Rotation.UP)
     self.assertEqual((200, 100), layout.size)
     self.assertEqual(0, layout.rotation_degrees)
示例#21
0
 def test_calcSpacerErrorMarginBorder3(self):
     layout = Layout((40, 200), border=3)
     layout.addLayer()
     self.assertEqual(0, sum(layout._calcPaddings()))
     self.assertEqual(0, layout._showSparePixels())
     layout.addLayer()
     self.assertEqual(0, layout._showSparePixels())
     self.assertEqual(1, sum(layout._paddings))
     layout.addLayer()
     self.assertEqual(0, layout._showSparePixels())
     self.assertEqual(1, sum(layout._paddings))