A lot of renaming variables, tools; improved README

This commit is contained in:
Philipp Klaus
2015-12-14 11:09:46 +01:00
parent bbb3919ed0
commit 05ce83ebd8
6 changed files with 55 additions and 38 deletions

View File

@@ -1,18 +1,29 @@
brother\_ql
===========
## brother\_ql ##
A Python package to control Brother QL label printers.
Installation
------------
### Installation ###
pip install https://github.com/pklaus/brother_ql/archive/master.zip
Usage
-----
### Usage ###
To analyze a binary file containing Brother QL Raster commands:
#### Create ####
brother_ql_reader your_brother_ql_file.bin --loglevel DEBUG 2>&1 | less
You can create a new command file to be sent to the printer with
the `brother_ql_create` tool:
brother_ql_create --model QL-500 ./720x300_monochrome.png > 720x300_monochrome.bin
If you want to find out about its options, just call the tool with `--help`:
brother_ql_create --help
#### Analyse ####
To analyse a binary file containing Brother QL Raster commands and
create an image of what would be printed:
brother_ql_analyse 720x300_monochrome.bin --loglevel DEBUG 2>&1 | less
This tool also has the `--help` option.

20
brother_ql/analyse.py Executable file
View File

@@ -0,0 +1,20 @@
#!/usr/bin/env python
import sys, argparse, logging
from brother_ql.reader import BrotherQLReader
def main():
parser = argparse.ArgumentParser()
parser.add_argument('file', help='The file to analyze')
parser.add_argument('--loglevel', type=lambda x: getattr(logging, x), default=logging.WARNING, help='The loglevel to apply')
args = parser.parse_args()
logging.basicConfig(stream=sys.stdout, format='%(levelname)s: %(message)s', level=args.loglevel)
br = BrotherQLReader(args.file)
br.analyse()
if __name__ == '__main__':
main()

View File

@@ -5,7 +5,7 @@ import sys, argparse, logging
import numpy as np
from PIL import Image
from brother_ql.writer import QLRaster
from brother_ql.writer import BrotherQLRaster
def hex_format(data):
return ' '.join('{:02X}'.format(byte) for byte in data)
@@ -37,7 +37,7 @@ def main():
arr[white_idx] = 1
arr[black_idx] = 0
qlr = QLRaster(args.model)
qlr = BrotherQLRaster(args.model)
qlr.set_mode()
qlr.set_clear_command_buffer()
qlr.set_initialize()

View File

@@ -36,7 +36,7 @@ dot_widths = {
def hex_format(data):
return ' '.join('{:02X}'.format(byte) for byte in data)
class BrotherReader(object):
class BrotherQLReader(object):
def __init__(self, brother_file):
if type(brother_file) in (str,):
@@ -48,7 +48,7 @@ class BrotherReader(object):
self.compression = False
self.page = 1
def analyze(self):
def analyse(self):
rem_script = self.brother_file.read()
while True:
if len(rem_script) == 0: break
@@ -117,18 +117,3 @@ class BrotherReader(object):
logger.error('cmd not found: {0}... ({1}...)'.format(hex_format(rem_script[0:4]), rem_script[0:4]))
rem_script = rem_script[1:]
def main():
from argparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument('file', help='The file to analyze')
parser.add_argument('--loglevel', type=lambda x: getattr(logging, x), default=logging.WARNING, help='The loglevel to apply')
args = parser.parse_args()
logging.basicConfig(stream=sys.stdout, format='%(levelname)s: %(message)s', level=args.loglevel)
br = BrotherReader(args.file)
br.analyze()
if __name__ == '__main__':
main()

View File

@@ -17,11 +17,11 @@ from .devicedependent import models, \
logger = logging.getLogger(__name__)
class QLRaster(object):
class BrotherQLRaster(object):
def __init__(self, model='QL-500'):
if model not in models:
raise QLRasterUnknownModel()
raise BrotherQLRasterUnknownModel()
self.model = model
self.data = b''
self._pquality = 1
@@ -33,7 +33,7 @@ class QLRaster(object):
def warn(self, problem):
if self.exception_on_warning:
raise QLRasterError(problem)
raise BrotherQLRasterError(problem)
else:
logger.warning(problem)
@@ -136,7 +136,7 @@ class QLRaster(object):
row = bytes(np.packbits(row))
if len(row) != nbpr:
fmt = 'Wrong number of bytes per row: {}, expected {}'
raise QLRasterError(fmt.format(len(row), nbpr))
raise BrotherQLRasterError(fmt.format(len(row), nbpr))
if self._compression:
row = packbits.encode(row)
self.data += bytes([len(row)])
@@ -148,6 +148,6 @@ class QLRaster(object):
else:
self.data += b'\x0C'
class QLRasterError(Exception): pass
class QLRasterUnknownModel(QLRasterError): pass
class BrotherQLRasterError(Exception): pass
class BrotherQLRasterUnknownModel(BrotherQLRasterError): pass

View File

@@ -16,16 +16,17 @@ setup(name='brother_ql',
packages = ['brother_ql'],
entry_points = {
'console_scripts': [
'brother_ql_read = brother_ql.reader:main',
'brother_ql_write = brother_ql.create:main',
'brother_ql_analyse = brother_ql.analyse:main',
'brother_ql_create = brother_ql.create:main',
],
},
include_package_data = False,
zip_safe = True,
platforms = 'any',
install_requires = ['numpy', 'packbits', 'pillow'],
install_requires = ['numpy', 'packbits', 'pillow', 'matplotlib'],
extras_require = {
'brother_ql_read': ["matplotlib",],
#'brother_ql_analyse': ["matplotlib",],
#'brother_ql_create' : ["matplotlib",],
},
keywords = 'Brother QL-500 QL-570 QL-710W QL-720NW',
classifiers = [