Added barcode to exported PDF.

This commit is contained in:
Landon Wark
2023-05-16 09:31:23 -05:00
parent 903f403672
commit 7f0e13168a
5 changed files with 8 additions and 7 deletions

View File

@@ -1,6 +1,7 @@
'''
Contains widgets specific to the submission summary and submission details.
'''
import base64
from datetime import datetime
from PyQt6 import QtPrintSupport
from PyQt6.QtWidgets import (
@@ -238,6 +239,7 @@ class SubmissionDetails(QDialog):
Renders submission to html, then creates and saves .pdf file to user selected file.
"""
template = env.get_template("submission_details.html")
self.base_dict['barcode'] = base64.b64encode(make_plate_barcode(self.base_dict['Plate Number'], width=120, height=30)).decode('utf-8')
html = template.render(sub=self.base_dict)
home_dir = Path(self.ctx["directory_path"]).joinpath(f"Submission_Details_{self.base_dict['Plate Number']}.pdf").resolve().__str__()
fname = Path(QFileDialog.getSaveFileName(self, "Save File", home_dir, filter=".pdf")[0])

View File

@@ -35,7 +35,6 @@ from .custom_widgets.pop_ups import AlertPop, QuestionAsker
from .custom_widgets import ReportDatePicker, ReagentTypeForm
from .custom_widgets.misc import ImportReagent
from .visualizations.control_charts import create_charts, construct_html
import asyncio
logger = logging.getLogger(f"submissions.{__name__}")

View File

@@ -1,8 +1,8 @@
from reportlab.graphics.barcode import createBarcodeDrawing, createBarcodeImageInMemory
from reportlab.graphics.barcode import createBarcodeImageInMemory
from reportlab.graphics.shapes import Drawing
from reportlab.lib.units import mm
def make_plate_barcode(text:str) -> Drawing:
def make_plate_barcode(text:str, width:int=100, height:int=25) -> Drawing:
# return createBarcodeDrawing('Code128', value=text, width=200, height=50, humanReadable=True)
return createBarcodeImageInMemory('Code128', value=text, width=100*mm, height=25*mm, humanReadable=True, format="png")
return createBarcodeImageInMemory('Code128', value=text, width=width*mm, height=height*mm, humanReadable=True, format="png")