-
Notifications
You must be signed in to change notification settings - Fork 307
3 examples #652
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
3 examples #652
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as in my previous comment: Move the resource file into the graphics/receipt sub-folder
| # 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, feel free to create a change request :-)
belono
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Second look.
I think I'm done.
| ## 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| # 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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='left') |
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.
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>
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: