TicketML is a simple markup language for receipt printers
Project description
# ticketml [![Build Status](https://travis-ci.org/lukegb/ticketml.svg?branch=master)](https://travis-ci.org/lukegb/ticketml) [![PyPI Version](https://pypip.in/version/ticketml/badge.svg?style=flat)](https://pypi.python.org/pypi/ticketml)
A small XML-based markup language for tickets
Why?
====
As part of the code I write for [Imperial Cinema](http://www.imperialcinema.co.uk), I decided
I need some way of cleanly abstracting over multiple different (but similar) ticket printers.
I decided on a sort-of HTML-ish language, for which you will find a parser and ticket printing
backend for the following receipt printers:
* Citizen CBM-1000
* IBM 4610 family (tested on the 4610-TF6)
The XML
=======
The XML document has the following sort of style:
```xml
<?xml version="1.0" ?>
<ticket>
<head>
<logo num="1" />
not bold<b> suddenly bold</b> not bold again<br />
not underlined <u>suddenly underlined</u> not underlined<br />
now <b>for <u>a mix</u></b> <u>of <b>settings</b></u><br/>
<align mode="center"><logo num="2" /></align>
base font<br />
<font width="2">2x wide</font><br />
<font height="2">2x high</font><br />
<font width="2" height="2">2x big</font><br />
<font width="8" height="8">MASSIVE</font>
</head>
</ticket>
```
(Note that this document is formatted neatly - leading per-line whitespace is NOT stripped by the parser and may cause you issues!)
The following tags are implemented - unknown tags are ignored (but are still recursed into!):
* `ticket`: this is the root tag and is not treated specially
* `b`: activates emphasis (usually bold)
* `u`: activates underlining
* `logo num="NUMBER"`: prints pre-loaded image NUMBER
* `align mode="left|right|center"`: changes the alignment of text
* `br`: prints a newline
* `font (width="WIDTH") (height="HEIGHT")`: changes the font width/height multiplier
Using it
========
At the moment there's a fairly simplistic API. In order to get started, you'll need some sort of file-like output device. This is usually a PySerial `Serial` object.
```python
import serial
output = serial.Serial('/dev/ttyS1', 19200)
```
Now that you have an output device, you can construct a `Backend`. At present there's a choice of two, the `CbmBackend` (for Citizen CBM-1000 printers) and the `Ibm4610Backend` (for IBM 4610 series printers). Backends are up to take whatever arguments they choose - at the moment this is just the output device they should talk to.
```python
backend = ticketml.Ibm4610Backend(output)
```
Now you can finally construct a parser. This takes place in two stages - first you parse the input XML, then you tell the parser to render it to the output device:
```python
ticket = ticketml.TicketML.parse('<?xml version="1.0" ?>\n<ticket>Hello! This is my first ticket!</ticket>')
context = {}
ticket.go(context, backend)
```
The `context` parameter is unused at the moment, but is planned to be used for future templating functionality.
A small XML-based markup language for tickets
Why?
====
As part of the code I write for [Imperial Cinema](http://www.imperialcinema.co.uk), I decided
I need some way of cleanly abstracting over multiple different (but similar) ticket printers.
I decided on a sort-of HTML-ish language, for which you will find a parser and ticket printing
backend for the following receipt printers:
* Citizen CBM-1000
* IBM 4610 family (tested on the 4610-TF6)
The XML
=======
The XML document has the following sort of style:
```xml
<?xml version="1.0" ?>
<ticket>
<head>
<logo num="1" />
not bold<b> suddenly bold</b> not bold again<br />
not underlined <u>suddenly underlined</u> not underlined<br />
now <b>for <u>a mix</u></b> <u>of <b>settings</b></u><br/>
<align mode="center"><logo num="2" /></align>
base font<br />
<font width="2">2x wide</font><br />
<font height="2">2x high</font><br />
<font width="2" height="2">2x big</font><br />
<font width="8" height="8">MASSIVE</font>
</head>
</ticket>
```
(Note that this document is formatted neatly - leading per-line whitespace is NOT stripped by the parser and may cause you issues!)
The following tags are implemented - unknown tags are ignored (but are still recursed into!):
* `ticket`: this is the root tag and is not treated specially
* `b`: activates emphasis (usually bold)
* `u`: activates underlining
* `logo num="NUMBER"`: prints pre-loaded image NUMBER
* `align mode="left|right|center"`: changes the alignment of text
* `br`: prints a newline
* `font (width="WIDTH") (height="HEIGHT")`: changes the font width/height multiplier
Using it
========
At the moment there's a fairly simplistic API. In order to get started, you'll need some sort of file-like output device. This is usually a PySerial `Serial` object.
```python
import serial
output = serial.Serial('/dev/ttyS1', 19200)
```
Now that you have an output device, you can construct a `Backend`. At present there's a choice of two, the `CbmBackend` (for Citizen CBM-1000 printers) and the `Ibm4610Backend` (for IBM 4610 series printers). Backends are up to take whatever arguments they choose - at the moment this is just the output device they should talk to.
```python
backend = ticketml.Ibm4610Backend(output)
```
Now you can finally construct a parser. This takes place in two stages - first you parse the input XML, then you tell the parser to render it to the output device:
```python
ticket = ticketml.TicketML.parse('<?xml version="1.0" ?>\n<ticket>Hello! This is my first ticket!</ticket>')
context = {}
ticket.go(context, backend)
```
The `context` parameter is unused at the moment, but is planned to be used for future templating functionality.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
ticketml-0.2.1.tar.gz
(8.0 kB
view details)
Built Distribution
File details
Details for the file ticketml-0.2.1.tar.gz
.
File metadata
- Download URL: ticketml-0.2.1.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e81693a754c554344bd6a61004b4015d31184b5b94da93a230684ef99fd3d68d |
|
MD5 | 7ff4b91bba255f6d436f936c5d0a2e85 |
|
BLAKE2b-256 | ace7d07e8ac945aeab5034e7f8184e3d4da4dabd96997ec9345faa648fbfd9ee |
File details
Details for the file ticketml-0.2.1-py2.py3-none-any.whl
.
File metadata
- Download URL: ticketml-0.2.1-py2.py3-none-any.whl
- Upload date:
- Size: 10.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 332166f01b39c316094d71927d21b7634c6012427e1e7cd530375c5ac742ddba |
|
MD5 | 0bf303fffb7fcb3220c95b351b9ec1e2 |
|
BLAKE2b-256 | 8776c7edcff34ee7bc767e057e408467b4778d215481398490e773ea3e19b36b |