| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
There was a problem hiding this comment.
Hi @agordon and welcome to python-escpos!!.
This examples are great, however I left some suggestions and fixes to the code.
I still have to take a second look to the receipt.py but please be patient as I could be a bit slow with the review process.
By the moment we can start discussing and checking this little changes.
Thanks in advance!
Sorry, something went wrong.
There was a problem hiding this comment.
You could move this resource file to the graphics folder i.e examples/graphics/receipt/creature5.gif to keep the resource images into a separated folder as in other example files
Sorry, something went wrong.
There was a problem hiding this comment.
Same as in my previous comment: Move the resource file into the graphics/receipt sub-folder
Sorry, something went wrong.
| # Justify-text on left AND right sides by padding spaces, | ||
| # code by: Georgina Skibinski https://stackoverflow.com/a/66087666 | ||
| def justify(txt: str, width: int) -> str: | ||
| prev_txt = txt | ||
| while (l := width - len(txt)) > 0: | ||
| txt = re.sub(r"(\s+)", r"\1 ", txt, count=l) | ||
| if txt == prev_txt: | ||
| break | ||
| return txt.rjust(width) |
Sorry, something went wrong.
There was a problem hiding this comment.
Sounds good, feel free to create a change request :-)
Sorry, something went wrong.
There was a problem hiding this comment.
Second look.
I think I'm done.
Sorry, something went wrong.
| ## Itemized list header (bold with underline) | ||
| p.set_with_default(bold=True, underline=True) | ||
| p.textln(header_format.format(**header)) | ||
|
|
||
| ## Itemized List | ||
| p.set_with_default() | ||
| for idx, item in enumerate(items): | ||
| txt = item_format.format(**item) | ||
| if idx == len(items) - 1: | ||
| # If this is the last item, add underline | ||
| # to visually "close" the list. | ||
| p.set_with_default(underline=True) | ||
| p.textln(txt) |
There was a problem hiding this comment.
We recently implemented the new software_columns method which simplifies formatting and printing lines of text as columns from a list of text items, so now users have an easy way to print something like "tables".
It would be great if this example file could include that functionality.
Sorry, something went wrong.
| # Font "b" on my TM-P80-clone printer can squeeze 64 characters per line | ||
| disclaimer_width = 64 | ||
|
|
||
| recipt_barcode = "1234567890" |
There was a problem hiding this comment.
Not used.
Forgot to add the barcode to the receipt?
It would be great to see a barcode or a QR printed on the receipt to showcase the capabilities of python-escpos.
Sorry, something went wrong.
| txt = re.sub(" +", " ", txt) | ||
| # textwrap.wrap() ensures words are not broken (unlike "escpos.block_text()"). | ||
| txt = textwrap.wrap(txt, width=disclaimer_width) | ||
| # Justify each line | ||
| txt = [justify(x, disclaimer_width) for x in txt] | ||
| p.set_with_default(font="b") | ||
| for l in txt: | ||
| p.textln(l) |
There was a problem hiding this comment.
| txt = re.sub(" +", " ", txt) | |
| # textwrap.wrap() ensures words are not broken (unlike "escpos.block_text()"). | |
| txt = textwrap.wrap(txt, width=disclaimer_width) | |
| # Justify each line | |
| txt = [justify(x, disclaimer_width) for x in txt] | |
| p.set_with_default(font="b") | |
| for l in txt: | |
| p.textln(l) | |
| p.software_columns(text_list=[txt], widths=disclaimer_width, align='justify') |
Again, the software_columns method is your friend here.
This will print the text in disclaimer as a single column of left aligned text wrapped to fit within 64 characters max width per line.
The only lack would be the justification of the text that I would like to see be part of the python-escpos tools in the near future.
EDIT 2026: Justification is already a feature
Sorry, something went wrong.
Change import sorting Co-authored-by: Benito López <belono@users.noreply.github.com>
Co-authored-by: Benito López <belono@users.noreply.github.com>
Co-authored-by: Benito López <belono@users.noreply.github.com>
|
Hi @agordon !! Are you still interested in finishing this PR? If you are not, maybe we could merge it as is and make modifications after merge. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Description
Three usage examples with pictures of printed results - hopefully will help users get started quicker with python-escpos
Tested with
TM-P80 clone, called "MUNBYN 80mm USB Receipt Printer" , kernel device info: