1
0
mirror of https://github.com/python-escpos/python-escpos synced 2025-09-13 09:09:58 +00:00

49 Commits

Author SHA1 Message Date
Patrick Kanzler
ea9a7b3fbb fix read the docs 2019-06-16 20:16:47 +02:00
Patrick Kanzler
02a47d413c fix conf 2019-06-16 20:16:47 +02:00
Patrick Kanzler
1f9e7bd45a update readthedocs 2019-06-16 20:16:47 +02:00
Patrick Kanzler
062660e00f fix path 2019-06-16 20:16:47 +02:00
Patrick Kanzler
6a8cc54b97 update read the docs config 2019-06-16 20:16:47 +02:00
Patrick Kanzler
6c6fe9bccf Merge pull request #342 from python-escpos/108-test-on-windows-travis
Add Windows and macOS configuration for Travis CI
2019-06-16 12:13:30 +02:00
Patrick Kanzler
c5e46a888d fix allowed failures 2019-06-16 03:08:19 +02:00
Patrick Kanzler
46942820a5 update env variables 2019-06-16 03:05:42 +02:00
Patrick Kanzler
e50e295acc add osx 2019-06-16 03:01:36 +02:00
Patrick Kanzler
2d7458fa49 activate fast_finish 2019-06-16 02:47:46 +02:00
Patrick Kanzler
a6f635c0d5 fix capabilities file 2019-06-16 02:45:40 +02:00
Patrick Kanzler
2d0f045457 add first draft of Windows conf for #108 2019-06-16 02:45:40 +02:00
Patrick Kanzler
293b8632ff Merge pull request #341 from python-escpos/308-update-docstring-qr
fix links and impl (in qr-method) in docstrings
2019-06-16 02:17:27 +02:00
Patrick Kanzler
5ff73595b6 fix links and impl (in qr-method) in docstrings
fixes #308
2019-06-16 01:54:47 +02:00
Patrick Kanzler
4ecab402b8 Merge pull request #339 from python-escpos/development
release v3.0a5
2019-06-16 00:31:07 +02:00
Patrick Kanzler
c56e43da84 update changelog 2019-06-16 00:17:04 +02:00
Patrick Kanzler
88af26f46e Merge pull request #338 from alexdebiasio/development
Implemented _read method of Network printer class. Solves issue #286
2019-06-16 00:01:12 +02:00
Patrick Kanzler
9dd966c2a3 update mailmap 2019-06-15 23:40:00 +02:00
Patrick Kanzler
a7d959428f update authors 2019-06-15 22:50:50 +02:00
Alex Debiasio
8bf0e08659 Implemented _read method of Network printer class 2019-06-13 21:28:46 +02:00
Patrick Kanzler
5ac5a24b50 Toolchain update travis drop py2x (#336)
* drop python 2 from supported languages

Python 2 compatibility will not be actively revoked, but will
not be worked on.

* update travis config

* remove flake8-test with Py2.7
2019-06-11 00:24:09 +02:00
Patrick Kanzler
63252515b5 Merge pull request #335 from python-escpos/322-doc-serial-printer-on-windows
doc add example for Serial on Windows
2019-06-10 22:26:34 +02:00
Patrick Kanzler
29a546821b doc add example for Serial on Windows
fixes #322
2019-06-10 22:05:26 +02:00
Patrick Kanzler
4ddd18279f Merge pull request #320 from ramonpoca/development
Add Win32Raw printer to available printers
2019-06-07 10:11:53 +02:00
Patrick Kanzler
de761e96e3 Merge branch 'development' into development 2019-06-07 09:53:14 +02:00
Patrick Kanzler
ed7bce6932 Merge pull request #329 from akeonly/patch-1
Update README.rst : example for network printer
2019-06-05 00:05:08 +02:00
Patrick Kanzler
edd567785c fix whitespace 2019-06-04 23:57:19 +02:00
Patrick Kanzler
f1054876da update authors 2019-06-04 23:55:33 +02:00
Patrick Kanzler
490e0657dd Merge branch 'development' into patch-1 2019-06-04 23:04:39 +02:00
Patrick Kanzler
b4c32b5a4a Merge branch 'development' into development 2019-06-04 23:04:25 +02:00
Patrick Kanzler
40b30225d3 Merge pull request #330 from om26er/windows-support
Enable Windows Support
2019-06-04 23:04:09 +02:00
Patrick Kanzler
19e3ec6895 Merge pull request #331 from teamorchard/use-pyyaml-safe-load
Update to use pyyaml safe_load()
2019-06-04 22:45:05 +02:00
Patrick Kanzler
df539da854 Merge branch 'development' into development 2019-06-04 22:31:47 +02:00
Patrick Kanzler
4534038b39 Merge branch 'development' into patch-1 2019-06-04 22:31:33 +02:00
Patrick Kanzler
adf85f7784 Merge branch 'development' into windows-support 2019-06-04 22:31:08 +02:00
Patrick Kanzler
aaa8162967 Merge branch 'development' into use-pyyaml-safe-load 2019-06-04 22:30:47 +02:00
Patrick Kanzler
0461adc212 restrict hypothesis-version to below 4 2019-06-04 22:30:23 +02:00
Justin Vieira
91ff83e506 Update to use pyyaml safe_load(), as load() is unsafe and disabled on some systems 2019-05-29 16:43:19 -04:00
Omer Akram
29ef88f591 Better comment 2019-05-22 17:25:33 +05:00
Omer Akram
7c01a30d6c fix a typo 2019-05-22 17:20:15 +05:00
Omer Akram
035c425581 Add author 2019-05-22 17:09:27 +05:00
Omer Akram
d20646b2a9 Make windows enablement code more intelligent 2019-05-22 17:01:13 +05:00
Omer Akram
206822ac69 Enable Windows Support 2019-05-22 16:39:26 +05:00
akeonly
dc08792e72 Update README.rst : example for network printer
Add example for Network Printer
2019-05-11 18:33:33 +07:00
Ramon Poca
2886075ce9 Fix initializer mess 2018-12-31 14:24:10 +01:00
Ramon Poca
73fff6291d Fix syntax 2018-12-31 13:57:53 +01:00
Ramon Poca
d5b9d99093 Update AUTHORS 2018-12-31 10:43:31 +01:00
Ramon Poca
18c51358aa Add Win32Raw printer to available printers 2018-12-13 08:01:05 -08:00
Gerard Marull-Paretas
52719c0b7d Allow arbitrary USB args 2018-11-21 22:01:13 +01:00
13 changed files with 188 additions and 50 deletions

View File

@@ -12,3 +12,4 @@ Juanmi Taboada <juanmi@juanmitaboada.com> Juanmi Taboada <juanmi@juan
csoft2k <csoft2k@hotmail.com>
Sergio Pulgarin <sergio.pulgarin@gmail.com>
reck31 <rakesh.gunduka@gmail.com>
Alex Debiasio <alex.debiasio@thinkin.io> <alex.debiasio@studenti.unitn.it>

10
.readthedocs.yml Normal file
View File

@@ -0,0 +1,10 @@
version: 2
formats:
- pdf
- epub
python:
version: 3.7
install:
- requirements: doc/requirements.txt
- method: setuptools
path: .

View File

@@ -1,6 +1,7 @@
language: python
sudo: false
cache: pip
dist: xenial
git:
depth: 100000
addons:
@@ -11,7 +12,23 @@ env:
global:
- ESCPOS_CAPABILITIES_FILE=/home/travis/build/python-escpos/python-escpos/capabilities-data/dist/capabilities.json
matrix:
fast_finish: true
include:
- name: "Python 3.7 on Windows"
os: windows
language: shell
before_install:
- choco install python
- pip install tox codecov 'sphinx>=1.5.1'
env:
- TOXENV=py37
- PATH=/c/Python37:/c/Python37/Scripts:$PATH
- ESCPOS_CAPABILITIES_FILE=C:/Users/travis/build/python-escpos/python-escpos/capabilities-data/dist/capabilities.json
- name: "Python 3.7 on macOS"
os: osx
osx_image: xcode10.2
language: shell
env: TOXENV=py37 ESCPOS_CAPABILITIES_FILE=/Users/travis/build/python-escpos/python-escpos/capabilities-data/dist/capabilities.json
- python: 2.7
env: TOXENV=py27
- python: 3.4
@@ -22,25 +39,31 @@ matrix:
env: TOXENV=py36
- python: 3.6-dev
env: TOXENV=py36
- python: 3.7
env: TOXENV=py37
- python: 3.7-dev
env: TOXENV=py37
- python: 3.8-dev
env: TOXENV=py38
- python: nightly
env: TOXENV=py37
env: TOXENV=py38
- python: pypy
env: TOXENV=pypy
- python: pypy3
env: TOXENV=pypy3
- python: 2.7
- python: 3.7
env: TOXENV=docs
- python: 2.7
env: TOXENV=flake8
- python: 3.6
- python: 3.7
env: TOXENV=flake8
allow_failures:
- python: 2.7
- python: 3.6-dev
- python: 3.7-dev
- python: 3.8-dev
- python: nightly
- python: pypy3
- os: windows
- os: osx
before_install:
- pip install tox codecov 'sphinx>=1.5.1'
- ./doc/generate_authors.sh --check
@@ -63,4 +86,4 @@ deploy:
tags: true
repo: python-escpos/python-escpos
branch: master
condition: $TRAVIS_PYTHON_VERSION = "3.6"
condition: $TRAVIS_PYTHON_VERSION = "3.7"

View File

@@ -1,4 +1,6 @@
Ahmed Tahri
akeonly
Alex Debiasio
Asuki Kono
belono
Christoph Heuel
@@ -8,8 +10,10 @@ Curtis // mashedkeyboard
Davis Goglin
Dean Rispin
Dmytro Katyukha
Gerard Marull-Paretas
Hark
Joel Lehtonen
Justin Vieira
kennedy
Kristi
ldos
@@ -19,9 +23,11 @@ Michael Billington
Michael Elsdörfer
mrwunderbar666
Nathan Bookham
Omer Akram
Patrick Kanzler
primax79
Qian Linfeng
Ramon Poca
reck31
Renato Lorenzi
Romain Porte

View File

@@ -1,6 +1,29 @@
*********
Changelog
*********
2019-06-16 - Version 3.0a5 - "Lightly Seared On The Reality Grill"
------------------------------------------------------------------
This release is the sixth alpha release of the new version 3.0. Please
be aware that the API is subject to change until v3.0 is released.
changes
^^^^^^^
- allow arbitrary USB arguments in USB-class
- add Win32Raw-Printer on Windows-platforms
- add and improve Windows support of USB-class
- use pyyaml safe_load()
- improve doc
- implement _read method of Network printer class
contributors
^^^^^^^^^^^^
- Patrick Kanzler
- Gerard Marull-Paretas
- Ramon Poca
- akeonly
- Omer Akram
- Justin Vieira
2018-05-15 - Version 3.0a4 - "Kakistocrat"
------------------------------------------
This release is the fifth alpha release of the new version 3.0. Please

View File

@@ -65,6 +65,19 @@ The basic usage is:
p.barcode('1324354657687', 'EAN13', 64, 2, '', '')
p.cut()
Another example based on the Network printer class:
.. code:: python
from escpos.printer import Network
kitchen = Network("192.168.1.100") #Printer IP Address
kitchen.text("Hello World\n")
kitchen.barcode('1324354657687', 'EAN13', 64, 2, '', '')
kitchen.cut()
The full project-documentation is available on `Read the Docs <https://python-escpos.readthedocs.io>`_.
Contributing

View File

@@ -44,7 +44,7 @@ to have and the second yields the "Output Endpoint" address.
::
Epson = printer.Usb(0x04b8,0x0202)
p = printer.Usb(0x04b8,0x0202)
By default the "Interface" number is "0" and the "Output Endpoint"
address is "0x01". If you have other values then you can define them on
@@ -55,7 +55,7 @@ on 0x81 and out\_ep=0x02, then the printer definition should look like:
::
Generic = printer.Usb(0x1a2b,0x1a2b,0,0x81,0x02)
p = printer.Usb(0x1a2b,0x1a2b,0,0x81,0x02)
Network printer
^^^^^^^^^^^^^^^
@@ -67,7 +67,7 @@ IP by DHCP or you set it manually.
::
Epson = printer.Network("192.168.1.99")
p = printer.Network("192.168.1.99")
Serial printer
^^^^^^^^^^^^^^
@@ -81,7 +81,10 @@ to.
::
Epson = printer.Serial("/dev/tty0")
p = printer.Serial("/dev/tty0")
# on a Windows OS serial devices are typically accessible as COM
p = printer.Serial("COM1")
Other printers
^^^^^^^^^^^^^^
@@ -93,7 +96,7 @@ passing the device node name.
::
Epson = printer.File("/dev/usb/lp1")
p = printer.File("/dev/usb/lp1")
The default is "/dev/usb/lp0", so if the printer is located on that
node, then you don't necessary need to pass the node name.
@@ -108,17 +111,17 @@ on a USB interface.
from escpos import *
""" Seiko Epson Corp. Receipt Printer M129 Definitions (EPSON TM-T88IV) """
Epson = printer.Usb(0x04b8,0x0202)
p = printer.Usb(0x04b8,0x0202)
# Print text
Epson.text("Hello World\n")
p.text("Hello World\n")
# Print image
Epson.image("logo.gif")
p.image("logo.gif")
# Print QR Code
Epson.qr("You can readme from your smartphone")
p.qr("You can readme from your smartphone")
# Print barcode
Epson.barcode('1324354657687','EAN13',64,2,'','')
p.barcode('1324354657687','EAN13',64,2,'','')
# Cut paper
Epson.cut()
p.cut()
Configuration File
------------------

View File

@@ -1,7 +0,0 @@
formats:
- pdf
- epub
requirements_file: doc/requirements.txt
python:
version: 2
setup_py_install: true

View File

@@ -65,8 +65,6 @@ setup(
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
@@ -102,7 +100,7 @@ setup(
'nose',
'scripttest',
'mock',
'hypothesis!=3.56.9',
'hypothesis!=3.56.9,<4',
'flake8'
],
entry_points={

View File

@@ -38,7 +38,7 @@ else:
if full_load:
logger.debug('Loading and pickling capabilities')
with open(capabilities_path) as cp, open(pickle_path, 'wb') as pp:
CAPABILITIES = yaml.load(cp)
CAPABILITIES = yaml.safe_load(cp)
pickle.dump(CAPABILITIES, pp, protocol=2)
logger.debug('Finished loading capabilities took %.2fs', time.time() - t0)

View File

@@ -195,6 +195,7 @@ class Escpos(object):
:param native: True to render the code on the printer, False to render the code as an image and send it to the
printer (Default)
:param center: Centers the code *default:* False
:param impl: Image-printing-implementation, refer to :meth:`.image()` for details
"""
# Basic validation
if ec not in [QR_ECLEVEL_L, QR_ECLEVEL_M, QR_ECLEVEL_H, QR_ECLEVEL_Q]:
@@ -306,8 +307,8 @@ class Escpos(object):
.. todo:: For fixed-length standards with mandatory checksum (EAN, UPC),
compute and add the checksum automatically if missing.
:param bc: barcode format, see :py:func`~escpos.Escpos.barcode`
:param code: alphanumeric data to be printed as bar code, see :py:func`~escpos.Escpos.barcode`
:param bc: barcode format, see :py:meth:`.barcode()`
:param code: alphanumeric data to be printed as bar code, see :py:meth:`.barcode()`
:return: bool
"""
if bc not in BARCODE_FORMATS:
@@ -394,7 +395,7 @@ class Escpos(object):
*default*: A
:param check: If this parameter is True, the barcode format will be checked to ensure it meets the bc
requirements as defigned in the esc/pos documentation. See py:func:`~escpos.Escpos.check_barcode`
requirements as defigned in the esc/pos documentation. See :py:meth:`.check_barcode()`
for more information. *default*: True.
:raises: :py:exc:`~escpos.exceptions.BarcodeSizeError`,

View File

@@ -34,28 +34,45 @@ class Usb(Escpos):
"""
def __init__(self, idVendor, idProduct, timeout=0, in_ep=0x82, out_ep=0x01, *args, **kwargs): # noqa: N803
def __init__(self, idVendor, idProduct, usb_args=None, timeout=0, in_ep=0x82, out_ep=0x01,
*args, **kwargs): # noqa: N803
"""
:param idVendor: Vendor ID
:param idProduct: Product ID
:param usb_args: Optional USB arguments (e.g. custom_match)
:param timeout: Is the time limit of the USB operation. Default without timeout.
:param in_ep: Input end point
:param out_ep: Output end point
"""
Escpos.__init__(self, *args, **kwargs)
self.idVendor = idVendor
self.idProduct = idProduct
self.timeout = timeout
self.in_ep = in_ep
self.out_ep = out_ep
self.open()
def open(self):
""" Search device on USB tree and set it as escpos device """
self.device = usb.core.find(idVendor=self.idVendor, idProduct=self.idProduct)
usb_args = usb_args or {}
if idVendor:
usb_args['idVendor'] = idVendor
if idProduct:
usb_args['idProduct'] = idProduct
self.open(usb_args)
def open(self, usb_args):
""" Search device on USB tree and set it as escpos device.
:param usb_args: USB arguments
"""
self.device = usb.core.find(**usb_args)
if self.device is None:
raise USBNotFoundError("Device not found or cable not plugged in.")
self.idVendor = self.device.idVendor
self.idProduct = self.device.idProduct
# pyusb has three backends: libusb0, libusb1 and openusb but
# only libusb1 backend implements the methods is_kernel_driver_active()
# and detach_kernel_driver().
# This helps enable this library to work on Windows.
if self.device.backend.__module__.endswith("libusb1"):
check_driver = None
try:
@@ -219,6 +236,11 @@ class Network(Escpos):
"""
self.device.sendall(msg)
def _read(self):
""" Read data from the TCP socket """
return self.device.recv(16)
def close(self):
""" Close TCP connection """
if self.device is not None:
@@ -322,3 +344,48 @@ class Dummy(Escpos):
def close(self):
pass
_WIN32PRINT = False
try:
import win32print
_WIN32PRINT = True
except ImportError:
pass
if _WIN32PRINT:
class Win32Raw(Escpos):
def __init__(self, printer_name=None, *args, **kwargs):
Escpos.__init__(self, *args, **kwargs)
if printer_name is not None:
self.printer_name = printer_name
else:
self.printer_name = win32print.GetDefaultPrinter()
self.hPrinter = None
def open(self, job_name="python-escpos"):
if self.printer_name is None:
raise Exception("Printer not found")
self.hPrinter = win32print.OpenPrinter(self.printer_name)
self.current_job = win32print.StartDocPrinter(self.hPrinter, 1, (job_name, None, "RAW"))
win32print.StartPagePrinter(self.hPrinter)
def close(self):
if not self.hPrinter:
return
win32print.EndPagePrinter(self.hPrinter)
win32print.EndDocPrinter(self.hPrinter)
win32print.ClosePrinter(self.hPrinter)
self.hPrinter = None
def _raw(self, msg):
""" Print any command sent in raw format
:param msg: arbitrary code to be printed
:type msg: bytes
"""
if self.printer_name is None:
raise Exception("Printer not found")
if self.hPrinter is None:
raise Exception("Printer job not opened")
win32print.WritePrinter(self.hPrinter, msg)

View File

@@ -1,5 +1,5 @@
[tox]
envlist = py27, py34, py35, docs, flake8
envlist = py27, py34, py35, py36, py37, docs, flake8
[testenv]
deps = nose
@@ -10,7 +10,7 @@ deps = nose
pytest!=3.2.0,!=3.3.0
pytest-cov
pytest-mock
hypothesis!=3.56.9
hypothesis!=3.56.9,<4
viivakoodi
commands = py.test --cov escpos
passenv = ESCPOS_CAPABILITIES_PICKLE_DIR ESCPOS_CAPABILITIES_FILE CI TRAVIS TRAVIS_* APPVEYOR APPVEYOR_* CODECOV_*