예제 #1
0
def test_add_font():
    zdoc = ZPLDocument()
    zdoc.add_font('A')
    assert (zdoc.zpl_bytes == b'^XA\n^AA\n^XZ')

    zdoc = ZPLDocument()
    zdoc.add_font('Y')
    assert (zdoc.zpl_bytes == b'^XA\n^AY\n^XZ')

    zdoc = ZPLDocument()
    zdoc.add_font(3)
    assert (zdoc.zpl_bytes == b'^XA\n^A3\n^XZ')

    with pytest.raises(ValueError):
        zdoc = ZPLDocument()
        zdoc.add_font('a')

    with pytest.raises(ValueError):
        zdoc = ZPLDocument()
        zdoc.add_font(23)
예제 #2
0
    def generateLabel(self,
                      dcNo='0',
                      upc='0',
                      title='',
                      price='$0',
                      ip_add='10.1.10.155',
                      width=2.25,
                      height=1.25):

        zpl = ZPLDocument()
        zpl.add_comment('DC No')
        zpl.add_field_origin(320, 25)
        zpl.add_font('A', zpl._ORIENTATION_NORMAL, 10)
        zpl.add_field_data(str(dcNo))

        zpl.add_comment('UPC')
        upcPos = self.__getUPCPosition(upc)
        zpl.add_field_origin(int(upcPos), 50)
        code128_data = str(upc)
        bc = Code128_Barcode(code128_data, 'N', 50, 'Y')
        zpl.add_barcode(bc)

        zpl.add_comment('Date')
        zpl.add_field_origin(30, 180)
        zpl.add_font('S', zpl._ORIENTATION_NORMAL, 16)
        zpl.add_field_data(datetime.datetime.now().strftime('%d/%m/%Y'))

        zpl.add_comment('Price')
        zpl.add_field_origin(290, 180)
        zpl.add_font('G', zpl._ORIENTATION_NORMAL, 18)
        zpl.add_field_data(str('$' + price))
        self.printZPL(zpl)
예제 #3
0
def test_add_font_width():
    for val in (10, 100, 32000):
        zdoc = ZPLDocument()
        zdoc.add_font('B', 'N', 100, val)
        assert (zdoc.zpl_bytes == b'^XA\n^AB,N,100,' +
                str(val).encode('utf-8') + b'\n^XZ')

    with pytest.raises(ValueError):
        zdoc = ZPLDocument()
        zdoc.add_font('A', 'N', 20, 9)

    with pytest.raises(ValueError):
        zdoc = ZPLDocument()
        zdoc.add_font('A', 'N', 20, 32001)

    with pytest.raises(ValueError):
        zdoc = ZPLDocument()
        zdoc.add_font('A', 'N', 20, 'ABC')
예제 #4
0
def test_add_font_orientation():
    for val in ('N', 'R', 'I', 'B'):
        zdoc = ZPLDocument()
        zdoc.add_font('B', val)
        assert (zdoc.zpl_bytes == b'^XA\n^AB,' + val.encode('utf-8') +
                b'\n^XZ')

    with pytest.raises(ValueError):
        zdoc = ZPLDocument()
        zdoc.add_font('A', '')

    with pytest.raises(ValueError):
        zdoc = ZPLDocument()
        zdoc.add_font('A', 7)
예제 #5
0
from simple_zpl2 import ZPLDocument, QR_Barcode

zpl = ZPLDocument()

zpl.add_comment('Create a QR Code')
zpl.add_field_origin(20, 20)
qr_data = 'This is data inside a QR code.  This is a barcode often read by cell phones.'
qr = QR_Barcode(qr_data, 2, 2, zpl._QR_ERROR_CORRECTION_STANDARD)
zpl.add_barcode(qr)

zpl.add_comment('Now some text')
zpl.add_field_origin(200, 20)
zpl.add_font('C', zpl._ORIENTATION_NORMAL, 15)
zpl.add_field_data('Text on Label')

# Print generated text
print(zpl.zpl_text)
예제 #6
0
def test_add_font_with_invalid_width(width):
    with pytest.raises(ValueError):
        zdoc = ZPLDocument()
        zdoc.add_font("A", "N", 20, width)
예제 #7
0
def test_add_font_width(width):
    zdoc = ZPLDocument()
    zdoc.add_font("B", "N", 100, width)
    assert zdoc.zpl_bytes == b"^XA\n^ABN,100," + str(width).encode(
        "utf-8") + b"\n^XZ"
예제 #8
0
def test_add_font(value):
    zdoc = ZPLDocument()
    zdoc.add_font(value)
    assert zdoc.zpl_bytes == b"^XA\n^A" + value.encode("utf-8") + b"\n^XZ"
예제 #9
0
def test_add_font_with_invalid_height(height):
    with pytest.raises(ValueError):
        zdoc = ZPLDocument()
        zdoc.add_font("A", "N", height)
예제 #10
0
def test_add_font_height(height):
    zdoc = ZPLDocument()
    zdoc.add_font("B", "N", height)
    assert zdoc.zpl_bytes == b"^XA\n^ABN," + str(height).encode(
        "utf-8") + b"\n^XZ"
예제 #11
0
def test_add_font_with_invalid_orientation(orientation):
    with pytest.raises(ValueError):
        zdoc = ZPLDocument()
        zdoc.add_font("A", orientation)
예제 #12
0
def test_add_font_orientation(orientation):
    zdoc = ZPLDocument()
    zdoc.add_font("B", orientation)
    assert zdoc.zpl_bytes == b"^XA\n^AB" + orientation.encode(
        "utf-8") + b"\n^XZ"
예제 #13
0
def test_add_font_with_invalid_value(value):
    with pytest.raises(ValueError):
        zdoc = ZPLDocument()
        zdoc.add_font(value)