From 280000d6eda6c6c7aa5721cb79d0a92a5e16c203 Mon Sep 17 00:00:00 2001 From: Manuel F Martinez Date: Sat, 22 Aug 2015 12:43:09 -0700 Subject: [PATCH 01/13] Fixed issues with transparent images --- CHANGELOG | 13 +++++++++++++ escpos/escpos.py | 11 ++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index d137f7e..05cc9da 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -22,3 +22,16 @@ CHANGELOG - Added charcode tables - Fixed Horizontal Tab - Fixed code tabulators + +* 2015-04-21 - Version 1.0.5 +- Merge pull request #45 from Krispy2009/master + . Raising the right error when wrong charcode is used + . Sent by Krispy2009@gmail.com + +* 2015-07-06 - Version 1.0.6 +- Merge pull request #53 from ldos/master + . Extended params for serial printers + . Sent by cafeteria.ldosalzira@gmail.com + +* 2015-08-22 - Version 1.0.6 +- Issue #57: Fixed transparent images diff --git a/escpos/escpos.py b/escpos/escpos.py index b2e91f7..2263458 100644 --- a/escpos/escpos.py +++ b/escpos/escpos.py @@ -107,7 +107,15 @@ class Escpos: def image(self,path_img): """ Open image file """ im_open = Image.open(path_img) - im = im_open.convert("RGB") + + # Remove the alpha channel on transparent images + if im_open.mode == 'RGBA': + im_open.load() + im = Image.new("RGB", im_open.size, (255, 255, 255)) + im.paste(im_open, mask=im_open.split()[3]) + else: + im = im_open.convert("RGB") + # Convert the RGB image in printable image self._convert_image(im) @@ -119,6 +127,7 @@ class Escpos: qr_code.make(fit=True) qr_img = qr_code.make_image() im = qr_img._img.convert("RGB") + # Convert the RGB image in printable image self._convert_image(im) From 37d7f3424176a00811edfa74504b0229058c4330 Mon Sep 17 00:00:00 2001 From: Manuel F Martinez Date: Sat, 22 Aug 2015 13:10:13 -0700 Subject: [PATCH 02/13] Updated project version --- CHANGELOG | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 05cc9da..f93f909 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -33,5 +33,5 @@ CHANGELOG . Extended params for serial printers . Sent by cafeteria.ldosalzira@gmail.com -* 2015-08-22 - Version 1.0.6 +* 2015-08-22 - Version 1.0.7 - Issue #57: Fixed transparent images diff --git a/setup.py b/setup.py index 7ceeb26..d29ad51 100755 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ from distutils.core import setup setup( name='escpos', - version='1.0-4', + version='1.0.7', url='https://github.com/manpaz/python-escpos', download_url='https://github.com/manpaz/python-escpos.git', description='Python library to manipulate ESC/POS Printers', From 5eaa6f26d0a17002fd4b0ebe00a8fa6eadd23954 Mon Sep 17 00:00:00 2001 From: Manuel F Martinez Date: Sat, 22 Aug 2015 13:52:06 -0700 Subject: [PATCH 03/13] Added donation message --- README | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README b/README index 80c4867..aa08b13 100644 --- a/README +++ b/README @@ -85,5 +85,17 @@ The following example shows how to initialize the Epson TM-TI88IV Please visit project documentation at: https://github.com/manpaz/python-escpos/wiki +------------------------------------------------------------------ +6. Donations + +There are some different prints I'd like to acquire, but unfortunately +not all, even used, are cheaper and easy to get. + +If you want to help funding money to get more printers or just want to +donate because you like the project, please be in touch and I'll be +sending my PayPal info so you can donate. + +Thank you! + Manuel F Martinez From 3f6528da077618facdc102b473c42956b5e65165 Mon Sep 17 00:00:00 2001 From: Joel Lehtonen Date: Sun, 1 Feb 2015 01:46:15 +0200 Subject: [PATCH 04/13] Support for images vertically longer than 256 pixels --- escpos/escpos.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/escpos/escpos.py b/escpos/escpos.py index 2263458..045a4fd 100644 --- a/escpos/escpos.py +++ b/escpos/escpos.py @@ -41,7 +41,7 @@ class Escpos: buffer = "" self._raw(S_RASTER_N) - buffer = "%02X%02X%02X%02X" % (((size[0]/size[1])/8), 0, size[1], 0) + buffer = "%02X%02X%02X%02X" % (((size[0]/size[1])/8), 0, size[1]&0xff, size[1]>>8) self._raw(buffer.decode('hex')) buffer = "" @@ -68,7 +68,7 @@ class Escpos: if im.size[0] > 512: print ("WARNING: Image is wider than 512 and could be truncated at print time ") - if im.size[1] > 255: + if im.size[1] > 0xffff: raise ImageSizeError() im_border = self._check_image_size(im.size[0]) From cd5969e843822e63473ac36a2e5570f634a17b85 Mon Sep 17 00:00:00 2001 From: Hark Date: Fri, 4 Sep 2015 22:48:58 +0100 Subject: [PATCH 05/13] Prevent crash when using libusb0 printers --- escpos/printer.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/escpos/printer.py b/escpos/printer.py index 738d7ca..3a3bc84 100644 --- a/escpos/printer.py +++ b/escpos/printer.py @@ -40,11 +40,19 @@ class Usb(Escpos): if self.device is None: print "Cable isn't plugged in" - if self.device.is_kernel_driver_active(0): + check_driver = None + + try: + check_driver = self.device.is_kernel_driver_active(0) + except NotImplementedError: + pass + + if check_driver is None or check_driver: try: self.device.detach_kernel_driver(0) except usb.core.USBError as e: - print "Could not detatch kernel driver: %s" % str(e) + if check_driver is not None: + print "Could not detatch kernel driver: %s" % str(e) try: self.device.set_configuration() From 7e3b6ce586a56eaddba2884e033f66d88e928c19 Mon Sep 17 00:00:00 2001 From: Manuel F Martinez Date: Tue, 27 Oct 2015 13:45:15 -0700 Subject: [PATCH 06/13] Updated README and documentation --- CHANGELOG | 10 +++++++-- README | 62 +++---------------------------------------------------- setup.py | 2 +- 3 files changed, 12 insertions(+), 62 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index f93f909..6af31fc 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -26,12 +26,18 @@ CHANGELOG * 2015-04-21 - Version 1.0.5 - Merge pull request #45 from Krispy2009/master . Raising the right error when wrong charcode is used - . Sent by Krispy2009@gmail.com + . Sent by Kristi * 2015-07-06 - Version 1.0.6 - Merge pull request #53 from ldos/master . Extended params for serial printers - . Sent by cafeteria.ldosalzira@gmail.com + . Sent by ldos * 2015-08-22 - Version 1.0.7 - Issue #57: Fixed transparent images + +* 2015-10-27 - Version 1.0.8 +- Merge pull request #59 from zouppen/master + . Support for images vertically longer than 256 pixels + . Sent by Joel Lehtonen +- Updated README diff --git a/README b/README index aa08b13..2c2a41a 100644 --- a/README +++ b/README @@ -4,16 +4,7 @@ ESCPOS Python library to manipulate ESC/POS Printers. ------------------------------------------------------------------ -1. Dependencies - -In order to start getting access to your printer, you must ensure -you have previously installed the following python modules: - - * pyusb (python-usb) - * PIL (Python Image Library) - ------------------------------------------------------------------- -2. Description +1. Description Python ESC/POS is a library which lets the user have access to all those printers handled by ESC/POS commands, as defined by Epson, @@ -33,60 +24,13 @@ paper, carrier return, printer reset and others concerned to the carriage alignment. ------------------------------------------------------------------ -3. Define your printer - -Before start create your Python ESC/POS printer instance, you must -see at your system for the printer parameters. This is done with -the 'lsusb' command. - -First run the command to look for the "Vendor ID" and "Product ID", -then write down the values, these values are displayed just before -the name of the device with the following format: - - xxxx:xxxx - -Example: - Bus 002 Device 001: ID 1a2b:1a2b Device name - -Write down the the values in question, then issue the following -command so you can get the "Interface" number and "End Point" - - lsusb -vvv -d xxxx:xxxx | grep iInterface - lsusb -vvv -d xxxx:xxxx | grep bEndpointAddress | grep OUT - -The first command will yields the "Interface" number that must -be handy to have and the second yields the "Output Endpoint" -address. - -By default the "Interface" number is "0" and the "Output Endpoint" -address is "0x82", if you have other values then you can define -with your instance. - ------------------------------------------------------------------- -4. Define your instance - -The following example shows how to initialize the Epson TM-TI88IV -*** NOTE: Always finish the sequence with Epson.cut() otherwise - you will endup with weird chars being printed. - - from escpos import * - - """ Seiko Epson Corp. Receipt Printer M129 Definitions (EPSON TM-T88IV) """ - Epson = escpos.Escpos(0x04b8,0x0202) - Epson.text("Hello World") - Epson.image("logo.gif") - Epson.barcode - Epson.barcode('1324354657687','EAN13',64,2,'','') - Epson.cut() - ------------------------------------------------------------------- -5. Links +2. Documentation Please visit project documentation at: https://github.com/manpaz/python-escpos/wiki ------------------------------------------------------------------ -6. Donations +3. Donations There are some different prints I'd like to acquire, but unfortunately not all, even used, are cheaper and easy to get. diff --git a/setup.py b/setup.py index d29ad51..adbb97a 100755 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ from distutils.core import setup setup( name='escpos', - version='1.0.7', + version='1.0.8', url='https://github.com/manpaz/python-escpos', download_url='https://github.com/manpaz/python-escpos.git', description='Python library to manipulate ESC/POS Printers', From c1d985eeaf98d369388acabb952972ca0ad72dce Mon Sep 17 00:00:00 2001 From: Patrick Kanzler Date: Sat, 28 Nov 2015 14:22:54 +0100 Subject: [PATCH 07/13] FIX constant definition for PC1252 * fixes #40 * according to the table http://content.epson.de/fileadmin/content/files/RSD/downloads/escpos.pdf --- escpos/constants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/escpos/constants.py b/escpos/constants.py index 7511365..09a833a 100644 --- a/escpos/constants.py +++ b/escpos/constants.py @@ -42,7 +42,7 @@ CHARCODE_PC865 = '\x1b\x74\x05' # Nordic CHARCODE_WEU = '\x1b\x74\x06' # Simplified Kanji, Hirakana CHARCODE_GREEK = '\x1b\x74\x07' # Simplified Kanji CHARCODE_HEBREW = '\x1b\x74\x08' # Simplified Kanji -CHARCODE_PC1252 = '\x1b\x74\x11' # Western European Windows Code Set +CHARCODE_PC1252 = '\x1b\x74\x10' # Western European Windows Code Set CHARCODE_PC866 = '\x1b\x74\x12' # Cirillic #2 CHARCODE_PC852 = '\x1b\x74\x13' # Latin 2 CHARCODE_PC858 = '\x1b\x74\x14' # Euro From 06a68d1c97cb4f2d8a795da45b24d300abda8dda Mon Sep 17 00:00:00 2001 From: Patrick Kanzler Date: Sat, 26 Dec 2015 17:18:40 +0100 Subject: [PATCH 08/13] DOC add very simple (and bad-looking) api-reference as doc-stub --- doc/.gitignore | 1 + doc/Makefile | 177 +++++++++++++++++++++++++ doc/api-documentation.rst | 32 +++++ doc/conf.py | 264 ++++++++++++++++++++++++++++++++++++++ doc/index.rst | 23 ++++ doc/make.bat | 242 ++++++++++++++++++++++++++++++++++ 6 files changed, 739 insertions(+) create mode 100644 doc/.gitignore create mode 100644 doc/Makefile create mode 100644 doc/api-documentation.rst create mode 100644 doc/conf.py create mode 100644 doc/index.rst create mode 100644 doc/make.bat diff --git a/doc/.gitignore b/doc/.gitignore new file mode 100644 index 0000000..b2f10c4 --- /dev/null +++ b/doc/.gitignore @@ -0,0 +1 @@ +_build diff --git a/doc/Makefile b/doc/Makefile new file mode 100644 index 0000000..f423c2f --- /dev/null +++ b/doc/Makefile @@ -0,0 +1,177 @@ +# Makefile for Sphinx documentation +# + +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = sphinx-build +PAPER = +BUILDDIR = _build + +# User-friendly check for sphinx-build +ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) +$(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/) +endif + +# Internal variables. +PAPEROPT_a4 = -D latex_paper_size=a4 +PAPEROPT_letter = -D latex_paper_size=letter +ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . +# the i18n builder cannot share the environment and doctrees with the others +I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . + +.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext + +help: + @echo "Please use \`make ' where is one of" + @echo " html to make standalone HTML files" + @echo " dirhtml to make HTML files named index.html in directories" + @echo " singlehtml to make a single large HTML file" + @echo " pickle to make pickle files" + @echo " json to make JSON files" + @echo " htmlhelp to make HTML files and a HTML help project" + @echo " qthelp to make HTML files and a qthelp project" + @echo " devhelp to make HTML files and a Devhelp project" + @echo " epub to make an epub" + @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" + @echo " latexpdf to make LaTeX files and run them through pdflatex" + @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" + @echo " text to make text files" + @echo " man to make manual pages" + @echo " texinfo to make Texinfo files" + @echo " info to make Texinfo files and run them through makeinfo" + @echo " gettext to make PO message catalogs" + @echo " changes to make an overview of all changed/added/deprecated items" + @echo " xml to make Docutils-native XML files" + @echo " pseudoxml to make pseudoxml-XML files for display purposes" + @echo " linkcheck to check all external links for integrity" + @echo " doctest to run all doctests embedded in the documentation (if enabled)" + +clean: + rm -rf $(BUILDDIR)/* + +html: + $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." + +dirhtml: + $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." + +singlehtml: + $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml + @echo + @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." + +pickle: + $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle + @echo + @echo "Build finished; now you can process the pickle files." + +json: + $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json + @echo + @echo "Build finished; now you can process the JSON files." + +htmlhelp: + $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp + @echo + @echo "Build finished; now you can run HTML Help Workshop with the" \ + ".hhp project file in $(BUILDDIR)/htmlhelp." + +qthelp: + $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp + @echo + @echo "Build finished; now you can run "qcollectiongenerator" with the" \ + ".qhcp project file in $(BUILDDIR)/qthelp, like this:" + @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/python-escpos.qhcp" + @echo "To view the help file:" + @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/python-escpos.qhc" + +devhelp: + $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp + @echo + @echo "Build finished." + @echo "To view the help file:" + @echo "# mkdir -p $$HOME/.local/share/devhelp/python-escpos" + @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/python-escpos" + @echo "# devhelp" + +epub: + $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub + @echo + @echo "Build finished. The epub file is in $(BUILDDIR)/epub." + +latex: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo + @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." + @echo "Run \`make' in that directory to run these through (pdf)latex" \ + "(use \`make latexpdf' here to do that automatically)." + +latexpdf: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo "Running LaTeX files through pdflatex..." + $(MAKE) -C $(BUILDDIR)/latex all-pdf + @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." + +latexpdfja: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo "Running LaTeX files through platex and dvipdfmx..." + $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja + @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." + +text: + $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text + @echo + @echo "Build finished. The text files are in $(BUILDDIR)/text." + +man: + $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man + @echo + @echo "Build finished. The manual pages are in $(BUILDDIR)/man." + +texinfo: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo + @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." + @echo "Run \`make' in that directory to run these through makeinfo" \ + "(use \`make info' here to do that automatically)." + +info: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo "Running Texinfo files through makeinfo..." + make -C $(BUILDDIR)/texinfo info + @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." + +gettext: + $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale + @echo + @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." + +changes: + $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes + @echo + @echo "The overview file is in $(BUILDDIR)/changes." + +linkcheck: + $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck + @echo + @echo "Link check complete; look for any errors in the above output " \ + "or in $(BUILDDIR)/linkcheck/output.txt." + +doctest: + $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest + @echo "Testing of doctests in the sources finished, look at the " \ + "results in $(BUILDDIR)/doctest/output.txt." + +xml: + $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml + @echo + @echo "Build finished. The XML files are in $(BUILDDIR)/xml." + +pseudoxml: + $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml + @echo + @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." diff --git a/doc/api-documentation.rst b/doc/api-documentation.rst new file mode 100644 index 0000000..30d3cde --- /dev/null +++ b/doc/api-documentation.rst @@ -0,0 +1,32 @@ +API reference +============= + +The main class and abstract implementation of an Esc/Pos printer. + +escpos +====== +.. automodule:: escpos.escpos + :members: + :undoc-members: + :show-inheritance: + +printer +======= +.. automodule:: escpos.printer + :members: + :undoc-members: + :show-inheritance: + +exceptions +========== +.. automodule:: escpos.exceptions + :members: + :undoc-members: + :show-inheritance: + +constants +========= +.. automodule:: escpos.constants + :members: + :undoc-members: + :show-inheritance: \ No newline at end of file diff --git a/doc/conf.py b/doc/conf.py new file mode 100644 index 0000000..eae97ac --- /dev/null +++ b/doc/conf.py @@ -0,0 +1,264 @@ +# -*- coding: utf-8 -*- +# +# python-escpos documentation build configuration file, created by +# sphinx-quickstart on Sat Dec 26 14:28:42 2015. +# +# This file is execfile()d with the current directory set to its +# containing dir. +# +# Note that not all possible configuration values are present in this +# autogenerated file. +# +# All configuration values have a default; values that are commented out +# serve to show the default. + +import sys +import os + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +#sys.path.insert(0, os.path.abspath('.')) + +# -- General configuration ------------------------------------------------ + +# If your documentation needs a minimal Sphinx version, state it here. +#needs_sphinx = '1.0' + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [ + 'sphinx.ext.autodoc', + 'sphinx.ext.doctest', + 'sphinx.ext.todo', + 'sphinx.ext.coverage', + 'sphinx.ext.viewcode', +] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# The suffix of source filenames. +source_suffix = '.rst' + +# The encoding of source files. +#source_encoding = 'utf-8-sig' + +# The master toctree document. +master_doc = 'index' + +# General information about the project. +project = u'python-escpos' +copyright = u'2015, Manuel F Martinez and others' + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +# The short X.Y version. +version = '1.0.8' +# The full version, including alpha/beta/rc tags. +release = '1.0.8' + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +#language = None + +# There are two options for replacing |today|: either, you set today to some +# non-false value, then it is used: +#today = '' +# Else, today_fmt is used as the format for a strftime call. +#today_fmt = '%B %d, %Y' + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +exclude_patterns = ['_build'] + +# The reST default role (used for this markup: `text`) to use for all +# documents. +#default_role = None + +# If true, '()' will be appended to :func: etc. cross-reference text. +#add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +#add_module_names = True + +# If true, sectionauthor and moduleauthor directives will be shown in the +# output. They are ignored by default. +#show_authors = False + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'sphinx' + +# A list of ignored prefixes for module index sorting. +#modindex_common_prefix = [] + +# If true, keep warnings as "system message" paragraphs in the built documents. +#keep_warnings = False + + +# -- Options for HTML output ---------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +html_theme = 'default' + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +#html_theme_options = {} + +# Add any paths that contain custom themes here, relative to this directory. +#html_theme_path = [] + +# The name for this set of Sphinx documents. If None, it defaults to +# " v documentation". +#html_title = None + +# A shorter title for the navigation bar. Default is the same as html_title. +#html_short_title = None + +# The name of an image file (relative to this directory) to place at the top +# of the sidebar. +#html_logo = None + +# The name of an image file (within the static path) to use as favicon of the +# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 +# pixels large. +#html_favicon = None + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] + +# Add any extra paths that contain custom files (such as robots.txt or +# .htaccess) here, relative to this directory. These files are copied +# directly to the root of the documentation. +#html_extra_path = [] + +# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, +# using the given strftime format. +#html_last_updated_fmt = '%b %d, %Y' + +# If true, SmartyPants will be used to convert quotes and dashes to +# typographically correct entities. +#html_use_smartypants = True + +# Custom sidebar templates, maps document names to template names. +#html_sidebars = {} + +# Additional templates that should be rendered to pages, maps page names to +# template names. +#html_additional_pages = {} + +# If false, no module index is generated. +#html_domain_indices = True + +# If false, no index is generated. +#html_use_index = True + +# If true, the index is split into individual pages for each letter. +#html_split_index = False + +# If true, links to the reST sources are added to the pages. +#html_show_sourcelink = True + +# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. +#html_show_sphinx = True + +# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. +#html_show_copyright = True + +# If true, an OpenSearch description file will be output, and all pages will +# contain a tag referring to it. The value of this option must be the +# base URL from which the finished HTML is served. +#html_use_opensearch = '' + +# This is the file name suffix for HTML files (e.g. ".xhtml"). +#html_file_suffix = None + +# Output file base name for HTML help builder. +htmlhelp_basename = 'python-escposdoc' + + +# -- Options for LaTeX output --------------------------------------------- + +latex_elements = { +# The paper size ('letterpaper' or 'a4paper'). +#'papersize': 'letterpaper', + +# The font size ('10pt', '11pt' or '12pt'). +#'pointsize': '10pt', + +# Additional stuff for the LaTeX preamble. +#'preamble': '', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, +# author, documentclass [howto, manual, or own class]). +latex_documents = [ + ('index', 'python-escpos.tex', u'python-escpos Documentation', + u'Manuel F Martinez and others', 'manual'), +] + +# The name of an image file (relative to this directory) to place at the top of +# the title page. +#latex_logo = None + +# For "manual" documents, if this is true, then toplevel headings are parts, +# not chapters. +#latex_use_parts = False + +# If true, show page references after internal links. +#latex_show_pagerefs = False + +# If true, show URL addresses after external links. +#latex_show_urls = False + +# Documents to append as an appendix to all manuals. +#latex_appendices = [] + +# If false, no module index is generated. +#latex_domain_indices = True + + +# -- Options for manual page output --------------------------------------- + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + ('index', 'python-escpos', u'python-escpos Documentation', + [u'Manuel F Martinez and others'], 1) +] + +# If true, show URL addresses after external links. +#man_show_urls = False + + +# -- Options for Texinfo output ------------------------------------------- + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + ('index', 'python-escpos', u'python-escpos Documentation', + u'Manuel F Martinez and others', 'python-escpos', 'One line description of project.', + 'Miscellaneous'), +] + +# Documents to append as an appendix to all manuals. +#texinfo_appendices = [] + +# If false, no module index is generated. +#texinfo_domain_indices = True + +# How to display URL addresses: 'footnote', 'no', or 'inline'. +#texinfo_show_urls = 'footnote' + +# If true, do not generate a @detailmenu in the "Top" node's menu. +#texinfo_no_detailmenu = False diff --git a/doc/index.rst b/doc/index.rst new file mode 100644 index 0000000..a1ac7c0 --- /dev/null +++ b/doc/index.rst @@ -0,0 +1,23 @@ +.. python-escpos documentation master file, created by + sphinx-quickstart on Sat Dec 26 14:28:42 2015. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +Welcome to python-escpos's documentation! +========================================= + +Contents: + +.. toctree:: + :maxdepth: 1 + + api-documentation + + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` + diff --git a/doc/make.bat b/doc/make.bat new file mode 100644 index 0000000..8e2ddc9 --- /dev/null +++ b/doc/make.bat @@ -0,0 +1,242 @@ +@ECHO OFF + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set BUILDDIR=_build +set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% . +set I18NSPHINXOPTS=%SPHINXOPTS% . +if NOT "%PAPER%" == "" ( + set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% + set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% +) + +if "%1" == "" goto help + +if "%1" == "help" ( + :help + echo.Please use `make ^` where ^ is one of + echo. html to make standalone HTML files + echo. dirhtml to make HTML files named index.html in directories + echo. singlehtml to make a single large HTML file + echo. pickle to make pickle files + echo. json to make JSON files + echo. htmlhelp to make HTML files and a HTML help project + echo. qthelp to make HTML files and a qthelp project + echo. devhelp to make HTML files and a Devhelp project + echo. epub to make an epub + echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter + echo. text to make text files + echo. man to make manual pages + echo. texinfo to make Texinfo files + echo. gettext to make PO message catalogs + echo. changes to make an overview over all changed/added/deprecated items + echo. xml to make Docutils-native XML files + echo. pseudoxml to make pseudoxml-XML files for display purposes + echo. linkcheck to check all external links for integrity + echo. doctest to run all doctests embedded in the documentation if enabled + goto end +) + +if "%1" == "clean" ( + for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i + del /q /s %BUILDDIR%\* + goto end +) + + +%SPHINXBUILD% 2> nul +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.http://sphinx-doc.org/ + exit /b 1 +) + +if "%1" == "html" ( + %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/html. + goto end +) + +if "%1" == "dirhtml" ( + %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. + goto end +) + +if "%1" == "singlehtml" ( + %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. + goto end +) + +if "%1" == "pickle" ( + %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can process the pickle files. + goto end +) + +if "%1" == "json" ( + %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can process the JSON files. + goto end +) + +if "%1" == "htmlhelp" ( + %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can run HTML Help Workshop with the ^ +.hhp project file in %BUILDDIR%/htmlhelp. + goto end +) + +if "%1" == "qthelp" ( + %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can run "qcollectiongenerator" with the ^ +.qhcp project file in %BUILDDIR%/qthelp, like this: + echo.^> qcollectiongenerator %BUILDDIR%\qthelp\python-escpos.qhcp + echo.To view the help file: + echo.^> assistant -collectionFile %BUILDDIR%\qthelp\python-escpos.ghc + goto end +) + +if "%1" == "devhelp" ( + %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. + goto end +) + +if "%1" == "epub" ( + %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The epub file is in %BUILDDIR%/epub. + goto end +) + +if "%1" == "latex" ( + %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. + goto end +) + +if "%1" == "latexpdf" ( + %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex + cd %BUILDDIR%/latex + make all-pdf + cd %BUILDDIR%/.. + echo. + echo.Build finished; the PDF files are in %BUILDDIR%/latex. + goto end +) + +if "%1" == "latexpdfja" ( + %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex + cd %BUILDDIR%/latex + make all-pdf-ja + cd %BUILDDIR%/.. + echo. + echo.Build finished; the PDF files are in %BUILDDIR%/latex. + goto end +) + +if "%1" == "text" ( + %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The text files are in %BUILDDIR%/text. + goto end +) + +if "%1" == "man" ( + %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The manual pages are in %BUILDDIR%/man. + goto end +) + +if "%1" == "texinfo" ( + %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. + goto end +) + +if "%1" == "gettext" ( + %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The message catalogs are in %BUILDDIR%/locale. + goto end +) + +if "%1" == "changes" ( + %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes + if errorlevel 1 exit /b 1 + echo. + echo.The overview file is in %BUILDDIR%/changes. + goto end +) + +if "%1" == "linkcheck" ( + %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck + if errorlevel 1 exit /b 1 + echo. + echo.Link check complete; look for any errors in the above output ^ +or in %BUILDDIR%/linkcheck/output.txt. + goto end +) + +if "%1" == "doctest" ( + %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest + if errorlevel 1 exit /b 1 + echo. + echo.Testing of doctests in the sources finished, look at the ^ +results in %BUILDDIR%/doctest/output.txt. + goto end +) + +if "%1" == "xml" ( + %SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The XML files are in %BUILDDIR%/xml. + goto end +) + +if "%1" == "pseudoxml" ( + %SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml. + goto end +) + +:end From 8a77c963c30dcb6c91b232416a66fa7dfd0f5a07 Mon Sep 17 00:00:00 2001 From: Patrick Kanzler Date: Sun, 27 Dec 2015 16:56:51 +0100 Subject: [PATCH 09/13] DOC transfered wiki to sphinx-doc * changed structure of index-file * copied the WIKI at commit 67601b2d33f5a3cf8e9633e6ad92cca286840680 * adapted the markdown to rst --- doc/{api-documentation.rst => api.rst} | 0 doc/index.rst | 37 ++++++- doc/user/.directory | 5 + doc/user/dependencies.rst | 57 ++++++++++ doc/user/installation.rst | 40 +++++++ doc/user/methods.rst | 118 +++++++++++++++++++++ doc/user/printers.rst | 42 ++++++++ doc/user/raspi.rst | 68 ++++++++++++ doc/user/todo.rst | 35 +++++++ doc/user/usage.rst | 138 +++++++++++++++++++++++++ 10 files changed, 538 insertions(+), 2 deletions(-) rename doc/{api-documentation.rst => api.rst} (100%) create mode 100644 doc/user/.directory create mode 100644 doc/user/dependencies.rst create mode 100644 doc/user/installation.rst create mode 100644 doc/user/methods.rst create mode 100644 doc/user/printers.rst create mode 100644 doc/user/raspi.rst create mode 100644 doc/user/todo.rst create mode 100644 doc/user/usage.rst diff --git a/doc/api-documentation.rst b/doc/api.rst similarity index 100% rename from doc/api-documentation.rst rename to doc/api.rst diff --git a/doc/index.rst b/doc/index.rst index a1ac7c0..14cd7be 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -6,13 +6,46 @@ Welcome to python-escpos's documentation! ========================================= -Contents: +Python ESC/POS is a library which lets the user have access to all those printers handled by ESC/POS commands, as defined by Epson, from a Python application. + +The standard usage is send raw text to the printer, but in also helps the user to enhance the experience with those printers by facilitating the bar code printing in many different standards,as well as manipulating images so they can be printed as brand logo or any other usage images migh have. + +Text can be justified and fonts can be changed by size, type and weight. + +Also, this module handles some hardware functionalists like, cut paper, cash drawer kicking, printer reset, carriage return and others concerned to the carriage alignment. + +------------ + +There are some different printers I'd like to acquire, unfortunately +not all, even used, are cheaper and easy to get. + +If you want to help funding money to get more printers or just want to +donate because you like the project, please be in touch and I'll be +sending my PayPal info so you can donate. + +Thank you! + +User Documentation: +------------------- .. toctree:: :maxdepth: 1 - api-documentation + user/dependencies + user/installation + user/methods + user/printers + user/raspi + user/todo + user/usage + +API: +---- + +.. toctree:: + :maxdepth: 1 + api Indices and tables ================== diff --git a/doc/user/.directory b/doc/user/.directory new file mode 100644 index 0000000..8e8ab5a --- /dev/null +++ b/doc/user/.directory @@ -0,0 +1,5 @@ +[Dolphin] +HeaderColumnWidths=270,74,108 +Timestamp=2015,12,27,17,3,8 +Version=3 +ViewMode=1 diff --git a/doc/user/dependencies.rst b/doc/user/dependencies.rst new file mode 100644 index 0000000..cc2963d --- /dev/null +++ b/doc/user/dependencies.rst @@ -0,0 +1,57 @@ +************ +Dependencies +************ + +Fedora +------ + +Fortunately everything is on Fedora repositories. + +:: + + # yum install python-imaging pyserial pyusb python-qrcode + +Ubuntu +------ + +Ultimately, this instructions also apply to Raspbian, in case you are +interested to install python-escpos on your Raspberry with Raspbian. + +Install the packages available on distro repositories. + +:: + + # apt-get install python-imaging pyserial + +The packages which are not available at Ubuntu repositories need to be +installed manually. + +pyusb +^^^^^ +This is the python binding to libusb-1.0 + +* Get the latest tarball from `sourceforge `__ +* Build and install it + +:: + + # tar zxvf pyusb-1.*.tar.gz + # cd pyusb-1.* + # python setup.py build + # sudo python setup.py install + +python-qrcode +^^^^^^^^^^^^^ + +This is the python module to generate QR Codes + +* Checkout the latest code from `github `__ +* Build and install it + +:: + + # git clone https://github.com/lincolnloop/python-qrcode + # cd python-qrcode + # python setup.py build + # sudo python setup.py install + diff --git a/doc/user/installation.rst b/doc/user/installation.rst new file mode 100644 index 0000000..be08c8a --- /dev/null +++ b/doc/user/installation.rst @@ -0,0 +1,40 @@ +************ +Installation +************ + +System preparation +------------------ + +1. Install the required + `dependencies `__ + +2. Get the *Product ID* and *Vendor ID* from the lsusb command + ``# lsusb Bus 002 Device 001: ID 1a2b:1a2b Device name`` + +3. Create a udev rule to let users belonging to *dialout* group use the + printer. You can create the file + ``/etc/udev/rules.d/99-escpos.rules`` and add the following: + ``SUBSYSTEM=="usb", ATTRS{idVendor}=="1a2b", ATTRS{idProduct}=="1a2b", MODE="0664", GROUP="dialout"`` + Replace *idVendor* and *idProduct* hex numbers with the ones that you + got from the previous step. Note that you can either, add yourself to + "dialout" group, or use another group you already belongs instead + "dialout" and set it in the ``GROUP`` parameter in the above rule. + +4. Restart udev ``# sudo service udev restart`` In some new systems it + is done with ``# sudo udevadm control --reload`` + +Install +------- + +* Clone python-escpos from github +* Change directory to python-escpos and install the package + + :: + + # cd python-escpos + # python setup.py build + # sudo python setup.py install + +* Enjoy !!! + + diff --git a/doc/user/methods.rst b/doc/user/methods.rst new file mode 100644 index 0000000..b4ce495 --- /dev/null +++ b/doc/user/methods.rst @@ -0,0 +1,118 @@ +******* +Methods +******* + +.. note:: **TODO** Merge this page into the API-description. + +Escpos class +------------ + +Escpos inherits its methods to the printers. the following methods are +defined: + +image("image\_name.ext") +^^^^^^^^^^^^^^^^^^^^^^^^ + +Prints an image. Its adjust the size in order to print it. + +* ``image_name.ext`` is the complete file name and location of any image type (jpg, gif, png, bmp) + +Raises ``ImageSizeError`` exception. + +qr("text") +^^^^^^^^^^ + +Prints a QR code. The size has been adjusted to Version 4, so it can be +enough small to be printed but also enough big to be read by a smart +phone. + +* ``text`` Any text that needs to be QR encoded. It could be a slogan, + salutation, url, etc. + +barcode("code", "barcode\_type", width, height, "position", "font") +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Prints a barcode. + +* ``code`` is an alphanumeric code to be printed as bar code +* ``barcode_type`` must be one of the following type of codes: + + * UPC-A + * UPC-E + * EAN13 + * EAN8 + * CODE39 + * ITF + * NW7 + +* ``width`` is a numeric value in the range between (1,255) *Default:* 64 +* ``height`` is a numeric value in the range between (2,6) *Default:* 3 +* ``position`` is where to place the code around the bars, could be one of the following values: + + * ABOVE + * BELOW + * BOTH + * OFF > *Default:* BELOW + +* ``font`` is one of the 2 type of fonts, values could be: + + * A + * B > *Default:* A Raises ``BarcodeTypeError``, ``BarcodeSizeError``, ``BarcodeCodeError`` exceptions. + +text("text") +^^^^^^^^^^^^ + +Prints raw text. Raises ``TextError`` exception. + +set("align", "font", "type", width, height) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Set text properties. +* ``align`` set horizontal position for text, the possible values are: + + * CENTER + * LEFT + * RIGHT > > *Default:* left + +* ``font`` type could be ``A`` or ``B``. *Default:* A +* ``type`` type could be ``B`` (Bold), ``U`` (Underline) or ``normal``. *Default:* normal +* ``width`` is a numeric value, 1 is for regular size, and 2 is twice the standard size. *Default*: 1 +* ``height`` is a numeric value, 1 is for regular size and 2 is twice the standard size. *Default*: 1 + +cut("mode") +^^^^^^^^^^^ + +Cut paper. +* ``mode`` set a full or partial cut. *Default:* full + +**Partial cut is not implemented in all printers.** + +cashdraw(pin) +^^^^^^^^^^^^^ + +Sends a pulse to the cash drawer in the specified pin. + +* ``pin`` is a numeric value which defines the pin to be used to send the pulse, it could be 2 or 5. Raises ``CashDrawerError()`` + +hw("operation") +^^^^^^^^^^^^^^^ + +Hardware operations. + +* ``operation`` is any of the following options: + + * INIT + * SELECT + * RESET + +control("align") +^^^^^^^^^^^^^^^^ + +Carrier feed and tabs. +* ``align`` is a string which takes any of the following values: + + * LF *for Line Feed* + * FF *for Form Feed* + * CR *for Carriage Return* + * HT *for Horizontal Tab* + * VT *for Vertical Tab* diff --git a/doc/user/printers.rst b/doc/user/printers.rst new file mode 100644 index 0000000..c1f5495 --- /dev/null +++ b/doc/user/printers.rst @@ -0,0 +1,42 @@ +******** +Printers +******** + +.. note:: **TODO** Merge this page into the API-description. + +There 3 different type of printers: + +USB(idVendor, idProduct, interface, in\_ep, out\_ep) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Based on pyusb and libusb-1.0 + +* ``idVendor`` is the Vendor ID +* ``idProduct`` is the Product ID +* ``interface`` is the USB device interface (default = 0) +* ``in_ep`` is the input end point (default = 0x82) +* ``out_ep`` is the output end point (default = 0x01) + +Serial("devfile", baudrate, bytesize, timeout) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Based on pyserial, default values are based on the defaults set by +DIP\_SWITCH\_1 on the documentation(hardware side). + +* ``devfile`` is an alphanumeric device file name under /dev filesystem (default = /ev/ttyS0) +* ``baudrate`` is the Baud rate for serial transmission (default = 9600) +* ``bytesize`` sets the serial buffer size (default = 8) +* ``timeout`` defines Read/Write timeout (default = 1) + +Network("host", port) +^^^^^^^^^^^^^^^^^^^^^ + +Based on socket +* ``host`` is an alphanumeric host name, could be either DNS host name or IP address. +* ``port`` to write to (default = 9100) + +File("file\_name") +^^^^^^^^^^^^^^^^^^ + +Printcap printers +* ``file_name`` is the full path to the device file name diff --git a/doc/user/raspi.rst b/doc/user/raspi.rst new file mode 100644 index 0000000..77b251f --- /dev/null +++ b/doc/user/raspi.rst @@ -0,0 +1,68 @@ +************ +Raspberry Pi +************ + +This instructions were tested on Raspbian. + +Unless you have done any distro with libusb-1.0 on the Raspberry Pi, the +following instructions should works fine on your raspberry distro. + +Dependencies +------------ + +First, install the packages available on Raspbian. + +:: + + # apt-get install python-imaging python-serial python-setuptools + +PyUSB +^^^^^ + +PyUSB 1.0 is not available on Ubuntu, so you have to download and +install it manually + +1. Download the latest tarball from + `Sourceforge `__ +2. Decompress the zip file +3. Install the library + + :: + + # wget ... + # unzip pyusb*.zip + # cd pyusb* + # python setup.py build + # sudo python setup.py install + +python-qrcode +^^^^^^^^^^^^^ + +1. Checkout the code from github +2. Install the library + + :: + + # git clone https://github.com/lincolnloop/python-qrcode + # cd python-qrcode + # python setup.py build + # sudo python setup.py install + +Installation +------------ + +If you have installed pyusb for libusb-1.0 then you need to: + +1. Download the latest file +1. Decompress the file +1. Install the library + +:: + + # git clone https://github.com/manpaz/python-escpos.git + # cd python-escpos + # python setup.py build + # sudo python setup.py install + +Now you can attach your printer and and test it with the example code in +the project's `home `__ diff --git a/doc/user/todo.rst b/doc/user/todo.rst new file mode 100644 index 0000000..3777a7d --- /dev/null +++ b/doc/user/todo.rst @@ -0,0 +1,35 @@ +**** +TODO +**** + +Introduction +------------ + +python-escpos is the initial idea, from here we can start to build a +robust library to get most of the ESC/POS printers working with this +library. + +Eventually, this library must be able to cover almost all the defined +models detailed in the ESC/POS Command Specification Manual. + +Details +------- + +What things are planned to work on? + +Testing +~~~~~~~ + +* Test on many printers as possible (USB, Serial, Network) + +Design +~~~~~~ + +* Add all those sequences which are not common, but part of the ESC/POS + Command Specifications. + + * Port to Python 3 + * Windows compatibility (hidapi instead libusb?) + * PDF417 support + + diff --git a/doc/user/usage.rst b/doc/user/usage.rst new file mode 100644 index 0000000..074e8a0 --- /dev/null +++ b/doc/user/usage.rst @@ -0,0 +1,138 @@ +***** +Usage +***** + +Define your printer +------------------- + +USB printer +^^^^^^^^^^^ + +Before start creating your Python ESC/POS printer instance, you must see +at your system for the printer parameters. This is done with the 'lsusb' +command. + +First run the command to look for the "Vendor ID" and "Product ID", then +write down the values, these values are displayed just before the name +of the device with the following format: + +:: + + xxxx:xxxx + +Example: + +:: + + # lsusb + Bus 002 Device 001: ID 04b8:0202 Epson ... + +Write down the the values in question, then issue the following command +so you can get the "Interface" number and "End Point" + +:: + + # lsusb -vvv -d xxxx:xxxx | grep iInterface + iInterface 0 + # lsusb -vvv -d xxxx:xxxx | grep bEndpointAddress | grep OUT + bEndpointAddress 0x01 EP 1 OUT + +The first command will yields the "Interface" number that must be handy +to have and the second yields the "Output Endpoint" address. + +**USB Printer initialization** + +:: + + Epson = 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 with +your instance. So, assuming that we have another printer where in\_ep is +on 0x81 and out\_ep=0x02, then the printer definition should looks like: + +**Generic USB Printer initialization** + +:: + + Generic = printer.Usb(0x1a2b,0x1a2b,0,0x81,0x02) + +Network printer +^^^^^^^^^^^^^^^ + +You only need the IP of your printer, either because it is getting its +IP by DHCP or you set it manually. + +**Network Printer initialization** + +:: + + Epson = printer.Network("192.168.1.99") + +Serial printer +^^^^^^^^^^^^^^ + +Must of the default values set by the DIP switches for the serial +printers, have been set as default on the serial printer class, so the +only thing you need to know is which serial port the printer is hooked +up. + +**Serial printer initialization** + +:: + + Epson = printer.Serial("/dev/tty0") + +Other printers +^^^^^^^^^^^^^^ + +Some printers under /dev can't be used or initialized with any of the +methods described above. Usually, those are printers used by printcap, +however, if you know the device name, you could try the initialize +passing the device node name. + +:: + + Epson = 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. + +Define your instance +-------------------- + +The following example demonstrate how to initialize the Epson TM-TI88IV +on USB interface + +:: + + from escpos import * + """ Seiko Epson Corp. Receipt Printer M129 Definitions (EPSON TM-T88IV) """ + Epson = printer.Usb(0x04b8,0x0202) + # Print text + Epson.text("Hello World\n") + # Print image + Epson.image("logo.gif") + # Print QR Code + Epson.qr("You can readme from your smartphone") + # Print barcode + Epson.barcode('1324354657687','EAN13',64,2,'','') + # Cut paper + Epson.cut() + +How to update your code for USB printers +---------------------------------------- + +Old code + +:: + + Epson = escpos.Escpos(0x04b8,0x0202,0) + +New code + +:: + + Epson = printer.Usb(0x04b8,0x0202) + +Nothe that "0" which is the interface number is no longer needed. From ce0b0d5ba304eb034524a0f4865fa98979a1e9bc Mon Sep 17 00:00:00 2001 From: Patrick Kanzler Date: Sun, 27 Dec 2015 19:09:31 +0100 Subject: [PATCH 10/13] DOC improve documentation * fixes #73 * links now to readthedocs instead of Wiki --- README | 2 +- doc/user/.directory | 5 ----- doc/user/raspi.rst | 4 ++-- 3 files changed, 3 insertions(+), 8 deletions(-) delete mode 100644 doc/user/.directory diff --git a/README b/README index 2c2a41a..337de1b 100644 --- a/README +++ b/README @@ -27,7 +27,7 @@ carriage alignment. 2. Documentation Please visit project documentation at: -https://github.com/manpaz/python-escpos/wiki +https://python-escpos.readthedocs.org/en/latest ------------------------------------------------------------------ 3. Donations diff --git a/doc/user/.directory b/doc/user/.directory deleted file mode 100644 index 8e8ab5a..0000000 --- a/doc/user/.directory +++ /dev/null @@ -1,5 +0,0 @@ -[Dolphin] -HeaderColumnWidths=270,74,108 -Timestamp=2015,12,27,17,3,8 -Version=3 -ViewMode=1 diff --git a/doc/user/raspi.rst b/doc/user/raspi.rst index 77b251f..8786768 100644 --- a/doc/user/raspi.rst +++ b/doc/user/raspi.rst @@ -54,8 +54,8 @@ Installation If you have installed pyusb for libusb-1.0 then you need to: 1. Download the latest file -1. Decompress the file -1. Install the library +2. Decompress the file +3. Install the library :: From 50fbf2873fa4957490866e7445eef31514c7a56b Mon Sep 17 00:00:00 2001 From: Patrick Kanzler Date: Sun, 27 Dec 2015 19:39:22 +0100 Subject: [PATCH 11/13] DOC improve api.rst --- doc/api.rst | 50 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/doc/api.rst b/doc/api.rst index 30d3cde..a3b00b1 100644 --- a/doc/api.rst +++ b/doc/api.rst @@ -1,32 +1,46 @@ -API reference -============= +escpos package +============== -The main class and abstract implementation of an Esc/Pos printer. +Submodules +---------- + +escpos.constants module +----------------------- + +.. automodule:: escpos.constants + :members: + :undoc-members: + :show-inheritance: + +escpos.escpos module +-------------------- -escpos -====== .. automodule:: escpos.escpos :members: :undoc-members: :show-inheritance: - -printer -======= + +escpos.exceptions module +------------------------ + +.. automodule:: escpos.exceptions + :members: + :undoc-members: + :show-inheritance: + +escpos.printer module +--------------------- + .. automodule:: escpos.printer :members: :undoc-members: :show-inheritance: -exceptions -========== -.. automodule:: escpos.exceptions + +Module contents +--------------- + +.. automodule:: escpos :members: :undoc-members: :show-inheritance: - -constants -========= -.. automodule:: escpos.constants - :members: - :undoc-members: - :show-inheritance: \ No newline at end of file From e16e666dcea05bb03938cee03bc45dfdd1083e89 Mon Sep 17 00:00:00 2001 From: Patrick Kanzler Date: Sun, 27 Dec 2015 22:48:17 +0100 Subject: [PATCH 12/13] DOC fix autodoc not working on RTD --- doc/conf.py | 2 +- doc/requirements.txt | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 doc/requirements.txt diff --git a/doc/conf.py b/doc/conf.py index eae97ac..dac6859 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -18,7 +18,7 @@ import os # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. -#sys.path.insert(0, os.path.abspath('.')) +sys.path.insert(0, os.path.abspath('..')) # -- General configuration ------------------------------------------------ diff --git a/doc/requirements.txt b/doc/requirements.txt new file mode 100644 index 0000000..56c7e15 --- /dev/null +++ b/doc/requirements.txt @@ -0,0 +1,4 @@ +pyusb +Pillow>=2.0 +qrcode>=4.0 +pyserial \ No newline at end of file From 331fe6a93a300a6bdc03dc28d7c6faec23d99d1c Mon Sep 17 00:00:00 2001 From: Patrick Kanzler Date: Sun, 24 Jan 2016 15:32:54 +0100 Subject: [PATCH 13/13] version bump to 1.0.9 --- CHANGELOG | 5 +++++ setup.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 6af31fc..421a510 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -41,3 +41,8 @@ CHANGELOG . Support for images vertically longer than 256 pixels . Sent by Joel Lehtonen - Updated README + +* 2016-01-24 - Version 1.0.9 +- fix constant definition for PC1252 +- move documentation to Sphinx + diff --git a/setup.py b/setup.py index adbb97a..8c64d6a 100755 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ from distutils.core import setup setup( name='escpos', - version='1.0.8', + version='1.0.9', url='https://github.com/manpaz/python-escpos', download_url='https://github.com/manpaz/python-escpos.git', description='Python library to manipulate ESC/POS Printers',