[IMP] Add diagonal lines management

This commit is contained in:
Sylvain GARANCHER
2018-02-13 16:57:56 +01:00
committed by Lois Rilo
parent 1024ddfa42
commit 59be9bc048
4 changed files with 53 additions and 6 deletions

View File

@@ -123,6 +123,16 @@ class PrintingLabelZpl2(models.Model):
zpl2.ARG_COLOR: component.color, zpl2.ARG_COLOR: component.color,
zpl2.ARG_ROUNDING: component.rounding, zpl2.ARG_ROUNDING: component.rounding,
}) })
elif component.component_type == 'diagonal':
label_data.graphic_diagonal_line(
component_offset_x, component_offset_y, {
zpl2.ARG_WIDTH: component.width,
zpl2.ARG_HEIGHT: component.height,
zpl2.ARG_THICKNESS: component.thickness,
zpl2.ARG_COLOR: component.color,
zpl2.ARG_DIAGONAL_ORIENTATION:
component.diagonal_orientation,
})
elif component.component_type == 'graphic': elif component.component_type == 'graphic':
image = component.graphic_image or data image = component.graphic_image or data
pil_image = Image.open(io.BytesIO( pil_image = Image.open(io.BytesIO(

View File

@@ -42,6 +42,7 @@ class PrintingLabelZpl2Component(models.Model):
selection=[ selection=[
('text', 'Text'), ('text', 'Text'),
('rectangle', 'Rectangle / Line'), ('rectangle', 'Rectangle / Line'),
('diagonal', 'Diagonal Line'),
('circle', 'Circle'), ('circle', 'Circle'),
('graphic', 'Graphic'), ('graphic', 'Graphic'),
(zpl2.BARCODE_CODE_11, 'Code 11'), (zpl2.BARCODE_CODE_11, 'Code 11'),
@@ -85,6 +86,12 @@ class PrintingLabelZpl2Component(models.Model):
(zpl2.ORIENTATION_BOTTOM_UP, 'Read from Bottom up'), (zpl2.ORIENTATION_BOTTOM_UP, 'Read from Bottom up'),
], required=True, default=zpl2.ORIENTATION_NORMAL, ], required=True, default=zpl2.ORIENTATION_NORMAL,
help='Orientation of the barcode.') help='Orientation of the barcode.')
diagonal_orientation = fields.Selection(
selection=[
(zpl2.DIAGONAL_ORIENTATION_LEFT, 'Left (\\)'),
(zpl2.DIAGONAL_ORIENTATION_RIGHT, 'Right (/)'),
], default=zpl2.DIAGONAL_ORIENTATION_LEFT,
help='Orientation of the diagonal line.')
check_digits = fields.Boolean( check_digits = fields.Boolean(
help='Check if you want to compute and print the check digit.') help='Check if you want to compute and print the check digit.')
height = fields.Integer( height = fields.Integer(

View File

@@ -527,6 +527,35 @@ class TestPrintingLabelZpl2(TransactionCase):
# Label end # Label end
'^XZ') '^XZ')
def test_diagonal_line_label_contents(self):
""" Check contents of a diagonal line label """
label = self.new_label()
self.new_component({
'label_id': label.id,
'component_type': 'diagonal',
})
contents = label._generate_zpl2_data(self.printer).decode("utf-8")
self.assertEqual(
contents,
# Label start
'^XA\n'
# Print width
'^PW480\n'
# UTF-8 encoding
'^CI28\n'
# Label position
'^LH10,10\n'
# Component position
'^FO10,10'
# Component format
'^GD3,3,1,B,L'
# Component end
'^FS\n'
# Recall last saved parameters
'^JUR\n'
# Label end
'^XZ')
def test_circle_label_contents(self): def test_circle_label_contents(self):
""" Check contents of a circle label """ """ Check contents of a circle label """
label = self.new_label() label = self.new_label()

View File

@@ -64,24 +64,25 @@
<field name="sublabel_id" attrs="{'invisible': [('component_type', '!=', 'sublabel')]}"/> <field name="sublabel_id" attrs="{'invisible': [('component_type', '!=', 'sublabel')]}"/>
</group> </group>
</group> </group>
<group attrs="{'invisible': [('component_type', 'in', ('rectangle', 'circle'))]}" string="Data"> <group attrs="{'invisible': [('component_type', 'in', ('rectangle', 'diagonal', 'circle'))]}" string="Data">
<field name="data" widget="ace" options="{'mode': 'python'}" nolabel="1"/> <field name="data" widget="ace" options="{'mode': 'python'}" nolabel="1"/>
</group> </group>
<notebook colspan="4"> <notebook colspan="4">
<page string="Format" attrs="{'invisible': [('component_type', 'in', ('sublabel', 'qr_code', 'zpl2_raw'))]}"> <page string="Format" attrs="{'invisible': [('component_type', 'in', ('sublabel', 'qr_code', 'zpl2_raw'))]}">
<group> <group>
<field name="height"/> <field name="height"/>
<field name="width" attrs="{'invisible': [('component_type', 'not in', ('text', 'rectangle', 'circle', 'graphic'))]}"/> <field name="width" attrs="{'invisible': [('component_type', 'not in', ('text', 'rectangle', 'diagonal', 'circle', 'graphic'))]}"/>
<field name="reverse_print"/> <field name="reverse_print"/>
<field name="orientation" attrs="{'invisible': [('component_type', 'in', ('rectangle', 'circle'))]}"/> <field name="orientation" attrs="{'invisible': [('component_type', 'in', ('rectangle', 'diagonal', 'circle'))]}"/>
<field name="font" attrs="{'invisible': [('component_type', '!=', 'text')]}"/> <field name="font" attrs="{'invisible': [('component_type', '!=', 'text')]}"/>
<field name="in_block" attrs="{'invisible': [('component_type', '!=', 'text')]}"/> <field name="in_block" attrs="{'invisible': [('component_type', '!=', 'text')]}"/>
<field name="thickness" attrs="{'invisible': [('component_type', 'not in', ('rectangle', 'circle'))]}"/> <field name="thickness" attrs="{'invisible': [('component_type', 'not in', ('rectangle', 'diagonal', 'circle'))]}"/>
<field name="color" attrs="{'invisible': [('component_type', 'not in', ('rectangle', 'circle'))]}"/> <field name="color" attrs="{'invisible': [('component_type', 'not in', ('rectangle', 'diagonal', 'circle'))]}"/>
<field name="diagonal_orientation" attrs="{'invisible': [('component_type', '!=', 'diagonal')], 'required': [('component_type', '=', 'diagonal')]}"/>
</group> </group>
</page> </page>
<!-- Barcode specific arguments --> <!-- Barcode specific arguments -->
<page string="Barcode Format" attrs="{'invisible': [('component_type', 'in', ('text', 'rectangle', 'circle', 'sublabel', 'graphic', 'qr_code', 'zpl2_raw'))]}"> <page string="Barcode Format" attrs="{'invisible': [('component_type', 'in', ('text', 'rectangle', 'diagonal', 'circle', 'sublabel', 'graphic', 'qr_code', 'zpl2_raw'))]}">
<group> <group>
<field name="check_digits"/> <field name="check_digits"/>
<field name="interpretation_line"/> <field name="interpretation_line"/>