├── doc ├── .gitignore ├── requirements.txt ├── user │ ├── todo.rst │ ├── installation.rst │ ├── dependencies.rst │ ├── printers.rst │ ├── raspi.rst │ ├── methods.rst │ └── usage.rst ├── api.rst ├── index.rst ├── Makefile ├── make.bat └── conf.py ├── escpos ├── __init__.py ├── exceptions.py ├── constants.py ├── printer.py └── escpos.py ├── .hgignore ├── MANIFEST ├── INSTALL ├── setup.py ├── CHANGELOG ├── README └── COPYING /doc/.gitignore: -------------------------------------------------------------------------------- 1 | _build 2 | -------------------------------------------------------------------------------- /doc/requirements.txt: -------------------------------------------------------------------------------- 1 | pyusb 2 | Pillow>=2.0 3 | qrcode>=4.0 4 | pyserial -------------------------------------------------------------------------------- /escpos/__init__.py: -------------------------------------------------------------------------------- 1 | __all__ = ["constants","escpos","exceptions","printer"] 2 | -------------------------------------------------------------------------------- /.hgignore: -------------------------------------------------------------------------------- 1 | # python temporary files 2 | syntax: glob 3 | *.pyc 4 | 5 | # editor autosaves 6 | $~ 7 | 8 | # temporary data 9 | syntax: regexp 10 | temp 11 | -------------------------------------------------------------------------------- /MANIFEST: -------------------------------------------------------------------------------- 1 | # file GENERATED by distutils, do NOT edit 2 | README 3 | setup.py 4 | escpos/__init__.py 5 | escpos/constants.py 6 | escpos/escpos.py 7 | escpos/exceptions.py 8 | escpos/printer.py 9 | -------------------------------------------------------------------------------- /doc/user/todo.rst: -------------------------------------------------------------------------------- 1 | **** 2 | TODO 3 | **** 4 | 5 | Introduction 6 | ------------ 7 | 8 | python-escpos is the initial idea, from here we can start to build a 9 | robust library to get most of the ESC/POS printers working with this 10 | library. 11 | 12 | Eventually, this library must be able to cover almost all the defined 13 | models detailed in the ESC/POS Command Specification Manual. 14 | 15 | Details 16 | ------- 17 | 18 | What things are planned to work on? 19 | 20 | Testing 21 | ~~~~~~~ 22 | 23 | * Test on many printers as possible (USB, Serial, Network) 24 | 25 | Design 26 | ~~~~~~ 27 | 28 | * Add all those sequences which are not common, but part of the ESC/POS 29 | Command Specifications. 30 | 31 | * Port to Python 3 32 | * Windows compatibility (hidapi instead libusb?) 33 | * PDF417 support 34 | 35 | 36 | -------------------------------------------------------------------------------- /INSTALL: -------------------------------------------------------------------------------- 1 | python-escpos 2 | ============= 3 | 4 | Ensure the library is installed on ${lib_arch}/${python_ver}/site-packages/escpos 5 | 6 | On CLi you must run: 7 | # python setup.py build 8 | # sudo python setup.py install 9 | 10 | On Linux, ensure you belongs to the proper group so you can have access to the printer. 11 | This can be done, by adding yourself to 'dialout' group, this might require to re-login 12 | so the changes make effect. 13 | 14 | Then, add the following rule to /etc/udev/rules.d/99-escpos.rules 15 | SUBSYSTEM=="usb", ATTRS{idVendor}=="04b8", ATTRS{idProduct}=="0202", MODE="0664", GROUP="dialout" 16 | 17 | and restar udev rules. 18 | # sudo service udev restart 19 | 20 | Enjoy !!! 21 | And please, don't forget to ALWAYS add Epson.cut() at the end of your printing :) 22 | 23 | Manuel F Martinez 24 | -------------------------------------------------------------------------------- /doc/api.rst: -------------------------------------------------------------------------------- 1 | escpos package 2 | ============== 3 | 4 | Submodules 5 | ---------- 6 | 7 | escpos.constants module 8 | ----------------------- 9 | 10 | .. automodule:: escpos.constants 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | escpos.escpos module 16 | -------------------- 17 | 18 | .. automodule:: escpos.escpos 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | escpos.exceptions module 24 | ------------------------ 25 | 26 | .. automodule:: escpos.exceptions 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | 31 | escpos.printer module 32 | --------------------- 33 | 34 | .. automodule:: escpos.printer 35 | :members: 36 | :undoc-members: 37 | :show-inheritance: 38 | 39 | 40 | Module contents 41 | --------------- 42 | 43 | .. automodule:: escpos 44 | :members: 45 | :undoc-members: 46 | :show-inheritance: 47 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | from distutils.core import setup 4 | 5 | setup( 6 | name='escpos', 7 | version='1.0.9', 8 | url='https://github.com/manpaz/python-escpos', 9 | download_url='https://github.com/manpaz/python-escpos.git', 10 | description='Python library to manipulate ESC/POS Printers', 11 | license='GNU GPL v3', 12 | long_description=open('README').read(), 13 | author='Manuel F Martinez', 14 | author_email='manpaz@bashlinux.com', 15 | platforms=['linux'], 16 | packages=[ 17 | 'escpos', 18 | ], 19 | package_data={'': ['COPYING']}, 20 | classifiers=[ 21 | 'Development Status :: 1 - Alpha', 22 | 'License :: OSI Approved :: GNU GPL v3', 23 | 'Operating System :: GNU/Linux', 24 | 'Intended Audience :: Developers', 25 | 'Programming Language :: Python', 26 | 'Topic :: System :: Pheripherals', 27 | 'Topic :: Software Development :: Libraries :: Python Modules', 28 | ], 29 | ) 30 | -------------------------------------------------------------------------------- /doc/user/installation.rst: -------------------------------------------------------------------------------- 1 | ************ 2 | Installation 3 | ************ 4 | 5 | System preparation 6 | ------------------ 7 | 8 | 1. Install the required 9 | `dependencies `__ 10 | 11 | 2. Get the *Product ID* and *Vendor ID* from the lsusb command 12 | ``# lsusb Bus 002 Device 001: ID 1a2b:1a2b Device name`` 13 | 14 | 3. Create a udev rule to let users belonging to *dialout* group use the 15 | printer. You can create the file 16 | ``/etc/udev/rules.d/99-escpos.rules`` and add the following: 17 | ``SUBSYSTEM=="usb", ATTRS{idVendor}=="1a2b", ATTRS{idProduct}=="1a2b", MODE="0664", GROUP="dialout"`` 18 | Replace *idVendor* and *idProduct* hex numbers with the ones that you 19 | got from the previous step. Note that you can either, add yourself to 20 | "dialout" group, or use another group you already belongs instead 21 | "dialout" and set it in the ``GROUP`` parameter in the above rule. 22 | 23 | 4. Restart udev ``# sudo service udev restart`` In some new systems it 24 | is done with ``# sudo udevadm control --reload`` 25 | 26 | Install 27 | ------- 28 | 29 | * Clone python-escpos from github 30 | * Change directory to python-escpos and install the package 31 | 32 | :: 33 | 34 | # cd python-escpos 35 | # python setup.py build 36 | # sudo python setup.py install 37 | 38 | * Enjoy !!! 39 | 40 | 41 | -------------------------------------------------------------------------------- /doc/user/dependencies.rst: -------------------------------------------------------------------------------- 1 | ************ 2 | Dependencies 3 | ************ 4 | 5 | Fedora 6 | ------ 7 | 8 | Fortunately everything is on Fedora repositories. 9 | 10 | :: 11 | 12 | # yum install python-imaging pyserial pyusb python-qrcode 13 | 14 | Ubuntu 15 | ------ 16 | 17 | Ultimately, this instructions also apply to Raspbian, in case you are 18 | interested to install python-escpos on your Raspberry with Raspbian. 19 | 20 | Install the packages available on distro repositories. 21 | 22 | :: 23 | 24 | # apt-get install python-imaging pyserial 25 | 26 | The packages which are not available at Ubuntu repositories need to be 27 | installed manually. 28 | 29 | pyusb 30 | ^^^^^ 31 | This is the python binding to libusb-1.0 32 | 33 | * Get the latest tarball from `sourceforge `__ 34 | * Build and install it 35 | 36 | :: 37 | 38 | # tar zxvf pyusb-1.*.tar.gz 39 | # cd pyusb-1.* 40 | # python setup.py build 41 | # sudo python setup.py install 42 | 43 | python-qrcode 44 | ^^^^^^^^^^^^^ 45 | 46 | This is the python module to generate QR Codes 47 | 48 | * Checkout the latest code from `github `__ 49 | * Build and install it 50 | 51 | :: 52 | 53 | # git clone https://github.com/lincolnloop/python-qrcode 54 | # cd python-qrcode 55 | # python setup.py build 56 | # sudo python setup.py install 57 | 58 | -------------------------------------------------------------------------------- /doc/user/printers.rst: -------------------------------------------------------------------------------- 1 | ******** 2 | Printers 3 | ******** 4 | 5 | .. note:: **TODO** Merge this page into the API-description. 6 | 7 | There 3 different type of printers: 8 | 9 | USB(idVendor, idProduct, interface, in\_ep, out\_ep) 10 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11 | 12 | Based on pyusb and libusb-1.0 13 | 14 | * ``idVendor`` is the Vendor ID 15 | * ``idProduct`` is the Product ID 16 | * ``interface`` is the USB device interface (default = 0) 17 | * ``in_ep`` is the input end point (default = 0x82) 18 | * ``out_ep`` is the output end point (default = 0x01) 19 | 20 | Serial("devfile", baudrate, bytesize, timeout) 21 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22 | 23 | Based on pyserial, default values are based on the defaults set by 24 | DIP\_SWITCH\_1 on the documentation(hardware side). 25 | 26 | * ``devfile`` is an alphanumeric device file name under /dev filesystem (default = /ev/ttyS0) 27 | * ``baudrate`` is the Baud rate for serial transmission (default = 9600) 28 | * ``bytesize`` sets the serial buffer size (default = 8) 29 | * ``timeout`` defines Read/Write timeout (default = 1) 30 | 31 | Network("host", port) 32 | ^^^^^^^^^^^^^^^^^^^^^ 33 | 34 | Based on socket 35 | * ``host`` is an alphanumeric host name, could be either DNS host name or IP address. 36 | * ``port`` to write to (default = 9100) 37 | 38 | File("file\_name") 39 | ^^^^^^^^^^^^^^^^^^ 40 | 41 | Printcap printers 42 | * ``file_name`` is the full path to the device file name 43 | -------------------------------------------------------------------------------- /CHANGELOG: -------------------------------------------------------------------------------- 1 | CHANGELOG 2 | 3 | * 2012-11-15 - Version 1.0 4 | - Issue #2: Added ethernet support 5 | - Issue #3: Added compatibility with libusb-1.0.1 6 | - Issue #4: Fixed typo in escpos.py 7 | 8 | * 2013-03-14 - Version 1.0.1 9 | - Issue #8: Fixed set font 10 | - Added QR support 11 | 12 | * 2013-12-30 - Version 1.0.2 13 | - Issue #5: Fixed vertical tab 14 | - Issue #9: Fixed identation inconsistence 15 | 16 | * 2014-02-23 - Version 1.0.3 17 | - Issue #18: Added quad-area characters (Sent by syncman1x@gmail.com) 18 | - Added exception for PIL import 19 | 20 | * 2014-05-20 - Version 1.0.4 21 | - Issue #20: Added Density support (Sent by thomas.erbacher@ragapack.de) 22 | - Added charcode tables 23 | - Fixed Horizontal Tab 24 | - Fixed code tabulators 25 | 26 | * 2015-04-21 - Version 1.0.5 27 | - Merge pull request #45 from Krispy2009/master 28 | . Raising the right error when wrong charcode is used 29 | . Sent by Kristi 30 | 31 | * 2015-07-06 - Version 1.0.6 32 | - Merge pull request #53 from ldos/master 33 | . Extended params for serial printers 34 | . Sent by ldos 35 | 36 | * 2015-08-22 - Version 1.0.7 37 | - Issue #57: Fixed transparent images 38 | 39 | * 2015-10-27 - Version 1.0.8 40 | - Merge pull request #59 from zouppen/master 41 | . Support for images vertically longer than 256 pixels 42 | . Sent by Joel Lehtonen 43 | - Updated README 44 | 45 | * 2016-01-24 - Version 1.0.9 46 | - fix constant definition for PC1252 47 | - move documentation to Sphinx 48 | 49 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | ESCPOS 2 | ====== 3 | 4 | Python library to manipulate ESC/POS Printers. 5 | 6 | ------------------------------------------------------------------ 7 | 1. Description 8 | 9 | Python ESC/POS is a library which lets the user have access to all 10 | those printers handled by ESC/POS commands, as defined by Epson, 11 | from a Python application. 12 | 13 | The standard usage is send raw text to the printer, but in also 14 | helps the user to enhance the experience with those printers by 15 | facilitating the bar code printing in many different standards, 16 | as well as manipulating images so they can be printed as brand 17 | logo or any other usage images migh have. 18 | 19 | Text can be aligned/justified and fonts can be changed by size, 20 | type and weight. 21 | 22 | Also, this module handles some hardware functionalities like, cut 23 | paper, carrier return, printer reset and others concerned to the 24 | carriage alignment. 25 | 26 | ------------------------------------------------------------------ 27 | 2. Documentation 28 | 29 | Please visit project documentation at: 30 | https://python-escpos.readthedocs.org/en/latest 31 | 32 | ------------------------------------------------------------------ 33 | 3. Donations 34 | 35 | There are some different prints I'd like to acquire, but unfortunately 36 | not all, even used, are cheaper and easy to get. 37 | 38 | If you want to help funding money to get more printers or just want to 39 | donate because you like the project, please be in touch and I'll be 40 | sending my PayPal info so you can donate. 41 | 42 | Thank you! 43 | 44 | Manuel F Martinez 45 | 46 | -------------------------------------------------------------------------------- /doc/user/raspi.rst: -------------------------------------------------------------------------------- 1 | ************ 2 | Raspberry Pi 3 | ************ 4 | 5 | This instructions were tested on Raspbian. 6 | 7 | Unless you have done any distro with libusb-1.0 on the Raspberry Pi, the 8 | following instructions should works fine on your raspberry distro. 9 | 10 | Dependencies 11 | ------------ 12 | 13 | First, install the packages available on Raspbian. 14 | 15 | :: 16 | 17 | # apt-get install python-imaging python-serial python-setuptools 18 | 19 | PyUSB 20 | ^^^^^ 21 | 22 | PyUSB 1.0 is not available on Ubuntu, so you have to download and 23 | install it manually 24 | 25 | 1. Download the latest tarball from 26 | `Sourceforge `__ 27 | 2. Decompress the zip file 28 | 3. Install the library 29 | 30 | :: 31 | 32 | # wget ... 33 | # unzip pyusb*.zip 34 | # cd pyusb* 35 | # python setup.py build 36 | # sudo python setup.py install 37 | 38 | python-qrcode 39 | ^^^^^^^^^^^^^ 40 | 41 | 1. Checkout the code from github 42 | 2. Install the library 43 | 44 | :: 45 | 46 | # git clone https://github.com/lincolnloop/python-qrcode 47 | # cd python-qrcode 48 | # python setup.py build 49 | # sudo python setup.py install 50 | 51 | Installation 52 | ------------ 53 | 54 | If you have installed pyusb for libusb-1.0 then you need to: 55 | 56 | 1. Download the latest file 57 | 2. Decompress the file 58 | 3. Install the library 59 | 60 | :: 61 | 62 | # git clone https://github.com/manpaz/python-escpos.git 63 | # cd python-escpos 64 | # python setup.py build 65 | # sudo python setup.py install 66 | 67 | Now you can attach your printer and and test it with the example code in 68 | the project's `home `__ 69 | -------------------------------------------------------------------------------- /doc/index.rst: -------------------------------------------------------------------------------- 1 | .. python-escpos documentation master file, created by 2 | sphinx-quickstart on Sat Dec 26 14:28:42 2015. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Welcome to python-escpos's documentation! 7 | ========================================= 8 | 9 | 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. 10 | 11 | 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. 12 | 13 | Text can be justified and fonts can be changed by size, type and weight. 14 | 15 | Also, this module handles some hardware functionalists like, cut paper, cash drawer kicking, printer reset, carriage return and others concerned to the carriage alignment. 16 | 17 | ------------ 18 | 19 | There are some different printers I'd like to acquire, unfortunately 20 | not all, even used, are cheaper and easy to get. 21 | 22 | If you want to help funding money to get more printers or just want to 23 | donate because you like the project, please be in touch and I'll be 24 | sending my PayPal info so you can donate. 25 | 26 | Thank you! 27 | 28 | User Documentation: 29 | ------------------- 30 | 31 | .. toctree:: 32 | :maxdepth: 1 33 | 34 | user/dependencies 35 | user/installation 36 | user/methods 37 | user/printers 38 | user/raspi 39 | user/todo 40 | user/usage 41 | 42 | API: 43 | ---- 44 | 45 | .. toctree:: 46 | :maxdepth: 1 47 | 48 | api 49 | 50 | Indices and tables 51 | ================== 52 | 53 | * :ref:`genindex` 54 | * :ref:`modindex` 55 | * :ref:`search` 56 | 57 | -------------------------------------------------------------------------------- /escpos/exceptions.py: -------------------------------------------------------------------------------- 1 | """ ESC/POS Exceptions classes """ 2 | 3 | import os 4 | 5 | class Error(Exception): 6 | """ Base class for ESC/POS errors """ 7 | def __init__(self, msg, status=None): 8 | Exception.__init__(self) 9 | self.msg = msg 10 | self.resultcode = 1 11 | if status is not None: 12 | self.resultcode = status 13 | 14 | def __str__(self): 15 | return self.msg 16 | 17 | # Result/Exit codes 18 | # 0 = success 19 | # 10 = No Barcode type defined 20 | # 20 = Barcode size values are out of range 21 | # 30 = Barcode text not supplied 22 | # 40 = Image height is too large 23 | # 50 = No string supplied to be printed 24 | # 60 = Invalid pin to send Cash Drawer pulse 25 | # 70 = Invalid number of tab positions 26 | # 80 = Invalid char code 27 | 28 | 29 | class BarcodeTypeError(Error): 30 | def __init__(self, msg=""): 31 | Error.__init__(self, msg) 32 | self.msg = msg 33 | self.resultcode = 10 34 | 35 | def __str__(self): 36 | return "No Barcode type is defined" 37 | 38 | class BarcodeSizeError(Error): 39 | def __init__(self, msg=""): 40 | Error.__init__(self, msg) 41 | self.msg = msg 42 | self.resultcode = 20 43 | 44 | def __str__(self): 45 | return "Barcode size is out of range" 46 | 47 | class BarcodeCodeError(Error): 48 | def __init__(self, msg=""): 49 | Error.__init__(self, msg) 50 | self.msg = msg 51 | self.resultcode = 30 52 | 53 | def __str__(self): 54 | return "Code was not supplied" 55 | 56 | class ImageSizeError(Error): 57 | def __init__(self, msg=""): 58 | Error.__init__(self, msg) 59 | self.msg = msg 60 | self.resultcode = 40 61 | 62 | def __str__(self): 63 | return "Image height is longer than 255px and can't be printed" 64 | 65 | class TextError(Error): 66 | def __init__(self, msg=""): 67 | Error.__init__(self, msg) 68 | self.msg = msg 69 | self.resultcode = 50 70 | 71 | def __str__(self): 72 | return "Text string must be supplied to the text() method" 73 | 74 | 75 | class CashDrawerError(Error): 76 | def __init__(self, msg=""): 77 | Error.__init__(self, msg) 78 | self.msg = msg 79 | self.resultcode = 60 80 | 81 | def __str__(self): 82 | return "Valid pin must be set to send pulse" 83 | 84 | 85 | class TabError(Error): 86 | def __init__(self, msg=""): 87 | Error.__init__(self, msg) 88 | self.msg = msg 89 | self.resultcode = 70 90 | 91 | def __str__(self): 92 | return "Valid tab positions must be in the range 0 to 16" 93 | 94 | 95 | class CharCodeError(Error): 96 | def __init__(self, msg=""): 97 | Error.__init__(self, msg) 98 | self.msg = msg 99 | self.resultcode = 70 100 | 101 | def __str__(self): 102 | return "Valid char code must be set" 103 | -------------------------------------------------------------------------------- /doc/user/methods.rst: -------------------------------------------------------------------------------- 1 | ******* 2 | Methods 3 | ******* 4 | 5 | .. note:: **TODO** Merge this page into the API-description. 6 | 7 | Escpos class 8 | ------------ 9 | 10 | Escpos inherits its methods to the printers. the following methods are 11 | defined: 12 | 13 | image("image\_name.ext") 14 | ^^^^^^^^^^^^^^^^^^^^^^^^ 15 | 16 | Prints an image. Its adjust the size in order to print it. 17 | 18 | * ``image_name.ext`` is the complete file name and location of any image type (jpg, gif, png, bmp) 19 | 20 | Raises ``ImageSizeError`` exception. 21 | 22 | qr("text") 23 | ^^^^^^^^^^ 24 | 25 | Prints a QR code. The size has been adjusted to Version 4, so it can be 26 | enough small to be printed but also enough big to be read by a smart 27 | phone. 28 | 29 | * ``text`` Any text that needs to be QR encoded. It could be a slogan, 30 | salutation, url, etc. 31 | 32 | barcode("code", "barcode\_type", width, height, "position", "font") 33 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 34 | 35 | Prints a barcode. 36 | 37 | * ``code`` is an alphanumeric code to be printed as bar code 38 | * ``barcode_type`` must be one of the following type of codes: 39 | 40 | * UPC-A 41 | * UPC-E 42 | * EAN13 43 | * EAN8 44 | * CODE39 45 | * ITF 46 | * NW7 47 | 48 | * ``width`` is a numeric value in the range between (1,255) *Default:* 64 49 | * ``height`` is a numeric value in the range between (2,6) *Default:* 3 50 | * ``position`` is where to place the code around the bars, could be one of the following values: 51 | 52 | * ABOVE 53 | * BELOW 54 | * BOTH 55 | * OFF > *Default:* BELOW 56 | 57 | * ``font`` is one of the 2 type of fonts, values could be: 58 | 59 | * A 60 | * B > *Default:* A Raises ``BarcodeTypeError``, ``BarcodeSizeError``, ``BarcodeCodeError`` exceptions. 61 | 62 | text("text") 63 | ^^^^^^^^^^^^ 64 | 65 | Prints raw text. Raises ``TextError`` exception. 66 | 67 | set("align", "font", "type", width, height) 68 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 69 | 70 | Set text properties. 71 | * ``align`` set horizontal position for text, the possible values are: 72 | 73 | * CENTER 74 | * LEFT 75 | * RIGHT > > *Default:* left 76 | 77 | * ``font`` type could be ``A`` or ``B``. *Default:* A 78 | * ``type`` type could be ``B`` (Bold), ``U`` (Underline) or ``normal``. *Default:* normal 79 | * ``width`` is a numeric value, 1 is for regular size, and 2 is twice the standard size. *Default*: 1 80 | * ``height`` is a numeric value, 1 is for regular size and 2 is twice the standard size. *Default*: 1 81 | 82 | cut("mode") 83 | ^^^^^^^^^^^ 84 | 85 | Cut paper. 86 | * ``mode`` set a full or partial cut. *Default:* full 87 | 88 | **Partial cut is not implemented in all printers.** 89 | 90 | cashdraw(pin) 91 | ^^^^^^^^^^^^^ 92 | 93 | Sends a pulse to the cash drawer in the specified pin. 94 | 95 | * ``pin`` is a numeric value which defines the pin to be used to send the pulse, it could be 2 or 5. Raises ``CashDrawerError()`` 96 | 97 | hw("operation") 98 | ^^^^^^^^^^^^^^^ 99 | 100 | Hardware operations. 101 | 102 | * ``operation`` is any of the following options: 103 | 104 | * INIT 105 | * SELECT 106 | * RESET 107 | 108 | control("align") 109 | ^^^^^^^^^^^^^^^^ 110 | 111 | Carrier feed and tabs. 112 | * ``align`` is a string which takes any of the following values: 113 | 114 | * LF *for Line Feed* 115 | * FF *for Form Feed* 116 | * CR *for Carriage Return* 117 | * HT *for Horizontal Tab* 118 | * VT *for Vertical Tab* 119 | -------------------------------------------------------------------------------- /doc/user/usage.rst: -------------------------------------------------------------------------------- 1 | ***** 2 | Usage 3 | ***** 4 | 5 | Define your printer 6 | ------------------- 7 | 8 | USB printer 9 | ^^^^^^^^^^^ 10 | 11 | Before start creating your Python ESC/POS printer instance, you must see 12 | at your system for the printer parameters. This is done with the 'lsusb' 13 | command. 14 | 15 | First run the command to look for the "Vendor ID" and "Product ID", then 16 | write down the values, these values are displayed just before the name 17 | of the device with the following format: 18 | 19 | :: 20 | 21 | xxxx:xxxx 22 | 23 | Example: 24 | 25 | :: 26 | 27 | # lsusb 28 | Bus 002 Device 001: ID 04b8:0202 Epson ... 29 | 30 | Write down the the values in question, then issue the following command 31 | so you can get the "Interface" number and "End Point" 32 | 33 | :: 34 | 35 | # lsusb -vvv -d xxxx:xxxx | grep iInterface 36 | iInterface 0 37 | # lsusb -vvv -d xxxx:xxxx | grep bEndpointAddress | grep OUT 38 | bEndpointAddress 0x01 EP 1 OUT 39 | 40 | The first command will yields the "Interface" number that must be handy 41 | to have and the second yields the "Output Endpoint" address. 42 | 43 | **USB Printer initialization** 44 | 45 | :: 46 | 47 | Epson = printer.Usb(0x04b8,0x0202) 48 | 49 | By default the "Interface" number is "0" and the "Output Endpoint" 50 | address is "0x01", if you have other values then you can define with 51 | your instance. So, assuming that we have another printer where in\_ep is 52 | on 0x81 and out\_ep=0x02, then the printer definition should looks like: 53 | 54 | **Generic USB Printer initialization** 55 | 56 | :: 57 | 58 | Generic = printer.Usb(0x1a2b,0x1a2b,0,0x81,0x02) 59 | 60 | Network printer 61 | ^^^^^^^^^^^^^^^ 62 | 63 | You only need the IP of your printer, either because it is getting its 64 | IP by DHCP or you set it manually. 65 | 66 | **Network Printer initialization** 67 | 68 | :: 69 | 70 | Epson = printer.Network("192.168.1.99") 71 | 72 | Serial printer 73 | ^^^^^^^^^^^^^^ 74 | 75 | Must of the default values set by the DIP switches for the serial 76 | printers, have been set as default on the serial printer class, so the 77 | only thing you need to know is which serial port the printer is hooked 78 | up. 79 | 80 | **Serial printer initialization** 81 | 82 | :: 83 | 84 | Epson = printer.Serial("/dev/tty0") 85 | 86 | Other printers 87 | ^^^^^^^^^^^^^^ 88 | 89 | Some printers under /dev can't be used or initialized with any of the 90 | methods described above. Usually, those are printers used by printcap, 91 | however, if you know the device name, you could try the initialize 92 | passing the device node name. 93 | 94 | :: 95 | 96 | Epson = printer.File("/dev/usb/lp1") 97 | 98 | The default is "/dev/usb/lp0", so if the printer is located on that 99 | node, then you don't necessary need to pass the node name. 100 | 101 | Define your instance 102 | -------------------- 103 | 104 | The following example demonstrate how to initialize the Epson TM-TI88IV 105 | on USB interface 106 | 107 | :: 108 | 109 | from escpos import * 110 | """ Seiko Epson Corp. Receipt Printer M129 Definitions (EPSON TM-T88IV) """ 111 | Epson = printer.Usb(0x04b8,0x0202) 112 | # Print text 113 | Epson.text("Hello World\n") 114 | # Print image 115 | Epson.image("logo.gif") 116 | # Print QR Code 117 | Epson.qr("You can readme from your smartphone") 118 | # Print barcode 119 | Epson.barcode('1324354657687','EAN13',64,2,'','') 120 | # Cut paper 121 | Epson.cut() 122 | 123 | How to update your code for USB printers 124 | ---------------------------------------- 125 | 126 | Old code 127 | 128 | :: 129 | 130 | Epson = escpos.Escpos(0x04b8,0x0202,0) 131 | 132 | New code 133 | 134 | :: 135 | 136 | Epson = printer.Usb(0x04b8,0x0202) 137 | 138 | Nothe that "0" which is the interface number is no longer needed. 139 | -------------------------------------------------------------------------------- /escpos/constants.py: -------------------------------------------------------------------------------- 1 | """ ESC/POS Commands (Constants) """ 2 | 3 | # Feed control sequences 4 | CTL_LF = '\x0a' # Print and line feed 5 | CTL_FF = '\x0c' # Form feed 6 | CTL_CR = '\x0d' # Carriage return 7 | CTL_HT = '\x09' # Horizontal tab 8 | CTL_SET_HT = '\x1b\x44' # Set horizontal tab positions 9 | CTL_VT = '\x1b\x64\x04' # Vertical tab 10 | # Printer hardware 11 | HW_INIT = '\x1b\x40' # Clear data in buffer and reset modes 12 | HW_SELECT = '\x1b\x3d\x01' # Printer select 13 | HW_RESET = '\x1b\x3f\x0a\x00' # Reset printer hardware 14 | # Cash Drawer 15 | CD_KICK_2 = '\x1b\x70\x00' # Sends a pulse to pin 2 [] 16 | CD_KICK_5 = '\x1b\x70\x01' # Sends a pulse to pin 5 [] 17 | # Paper 18 | PAPER_FULL_CUT = '\x1d\x56\x00' # Full cut paper 19 | PAPER_PART_CUT = '\x1d\x56\x01' # Partial cut paper 20 | # Text format 21 | TXT_NORMAL = '\x1b\x21\x00' # Normal text 22 | TXT_2HEIGHT = '\x1b\x21\x10' # Double height text 23 | TXT_2WIDTH = '\x1b\x21\x20' # Double width text 24 | TXT_4SQUARE = '\x1b\x21\x30' # Quad area text 25 | TXT_UNDERL_OFF = '\x1b\x2d\x00' # Underline font OFF 26 | TXT_UNDERL_ON = '\x1b\x2d\x01' # Underline font 1-dot ON 27 | TXT_UNDERL2_ON = '\x1b\x2d\x02' # Underline font 2-dot ON 28 | TXT_BOLD_OFF = '\x1b\x45\x00' # Bold font OFF 29 | TXT_BOLD_ON = '\x1b\x45\x01' # Bold font ON 30 | TXT_FONT_A = '\x1b\x4d\x00' # Font type A 31 | TXT_FONT_B = '\x1b\x4d\x01' # Font type B 32 | TXT_ALIGN_LT = '\x1b\x61\x00' # Left justification 33 | TXT_ALIGN_CT = '\x1b\x61\x01' # Centering 34 | TXT_ALIGN_RT = '\x1b\x61\x02' # Right justification 35 | # Char code table 36 | CHARCODE_PC437 = '\x1b\x74\x00' # USA: Standard Europe 37 | CHARCODE_JIS = '\x1b\x74\x01' # Japanese Katakana 38 | CHARCODE_PC850 = '\x1b\x74\x02' # Multilingual 39 | CHARCODE_PC860 = '\x1b\x74\x03' # Portuguese 40 | CHARCODE_PC863 = '\x1b\x74\x04' # Canadian-French 41 | CHARCODE_PC865 = '\x1b\x74\x05' # Nordic 42 | CHARCODE_WEU = '\x1b\x74\x06' # Simplified Kanji, Hirakana 43 | CHARCODE_GREEK = '\x1b\x74\x07' # Simplified Kanji 44 | CHARCODE_HEBREW = '\x1b\x74\x08' # Simplified Kanji 45 | CHARCODE_PC1252 = '\x1b\x74\x10' # Western European Windows Code Set 46 | CHARCODE_PC866 = '\x1b\x74\x12' # Cirillic #2 47 | CHARCODE_PC852 = '\x1b\x74\x13' # Latin 2 48 | CHARCODE_PC858 = '\x1b\x74\x14' # Euro 49 | CHARCODE_THAI42 = '\x1b\x74\x15' # Thai character code 42 50 | CHARCODE_THAI11 = '\x1b\x74\x16' # Thai character code 11 51 | CHARCODE_THAI13 = '\x1b\x74\x17' # Thai character code 13 52 | CHARCODE_THAI14 = '\x1b\x74\x18' # Thai character code 14 53 | CHARCODE_THAI16 = '\x1b\x74\x19' # Thai character code 16 54 | CHARCODE_THAI17 = '\x1b\x74\x1a' # Thai character code 17 55 | CHARCODE_THAI18 = '\x1b\x74\x1b' # Thai character code 18 56 | # Barcode format 57 | BARCODE_TXT_OFF = '\x1d\x48\x00' # HRI barcode chars OFF 58 | BARCODE_TXT_ABV = '\x1d\x48\x01' # HRI barcode chars above 59 | BARCODE_TXT_BLW = '\x1d\x48\x02' # HRI barcode chars below 60 | BARCODE_TXT_BTH = '\x1d\x48\x03' # HRI barcode chars both above and below 61 | BARCODE_FONT_A = '\x1d\x66\x00' # Font type A for HRI barcode chars 62 | BARCODE_FONT_B = '\x1d\x66\x01' # Font type B for HRI barcode chars 63 | BARCODE_HEIGHT = '\x1d\x68\x64' # Barcode Height [1-255] 64 | BARCODE_WIDTH = '\x1d\x77\x03' # Barcode Width [2-6] 65 | BARCODE_UPC_A = '\x1d\x6b\x00' # Barcode type UPC-A 66 | BARCODE_UPC_E = '\x1d\x6b\x01' # Barcode type UPC-E 67 | BARCODE_EAN13 = '\x1d\x6b\x02' # Barcode type EAN13 68 | BARCODE_EAN8 = '\x1d\x6b\x03' # Barcode type EAN8 69 | BARCODE_CODE39 = '\x1d\x6b\x04' # Barcode type CODE39 70 | BARCODE_ITF = '\x1d\x6b\x05' # Barcode type ITF 71 | BARCODE_NW7 = '\x1d\x6b\x06' # Barcode type NW7 72 | # Image format 73 | S_RASTER_N = '\x1d\x76\x30\x00' # Set raster image normal size 74 | S_RASTER_2W = '\x1d\x76\x30\x01' # Set raster image double width 75 | S_RASTER_2H = '\x1d\x76\x30\x02' # Set raster image double height 76 | S_RASTER_Q = '\x1d\x76\x30\x03' # Set raster image quadruple 77 | # Printing Density 78 | PD_N50 = '\x1d\x7c\x00' # Printing Density -50% 79 | PD_N37 = '\x1d\x7c\x01' # Printing Density -37.5% 80 | PD_N25 = '\x1d\x7c\x02' # Printing Density -25% 81 | PD_N12 = '\x1d\x7c\x03' # Printing Density -12.5% 82 | PD_0 = '\x1d\x7c\x04' # Printing Density 0% 83 | PD_P50 = '\x1d\x7c\x08' # Printing Density +50% 84 | PD_P37 = '\x1d\x7c\x07' # Printing Density +37.5% 85 | PD_P25 = '\x1d\x7c\x06' # Printing Density +25% 86 | PD_P12 = '\x1d\x7c\x05' # Printing Density +12.5% 87 | -------------------------------------------------------------------------------- /escpos/printer.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | """ 3 | @author: Manuel F Martinez 4 | @organization: Bashlinux 5 | @copyright: Copyright (c) 2012 Bashlinux 6 | @license: GNU GPL v3 7 | """ 8 | 9 | import usb.core 10 | import usb.util 11 | import serial 12 | import socket 13 | 14 | from escpos import * 15 | from constants import * 16 | from exceptions import * 17 | 18 | class Usb(Escpos): 19 | """ Define USB printer """ 20 | 21 | def __init__(self, idVendor, idProduct, interface=0, in_ep=0x82, out_ep=0x01): 22 | """ 23 | @param idVendor : Vendor ID 24 | @param idProduct : Product ID 25 | @param interface : USB device interface 26 | @param in_ep : Input end point 27 | @param out_ep : Output end point 28 | """ 29 | self.idVendor = idVendor 30 | self.idProduct = idProduct 31 | self.interface = interface 32 | self.in_ep = in_ep 33 | self.out_ep = out_ep 34 | self.open() 35 | 36 | 37 | def open(self): 38 | """ Search device on USB tree and set is as escpos device """ 39 | self.device = usb.core.find(idVendor=self.idVendor, idProduct=self.idProduct) 40 | if self.device is None: 41 | print "Cable isn't plugged in" 42 | 43 | check_driver = None 44 | 45 | try: 46 | check_driver = self.device.is_kernel_driver_active(0) 47 | except NotImplementedError: 48 | pass 49 | 50 | if check_driver is None or check_driver: 51 | try: 52 | self.device.detach_kernel_driver(0) 53 | except usb.core.USBError as e: 54 | if check_driver is not None: 55 | print "Could not detatch kernel driver: %s" % str(e) 56 | 57 | try: 58 | self.device.set_configuration() 59 | self.device.reset() 60 | except usb.core.USBError as e: 61 | print "Could not set configuration: %s" % str(e) 62 | 63 | 64 | def _raw(self, msg): 65 | """ Print any command sent in raw format """ 66 | self.device.write(self.out_ep, msg, self.interface) 67 | 68 | 69 | def __del__(self): 70 | """ Release USB interface """ 71 | if self.device: 72 | usb.util.dispose_resources(self.device) 73 | self.device = None 74 | 75 | 76 | 77 | class Serial(Escpos): 78 | """ Define Serial printer """ 79 | 80 | def __init__(self, devfile="/dev/ttyS0", baudrate=9600, bytesize=8, timeout=1, 81 | parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, 82 | xonxoff=False , dsrdtr=True): 83 | """ 84 | @param devfile : Device file under dev filesystem 85 | @param baudrate : Baud rate for serial transmission 86 | @param bytesize : Serial buffer size 87 | @param timeout : Read/Write timeout 88 | 89 | @param parity : Parity checking 90 | @param stopbits : Number of stop bits 91 | @param xonxoff : Software flow control 92 | @param dsrdtr : Hardware flow control (False to enable RTS/CTS) 93 | """ 94 | self.devfile = devfile 95 | self.baudrate = baudrate 96 | self.bytesize = bytesize 97 | self.timeout = timeout 98 | 99 | self.parity = parity 100 | self.stopbits = stopbits 101 | self.xonxoff = xonxoff 102 | self.dsrdtr = dsrdtr 103 | 104 | self.open() 105 | 106 | 107 | def open(self): 108 | """ Setup serial port and set is as escpos device """ 109 | self.device = serial.Serial(port=self.devfile, baudrate=self.baudrate, 110 | bytesize=self.bytesize, parity=self.parity, 111 | stopbits=self.stopbits, timeout=self.timeout, 112 | xonxoff=self.xonxoff, dsrdtr=self.dsrdtr) 113 | 114 | if self.device is not None: 115 | print "Serial printer enabled" 116 | else: 117 | print "Unable to open serial printer on: %s" % self.devfile 118 | 119 | 120 | def _raw(self, msg): 121 | """ Print any command sent in raw format """ 122 | self.device.write(msg) 123 | 124 | 125 | def __del__(self): 126 | """ Close Serial interface """ 127 | if self.device is not None: 128 | self.device.close() 129 | 130 | 131 | 132 | class Network(Escpos): 133 | """ Define Network printer """ 134 | 135 | def __init__(self,host,port=9100): 136 | """ 137 | @param host : Printer's hostname or IP address 138 | @param port : Port to write to 139 | """ 140 | self.host = host 141 | self.port = port 142 | self.open() 143 | 144 | 145 | def open(self): 146 | """ Open TCP socket and set it as escpos device """ 147 | self.device = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 148 | self.device.connect((self.host, self.port)) 149 | 150 | if self.device is None: 151 | print "Could not open socket for %s" % self.host 152 | 153 | 154 | def _raw(self, msg): 155 | """ Print any command sent in raw format """ 156 | self.device.send(msg) 157 | 158 | 159 | def __del__(self): 160 | """ Close TCP connection """ 161 | self.device.close() 162 | 163 | 164 | 165 | class File(Escpos): 166 | """ Define Generic file printer """ 167 | 168 | def __init__(self, devfile="/dev/usb/lp0"): 169 | """ 170 | @param devfile : Device file under dev filesystem 171 | """ 172 | self.devfile = devfile 173 | self.open() 174 | 175 | 176 | def open(self): 177 | """ Open system file """ 178 | self.device = open(self.devfile, "wb") 179 | 180 | if self.device is None: 181 | print "Could not open the specified file %s" % self.devfile 182 | 183 | 184 | def _raw(self, msg): 185 | """ Print any command sent in raw format """ 186 | self.device.write(msg); 187 | 188 | 189 | def __del__(self): 190 | """ Close system file """ 191 | self.device.close() 192 | -------------------------------------------------------------------------------- /doc/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | PAPER = 8 | BUILDDIR = _build 9 | 10 | # User-friendly check for sphinx-build 11 | ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) 12 | $(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/) 13 | endif 14 | 15 | # Internal variables. 16 | PAPEROPT_a4 = -D latex_paper_size=a4 17 | PAPEROPT_letter = -D latex_paper_size=letter 18 | ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 19 | # the i18n builder cannot share the environment and doctrees with the others 20 | I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 21 | 22 | .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext 23 | 24 | help: 25 | @echo "Please use \`make ' where is one of" 26 | @echo " html to make standalone HTML files" 27 | @echo " dirhtml to make HTML files named index.html in directories" 28 | @echo " singlehtml to make a single large HTML file" 29 | @echo " pickle to make pickle files" 30 | @echo " json to make JSON files" 31 | @echo " htmlhelp to make HTML files and a HTML help project" 32 | @echo " qthelp to make HTML files and a qthelp project" 33 | @echo " devhelp to make HTML files and a Devhelp project" 34 | @echo " epub to make an epub" 35 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" 36 | @echo " latexpdf to make LaTeX files and run them through pdflatex" 37 | @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" 38 | @echo " text to make text files" 39 | @echo " man to make manual pages" 40 | @echo " texinfo to make Texinfo files" 41 | @echo " info to make Texinfo files and run them through makeinfo" 42 | @echo " gettext to make PO message catalogs" 43 | @echo " changes to make an overview of all changed/added/deprecated items" 44 | @echo " xml to make Docutils-native XML files" 45 | @echo " pseudoxml to make pseudoxml-XML files for display purposes" 46 | @echo " linkcheck to check all external links for integrity" 47 | @echo " doctest to run all doctests embedded in the documentation (if enabled)" 48 | 49 | clean: 50 | rm -rf $(BUILDDIR)/* 51 | 52 | html: 53 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html 54 | @echo 55 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." 56 | 57 | dirhtml: 58 | $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml 59 | @echo 60 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." 61 | 62 | singlehtml: 63 | $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml 64 | @echo 65 | @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." 66 | 67 | pickle: 68 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle 69 | @echo 70 | @echo "Build finished; now you can process the pickle files." 71 | 72 | json: 73 | $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json 74 | @echo 75 | @echo "Build finished; now you can process the JSON files." 76 | 77 | htmlhelp: 78 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp 79 | @echo 80 | @echo "Build finished; now you can run HTML Help Workshop with the" \ 81 | ".hhp project file in $(BUILDDIR)/htmlhelp." 82 | 83 | qthelp: 84 | $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp 85 | @echo 86 | @echo "Build finished; now you can run "qcollectiongenerator" with the" \ 87 | ".qhcp project file in $(BUILDDIR)/qthelp, like this:" 88 | @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/python-escpos.qhcp" 89 | @echo "To view the help file:" 90 | @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/python-escpos.qhc" 91 | 92 | devhelp: 93 | $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp 94 | @echo 95 | @echo "Build finished." 96 | @echo "To view the help file:" 97 | @echo "# mkdir -p $$HOME/.local/share/devhelp/python-escpos" 98 | @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/python-escpos" 99 | @echo "# devhelp" 100 | 101 | epub: 102 | $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub 103 | @echo 104 | @echo "Build finished. The epub file is in $(BUILDDIR)/epub." 105 | 106 | latex: 107 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 108 | @echo 109 | @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." 110 | @echo "Run \`make' in that directory to run these through (pdf)latex" \ 111 | "(use \`make latexpdf' here to do that automatically)." 112 | 113 | latexpdf: 114 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 115 | @echo "Running LaTeX files through pdflatex..." 116 | $(MAKE) -C $(BUILDDIR)/latex all-pdf 117 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 118 | 119 | latexpdfja: 120 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 121 | @echo "Running LaTeX files through platex and dvipdfmx..." 122 | $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja 123 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 124 | 125 | text: 126 | $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text 127 | @echo 128 | @echo "Build finished. The text files are in $(BUILDDIR)/text." 129 | 130 | man: 131 | $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man 132 | @echo 133 | @echo "Build finished. The manual pages are in $(BUILDDIR)/man." 134 | 135 | texinfo: 136 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 137 | @echo 138 | @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." 139 | @echo "Run \`make' in that directory to run these through makeinfo" \ 140 | "(use \`make info' here to do that automatically)." 141 | 142 | info: 143 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 144 | @echo "Running Texinfo files through makeinfo..." 145 | make -C $(BUILDDIR)/texinfo info 146 | @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." 147 | 148 | gettext: 149 | $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale 150 | @echo 151 | @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." 152 | 153 | changes: 154 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes 155 | @echo 156 | @echo "The overview file is in $(BUILDDIR)/changes." 157 | 158 | linkcheck: 159 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck 160 | @echo 161 | @echo "Link check complete; look for any errors in the above output " \ 162 | "or in $(BUILDDIR)/linkcheck/output.txt." 163 | 164 | doctest: 165 | $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest 166 | @echo "Testing of doctests in the sources finished, look at the " \ 167 | "results in $(BUILDDIR)/doctest/output.txt." 168 | 169 | xml: 170 | $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml 171 | @echo 172 | @echo "Build finished. The XML files are in $(BUILDDIR)/xml." 173 | 174 | pseudoxml: 175 | $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml 176 | @echo 177 | @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." 178 | -------------------------------------------------------------------------------- /doc/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | REM Command file for Sphinx documentation 4 | 5 | if "%SPHINXBUILD%" == "" ( 6 | set SPHINXBUILD=sphinx-build 7 | ) 8 | set BUILDDIR=_build 9 | set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% . 10 | set I18NSPHINXOPTS=%SPHINXOPTS% . 11 | if NOT "%PAPER%" == "" ( 12 | set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% 13 | set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% 14 | ) 15 | 16 | if "%1" == "" goto help 17 | 18 | if "%1" == "help" ( 19 | :help 20 | echo.Please use `make ^` where ^ is one of 21 | echo. html to make standalone HTML files 22 | echo. dirhtml to make HTML files named index.html in directories 23 | echo. singlehtml to make a single large HTML file 24 | echo. pickle to make pickle files 25 | echo. json to make JSON files 26 | echo. htmlhelp to make HTML files and a HTML help project 27 | echo. qthelp to make HTML files and a qthelp project 28 | echo. devhelp to make HTML files and a Devhelp project 29 | echo. epub to make an epub 30 | echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter 31 | echo. text to make text files 32 | echo. man to make manual pages 33 | echo. texinfo to make Texinfo files 34 | echo. gettext to make PO message catalogs 35 | echo. changes to make an overview over all changed/added/deprecated items 36 | echo. xml to make Docutils-native XML files 37 | echo. pseudoxml to make pseudoxml-XML files for display purposes 38 | echo. linkcheck to check all external links for integrity 39 | echo. doctest to run all doctests embedded in the documentation if enabled 40 | goto end 41 | ) 42 | 43 | if "%1" == "clean" ( 44 | for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i 45 | del /q /s %BUILDDIR%\* 46 | goto end 47 | ) 48 | 49 | 50 | %SPHINXBUILD% 2> nul 51 | if errorlevel 9009 ( 52 | echo. 53 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 54 | echo.installed, then set the SPHINXBUILD environment variable to point 55 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 56 | echo.may add the Sphinx directory to PATH. 57 | echo. 58 | echo.If you don't have Sphinx installed, grab it from 59 | echo.http://sphinx-doc.org/ 60 | exit /b 1 61 | ) 62 | 63 | if "%1" == "html" ( 64 | %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html 65 | if errorlevel 1 exit /b 1 66 | echo. 67 | echo.Build finished. The HTML pages are in %BUILDDIR%/html. 68 | goto end 69 | ) 70 | 71 | if "%1" == "dirhtml" ( 72 | %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml 73 | if errorlevel 1 exit /b 1 74 | echo. 75 | echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. 76 | goto end 77 | ) 78 | 79 | if "%1" == "singlehtml" ( 80 | %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml 81 | if errorlevel 1 exit /b 1 82 | echo. 83 | echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. 84 | goto end 85 | ) 86 | 87 | if "%1" == "pickle" ( 88 | %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle 89 | if errorlevel 1 exit /b 1 90 | echo. 91 | echo.Build finished; now you can process the pickle files. 92 | goto end 93 | ) 94 | 95 | if "%1" == "json" ( 96 | %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json 97 | if errorlevel 1 exit /b 1 98 | echo. 99 | echo.Build finished; now you can process the JSON files. 100 | goto end 101 | ) 102 | 103 | if "%1" == "htmlhelp" ( 104 | %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp 105 | if errorlevel 1 exit /b 1 106 | echo. 107 | echo.Build finished; now you can run HTML Help Workshop with the ^ 108 | .hhp project file in %BUILDDIR%/htmlhelp. 109 | goto end 110 | ) 111 | 112 | if "%1" == "qthelp" ( 113 | %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp 114 | if errorlevel 1 exit /b 1 115 | echo. 116 | echo.Build finished; now you can run "qcollectiongenerator" with the ^ 117 | .qhcp project file in %BUILDDIR%/qthelp, like this: 118 | echo.^> qcollectiongenerator %BUILDDIR%\qthelp\python-escpos.qhcp 119 | echo.To view the help file: 120 | echo.^> assistant -collectionFile %BUILDDIR%\qthelp\python-escpos.ghc 121 | goto end 122 | ) 123 | 124 | if "%1" == "devhelp" ( 125 | %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp 126 | if errorlevel 1 exit /b 1 127 | echo. 128 | echo.Build finished. 129 | goto end 130 | ) 131 | 132 | if "%1" == "epub" ( 133 | %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub 134 | if errorlevel 1 exit /b 1 135 | echo. 136 | echo.Build finished. The epub file is in %BUILDDIR%/epub. 137 | goto end 138 | ) 139 | 140 | if "%1" == "latex" ( 141 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 142 | if errorlevel 1 exit /b 1 143 | echo. 144 | echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. 145 | goto end 146 | ) 147 | 148 | if "%1" == "latexpdf" ( 149 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 150 | cd %BUILDDIR%/latex 151 | make all-pdf 152 | cd %BUILDDIR%/.. 153 | echo. 154 | echo.Build finished; the PDF files are in %BUILDDIR%/latex. 155 | goto end 156 | ) 157 | 158 | if "%1" == "latexpdfja" ( 159 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 160 | cd %BUILDDIR%/latex 161 | make all-pdf-ja 162 | cd %BUILDDIR%/.. 163 | echo. 164 | echo.Build finished; the PDF files are in %BUILDDIR%/latex. 165 | goto end 166 | ) 167 | 168 | if "%1" == "text" ( 169 | %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text 170 | if errorlevel 1 exit /b 1 171 | echo. 172 | echo.Build finished. The text files are in %BUILDDIR%/text. 173 | goto end 174 | ) 175 | 176 | if "%1" == "man" ( 177 | %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man 178 | if errorlevel 1 exit /b 1 179 | echo. 180 | echo.Build finished. The manual pages are in %BUILDDIR%/man. 181 | goto end 182 | ) 183 | 184 | if "%1" == "texinfo" ( 185 | %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo 186 | if errorlevel 1 exit /b 1 187 | echo. 188 | echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. 189 | goto end 190 | ) 191 | 192 | if "%1" == "gettext" ( 193 | %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale 194 | if errorlevel 1 exit /b 1 195 | echo. 196 | echo.Build finished. The message catalogs are in %BUILDDIR%/locale. 197 | goto end 198 | ) 199 | 200 | if "%1" == "changes" ( 201 | %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes 202 | if errorlevel 1 exit /b 1 203 | echo. 204 | echo.The overview file is in %BUILDDIR%/changes. 205 | goto end 206 | ) 207 | 208 | if "%1" == "linkcheck" ( 209 | %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck 210 | if errorlevel 1 exit /b 1 211 | echo. 212 | echo.Link check complete; look for any errors in the above output ^ 213 | or in %BUILDDIR%/linkcheck/output.txt. 214 | goto end 215 | ) 216 | 217 | if "%1" == "doctest" ( 218 | %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest 219 | if errorlevel 1 exit /b 1 220 | echo. 221 | echo.Testing of doctests in the sources finished, look at the ^ 222 | results in %BUILDDIR%/doctest/output.txt. 223 | goto end 224 | ) 225 | 226 | if "%1" == "xml" ( 227 | %SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml 228 | if errorlevel 1 exit /b 1 229 | echo. 230 | echo.Build finished. The XML files are in %BUILDDIR%/xml. 231 | goto end 232 | ) 233 | 234 | if "%1" == "pseudoxml" ( 235 | %SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml 236 | if errorlevel 1 exit /b 1 237 | echo. 238 | echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml. 239 | goto end 240 | ) 241 | 242 | :end 243 | -------------------------------------------------------------------------------- /doc/conf.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # 3 | # python-escpos documentation build configuration file, created by 4 | # sphinx-quickstart on Sat Dec 26 14:28:42 2015. 5 | # 6 | # This file is execfile()d with the current directory set to its 7 | # containing dir. 8 | # 9 | # Note that not all possible configuration values are present in this 10 | # autogenerated file. 11 | # 12 | # All configuration values have a default; values that are commented out 13 | # serve to show the default. 14 | 15 | import sys 16 | import os 17 | 18 | # If extensions (or modules to document with autodoc) are in another directory, 19 | # add these directories to sys.path here. If the directory is relative to the 20 | # documentation root, use os.path.abspath to make it absolute, like shown here. 21 | sys.path.insert(0, os.path.abspath('..')) 22 | 23 | # -- General configuration ------------------------------------------------ 24 | 25 | # If your documentation needs a minimal Sphinx version, state it here. 26 | #needs_sphinx = '1.0' 27 | 28 | # Add any Sphinx extension module names here, as strings. They can be 29 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 30 | # ones. 31 | extensions = [ 32 | 'sphinx.ext.autodoc', 33 | 'sphinx.ext.doctest', 34 | 'sphinx.ext.todo', 35 | 'sphinx.ext.coverage', 36 | 'sphinx.ext.viewcode', 37 | ] 38 | 39 | # Add any paths that contain templates here, relative to this directory. 40 | templates_path = ['_templates'] 41 | 42 | # The suffix of source filenames. 43 | source_suffix = '.rst' 44 | 45 | # The encoding of source files. 46 | #source_encoding = 'utf-8-sig' 47 | 48 | # The master toctree document. 49 | master_doc = 'index' 50 | 51 | # General information about the project. 52 | project = u'python-escpos' 53 | copyright = u'2015, Manuel F Martinez and others' 54 | 55 | # The version info for the project you're documenting, acts as replacement for 56 | # |version| and |release|, also used in various other places throughout the 57 | # built documents. 58 | # 59 | # The short X.Y version. 60 | version = '1.0.8' 61 | # The full version, including alpha/beta/rc tags. 62 | release = '1.0.8' 63 | 64 | # The language for content autogenerated by Sphinx. Refer to documentation 65 | # for a list of supported languages. 66 | #language = None 67 | 68 | # There are two options for replacing |today|: either, you set today to some 69 | # non-false value, then it is used: 70 | #today = '' 71 | # Else, today_fmt is used as the format for a strftime call. 72 | #today_fmt = '%B %d, %Y' 73 | 74 | # List of patterns, relative to source directory, that match files and 75 | # directories to ignore when looking for source files. 76 | exclude_patterns = ['_build'] 77 | 78 | # The reST default role (used for this markup: `text`) to use for all 79 | # documents. 80 | #default_role = None 81 | 82 | # If true, '()' will be appended to :func: etc. cross-reference text. 83 | #add_function_parentheses = True 84 | 85 | # If true, the current module name will be prepended to all description 86 | # unit titles (such as .. function::). 87 | #add_module_names = True 88 | 89 | # If true, sectionauthor and moduleauthor directives will be shown in the 90 | # output. They are ignored by default. 91 | #show_authors = False 92 | 93 | # The name of the Pygments (syntax highlighting) style to use. 94 | pygments_style = 'sphinx' 95 | 96 | # A list of ignored prefixes for module index sorting. 97 | #modindex_common_prefix = [] 98 | 99 | # If true, keep warnings as "system message" paragraphs in the built documents. 100 | #keep_warnings = False 101 | 102 | 103 | # -- Options for HTML output ---------------------------------------------- 104 | 105 | # The theme to use for HTML and HTML Help pages. See the documentation for 106 | # a list of builtin themes. 107 | html_theme = 'default' 108 | 109 | # Theme options are theme-specific and customize the look and feel of a theme 110 | # further. For a list of options available for each theme, see the 111 | # documentation. 112 | #html_theme_options = {} 113 | 114 | # Add any paths that contain custom themes here, relative to this directory. 115 | #html_theme_path = [] 116 | 117 | # The name for this set of Sphinx documents. If None, it defaults to 118 | # " v documentation". 119 | #html_title = None 120 | 121 | # A shorter title for the navigation bar. Default is the same as html_title. 122 | #html_short_title = None 123 | 124 | # The name of an image file (relative to this directory) to place at the top 125 | # of the sidebar. 126 | #html_logo = None 127 | 128 | # The name of an image file (within the static path) to use as favicon of the 129 | # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 130 | # pixels large. 131 | #html_favicon = None 132 | 133 | # Add any paths that contain custom static files (such as style sheets) here, 134 | # relative to this directory. They are copied after the builtin static files, 135 | # so a file named "default.css" will overwrite the builtin "default.css". 136 | html_static_path = ['_static'] 137 | 138 | # Add any extra paths that contain custom files (such as robots.txt or 139 | # .htaccess) here, relative to this directory. These files are copied 140 | # directly to the root of the documentation. 141 | #html_extra_path = [] 142 | 143 | # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, 144 | # using the given strftime format. 145 | #html_last_updated_fmt = '%b %d, %Y' 146 | 147 | # If true, SmartyPants will be used to convert quotes and dashes to 148 | # typographically correct entities. 149 | #html_use_smartypants = True 150 | 151 | # Custom sidebar templates, maps document names to template names. 152 | #html_sidebars = {} 153 | 154 | # Additional templates that should be rendered to pages, maps page names to 155 | # template names. 156 | #html_additional_pages = {} 157 | 158 | # If false, no module index is generated. 159 | #html_domain_indices = True 160 | 161 | # If false, no index is generated. 162 | #html_use_index = True 163 | 164 | # If true, the index is split into individual pages for each letter. 165 | #html_split_index = False 166 | 167 | # If true, links to the reST sources are added to the pages. 168 | #html_show_sourcelink = True 169 | 170 | # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. 171 | #html_show_sphinx = True 172 | 173 | # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. 174 | #html_show_copyright = True 175 | 176 | # If true, an OpenSearch description file will be output, and all pages will 177 | # contain a tag referring to it. The value of this option must be the 178 | # base URL from which the finished HTML is served. 179 | #html_use_opensearch = '' 180 | 181 | # This is the file name suffix for HTML files (e.g. ".xhtml"). 182 | #html_file_suffix = None 183 | 184 | # Output file base name for HTML help builder. 185 | htmlhelp_basename = 'python-escposdoc' 186 | 187 | 188 | # -- Options for LaTeX output --------------------------------------------- 189 | 190 | latex_elements = { 191 | # The paper size ('letterpaper' or 'a4paper'). 192 | #'papersize': 'letterpaper', 193 | 194 | # The font size ('10pt', '11pt' or '12pt'). 195 | #'pointsize': '10pt', 196 | 197 | # Additional stuff for the LaTeX preamble. 198 | #'preamble': '', 199 | } 200 | 201 | # Grouping the document tree into LaTeX files. List of tuples 202 | # (source start file, target name, title, 203 | # author, documentclass [howto, manual, or own class]). 204 | latex_documents = [ 205 | ('index', 'python-escpos.tex', u'python-escpos Documentation', 206 | u'Manuel F Martinez and others', 'manual'), 207 | ] 208 | 209 | # The name of an image file (relative to this directory) to place at the top of 210 | # the title page. 211 | #latex_logo = None 212 | 213 | # For "manual" documents, if this is true, then toplevel headings are parts, 214 | # not chapters. 215 | #latex_use_parts = False 216 | 217 | # If true, show page references after internal links. 218 | #latex_show_pagerefs = False 219 | 220 | # If true, show URL addresses after external links. 221 | #latex_show_urls = False 222 | 223 | # Documents to append as an appendix to all manuals. 224 | #latex_appendices = [] 225 | 226 | # If false, no module index is generated. 227 | #latex_domain_indices = True 228 | 229 | 230 | # -- Options for manual page output --------------------------------------- 231 | 232 | # One entry per manual page. List of tuples 233 | # (source start file, name, description, authors, manual section). 234 | man_pages = [ 235 | ('index', 'python-escpos', u'python-escpos Documentation', 236 | [u'Manuel F Martinez and others'], 1) 237 | ] 238 | 239 | # If true, show URL addresses after external links. 240 | #man_show_urls = False 241 | 242 | 243 | # -- Options for Texinfo output ------------------------------------------- 244 | 245 | # Grouping the document tree into Texinfo files. List of tuples 246 | # (source start file, target name, title, author, 247 | # dir menu entry, description, category) 248 | texinfo_documents = [ 249 | ('index', 'python-escpos', u'python-escpos Documentation', 250 | u'Manuel F Martinez and others', 'python-escpos', 'One line description of project.', 251 | 'Miscellaneous'), 252 | ] 253 | 254 | # Documents to append as an appendix to all manuals. 255 | #texinfo_appendices = [] 256 | 257 | # If false, no module index is generated. 258 | #texinfo_domain_indices = True 259 | 260 | # How to display URL addresses: 'footnote', 'no', or 'inline'. 261 | #texinfo_show_urls = 'footnote' 262 | 263 | # If true, do not generate a @detailmenu in the "Top" node's menu. 264 | #texinfo_no_detailmenu = False 265 | -------------------------------------------------------------------------------- /escpos/escpos.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | """ 3 | @author: Manuel F Martinez 4 | @organization: Bashlinux 5 | @copyright: Copyright (c) 2012 Bashlinux 6 | @license: GNU GPL v3 7 | """ 8 | 9 | try: 10 | import Image 11 | except ImportError: 12 | from PIL import Image 13 | 14 | import qrcode 15 | import time 16 | 17 | from constants import * 18 | from exceptions import * 19 | 20 | class Escpos: 21 | """ ESC/POS Printer object """ 22 | device = None 23 | 24 | 25 | def _check_image_size(self, size): 26 | """ Check and fix the size of the image to 32 bits """ 27 | if size % 32 == 0: 28 | return (0, 0) 29 | else: 30 | image_border = 32 - (size % 32) 31 | if (image_border % 2) == 0: 32 | return (image_border / 2, image_border / 2) 33 | else: 34 | return (image_border / 2, (image_border / 2) + 1) 35 | 36 | 37 | def _print_image(self, line, size): 38 | """ Print formatted image """ 39 | i = 0 40 | cont = 0 41 | buffer = "" 42 | 43 | self._raw(S_RASTER_N) 44 | buffer = "%02X%02X%02X%02X" % (((size[0]/size[1])/8), 0, size[1]&0xff, size[1]>>8) 45 | self._raw(buffer.decode('hex')) 46 | buffer = "" 47 | 48 | while i < len(line): 49 | hex_string = int(line[i:i+8],2) 50 | buffer += "%02X" % hex_string 51 | i += 8 52 | cont += 1 53 | if cont % 4 == 0: 54 | self._raw(buffer.decode("hex")) 55 | buffer = "" 56 | cont = 0 57 | 58 | 59 | def _convert_image(self, im): 60 | """ Parse image and prepare it to a printable format """ 61 | pixels = [] 62 | pix_line = "" 63 | im_left = "" 64 | im_right = "" 65 | switch = 0 66 | img_size = [ 0, 0 ] 67 | 68 | 69 | if im.size[0] > 512: 70 | print ("WARNING: Image is wider than 512 and could be truncated at print time ") 71 | if im.size[1] > 0xffff: 72 | raise ImageSizeError() 73 | 74 | im_border = self._check_image_size(im.size[0]) 75 | for i in range(im_border[0]): 76 | im_left += "0" 77 | for i in range(im_border[1]): 78 | im_right += "0" 79 | 80 | for y in range(im.size[1]): 81 | img_size[1] += 1 82 | pix_line += im_left 83 | img_size[0] += im_border[0] 84 | for x in range(im.size[0]): 85 | img_size[0] += 1 86 | RGB = im.getpixel((x, y)) 87 | im_color = (RGB[0] + RGB[1] + RGB[2]) 88 | im_pattern = "1X0" 89 | pattern_len = len(im_pattern) 90 | switch = (switch - 1 ) * (-1) 91 | for x in range(pattern_len): 92 | if im_color <= (255 * 3 / pattern_len * (x+1)): 93 | if im_pattern[x] == "X": 94 | pix_line += "%d" % switch 95 | else: 96 | pix_line += im_pattern[x] 97 | break 98 | elif im_color > (255 * 3 / pattern_len * pattern_len) and im_color <= (255 * 3): 99 | pix_line += im_pattern[-1] 100 | break 101 | pix_line += im_right 102 | img_size[0] += im_border[1] 103 | 104 | self._print_image(pix_line, img_size) 105 | 106 | 107 | def image(self,path_img): 108 | """ Open image file """ 109 | im_open = Image.open(path_img) 110 | 111 | # Remove the alpha channel on transparent images 112 | if im_open.mode == 'RGBA': 113 | im_open.load() 114 | im = Image.new("RGB", im_open.size, (255, 255, 255)) 115 | im.paste(im_open, mask=im_open.split()[3]) 116 | else: 117 | im = im_open.convert("RGB") 118 | 119 | # Convert the RGB image in printable image 120 | self._convert_image(im) 121 | 122 | 123 | def qr(self,text): 124 | """ Print QR Code for the provided string """ 125 | qr_code = qrcode.QRCode(version=4, box_size=4, border=1) 126 | qr_code.add_data(text) 127 | qr_code.make(fit=True) 128 | qr_img = qr_code.make_image() 129 | im = qr_img._img.convert("RGB") 130 | 131 | # Convert the RGB image in printable image 132 | self._convert_image(im) 133 | 134 | 135 | def charcode(self,code): 136 | """ Set Character Code Table """ 137 | if code.upper() == "USA": 138 | self._raw(CHARCODE_PC437) 139 | elif code.upper() == "JIS": 140 | self._raw(CHARCODE_JIS) 141 | elif code.upper() == "MULTILINGUAL": 142 | self._raw(CHARCODE_PC850) 143 | elif code.upper() == "PORTUGUESE": 144 | self._raw(CHARCODE_PC860) 145 | elif code.upper() == "CA_FRENCH": 146 | self._raw(CHARCODE_PC863) 147 | elif code.upper() == "NORDIC": 148 | self._raw(CHARCODE_PC865) 149 | elif code.upper() == "WEST_EUROPE": 150 | self._raw(CHARCODE_WEU) 151 | elif code.upper() == "GREEK": 152 | self._raw(CHARCODE_GREEK) 153 | elif code.upper() == "HEBREW": 154 | self._raw(CHARCODE_HEBREW) 155 | elif code.upper() == "LATVIAN": 156 | self._raw(CHARCODE_PC755) 157 | elif code.upper() == "WPC1252": 158 | self._raw(CHARCODE_PC1252) 159 | elif code.upper() == "CIRILLIC2": 160 | self._raw(CHARCODE_PC866) 161 | elif code.upper() == "LATIN2": 162 | self._raw(CHARCODE_PC852) 163 | elif code.upper() == "EURO": 164 | self._raw(CHARCODE_PC858) 165 | elif code.upper() == "THAI42": 166 | self._raw(CHARCODE_THAI42) 167 | elif code.upper() == "THAI11": 168 | self._raw(CHARCODE_THAI11) 169 | elif code.upper() == "THAI13": 170 | self._raw(CHARCODE_THAI13) 171 | elif code.upper() == "THAI14": 172 | self._raw(CHARCODE_THAI14) 173 | elif code.upper() == "THAI16": 174 | self._raw(CHARCODE_THAI16) 175 | elif code.upper() == "THAI17": 176 | self._raw(CHARCODE_THAI17) 177 | elif code.upper() == "THAI18": 178 | self._raw(CHARCODE_THAI18) 179 | else: 180 | raise CharCodeError() 181 | 182 | def barcode(self, code, bc, width, height, pos, font): 183 | """ Print Barcode """ 184 | # Align Bar Code() 185 | self._raw(TXT_ALIGN_CT) 186 | # Height 187 | if height >=2 or height <=6: 188 | self._raw(BARCODE_HEIGHT) 189 | else: 190 | raise BarcodeSizeError() 191 | # Width 192 | if width >= 1 or width <=255: 193 | self._raw(BARCODE_WIDTH) 194 | else: 195 | raise BarcodeSizeError() 196 | # Font 197 | if font.upper() == "B": 198 | self._raw(BARCODE_FONT_B) 199 | else: # DEFAULT FONT: A 200 | self._raw(BARCODE_FONT_A) 201 | # Position 202 | if pos.upper() == "OFF": 203 | self._raw(BARCODE_TXT_OFF) 204 | elif pos.upper() == "BOTH": 205 | self._raw(BARCODE_TXT_BTH) 206 | elif pos.upper() == "ABOVE": 207 | self._raw(BARCODE_TXT_ABV) 208 | else: # DEFAULT POSITION: BELOW 209 | self._raw(BARCODE_TXT_BLW) 210 | # Type 211 | if bc.upper() == "UPC-A": 212 | self._raw(BARCODE_UPC_A) 213 | elif bc.upper() == "UPC-E": 214 | self._raw(BARCODE_UPC_E) 215 | elif bc.upper() == "EAN13": 216 | self._raw(BARCODE_EAN13) 217 | elif bc.upper() == "EAN8": 218 | self._raw(BARCODE_EAN8) 219 | elif bc.upper() == "CODE39": 220 | self._raw(BARCODE_CODE39) 221 | elif bc.upper() == "ITF": 222 | self._raw(BARCODE_ITF) 223 | elif bc.upper() == "NW7": 224 | self._raw(BARCODE_NW7) 225 | else: 226 | raise BarcodeTypeError() 227 | # Print Code 228 | if code: 229 | self._raw(code) 230 | else: 231 | raise exception.BarcodeCodeError() 232 | 233 | 234 | def text(self, txt): 235 | """ Print alpha-numeric text """ 236 | if txt: 237 | self._raw(txt) 238 | else: 239 | raise TextError() 240 | 241 | 242 | def set(self, align='left', font='a', type='normal', width=1, height=1, density=9): 243 | """ Set text properties """ 244 | # Width 245 | if height == 2 and width == 2: 246 | self._raw(TXT_NORMAL) 247 | self._raw(TXT_4SQUARE) 248 | elif height == 2 and width != 2: 249 | self._raw(TXT_NORMAL) 250 | self._raw(TXT_2HEIGHT) 251 | elif width == 2 and height != 2: 252 | self._raw(TXT_NORMAL) 253 | self._raw(TXT_2WIDTH) 254 | else: # DEFAULT SIZE: NORMAL 255 | self._raw(TXT_NORMAL) 256 | # Type 257 | if type.upper() == "B": 258 | self._raw(TXT_BOLD_ON) 259 | self._raw(TXT_UNDERL_OFF) 260 | elif type.upper() == "U": 261 | self._raw(TXT_BOLD_OFF) 262 | self._raw(TXT_UNDERL_ON) 263 | elif type.upper() == "U2": 264 | self._raw(TXT_BOLD_OFF) 265 | self._raw(TXT_UNDERL2_ON) 266 | elif type.upper() == "BU": 267 | self._raw(TXT_BOLD_ON) 268 | self._raw(TXT_UNDERL_ON) 269 | elif type.upper() == "BU2": 270 | self._raw(TXT_BOLD_ON) 271 | self._raw(TXT_UNDERL2_ON) 272 | elif type.upper == "NORMAL": 273 | self._raw(TXT_BOLD_OFF) 274 | self._raw(TXT_UNDERL_OFF) 275 | # Font 276 | if font.upper() == "B": 277 | self._raw(TXT_FONT_B) 278 | else: # DEFAULT FONT: A 279 | self._raw(TXT_FONT_A) 280 | # Align 281 | if align.upper() == "CENTER": 282 | self._raw(TXT_ALIGN_CT) 283 | elif align.upper() == "RIGHT": 284 | self._raw(TXT_ALIGN_RT) 285 | elif align.upper() == "LEFT": 286 | self._raw(TXT_ALIGN_LT) 287 | # Density 288 | if density == 0: 289 | self._raw(PD_N50) 290 | elif density == 1: 291 | self._raw(PD_N37) 292 | elif density == 2: 293 | self._raw(PD_N25) 294 | elif density == 3: 295 | self._raw(PD_N12) 296 | elif density == 4: 297 | self._raw(PD_0) 298 | elif density == 5: 299 | self._raw(PD_P12) 300 | elif density == 6: 301 | self._raw(PD_P25) 302 | elif density == 7: 303 | self._raw(PD_P37) 304 | elif density == 8: 305 | self._raw(PD_P50) 306 | else:# DEFAULT: DOES NOTHING 307 | pass 308 | 309 | 310 | def cut(self, mode=''): 311 | """ Cut paper """ 312 | # Fix the size between last line and cut 313 | # TODO: handle this with a line feed 314 | self._raw("\n\n\n\n\n\n") 315 | if mode.upper() == "PART": 316 | self._raw(PAPER_PART_CUT) 317 | else: # DEFAULT MODE: FULL CUT 318 | self._raw(PAPER_FULL_CUT) 319 | 320 | 321 | def cashdraw(self, pin): 322 | """ Send pulse to kick the cash drawer """ 323 | if pin == 2: 324 | self._raw(CD_KICK_2) 325 | elif pin == 5: 326 | self._raw(CD_KICK_5) 327 | else: 328 | raise CashDrawerError() 329 | 330 | 331 | def hw(self, hw): 332 | """ Hardware operations """ 333 | if hw.upper() == "INIT": 334 | self._raw(HW_INIT) 335 | elif hw.upper() == "SELECT": 336 | self._raw(HW_SELECT) 337 | elif hw.upper() == "RESET": 338 | self._raw(HW_RESET) 339 | else: # DEFAULT: DOES NOTHING 340 | pass 341 | 342 | 343 | def control(self, ctl, pos=4): 344 | """ Feed control sequences """ 345 | # Set tab positions 346 | if pos < 1 or pos > 16: 347 | raise TabError() 348 | else: 349 | self._raw("".join([CTL_SET_HT,hex(pos)])) 350 | # Set position 351 | if ctl.upper() == "LF": 352 | self._raw(CTL_LF) 353 | elif ctl.upper() == "FF": 354 | self._raw(CTL_FF) 355 | elif ctl.upper() == "CR": 356 | self._raw(CTL_CR) 357 | elif ctl.upper() == "HT": 358 | self._raw(CTL_HT) 359 | elif ctl.upper() == "VT": 360 | self._raw(CTL_VT) 361 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------