A lot of renaming variables, tools; improved README
This commit is contained in:
@@ -1,18 +1,29 @@
|
|||||||
brother\_ql
|
## brother\_ql ##
|
||||||
===========
|
|
||||||
|
|
||||||
A Python package to control Brother QL label printers.
|
A Python package to control Brother QL label printers.
|
||||||
|
|
||||||
|
### Installation ###
|
||||||
Installation
|
|
||||||
------------
|
|
||||||
|
|
||||||
pip install https://github.com/pklaus/brother_ql/archive/master.zip
|
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.
|
||||||
|
|||||||
Executable
+20
@@ -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()
|
||||||
@@ -5,7 +5,7 @@ import sys, argparse, logging
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
from brother_ql.writer import QLRaster
|
from brother_ql.writer import BrotherQLRaster
|
||||||
|
|
||||||
def hex_format(data):
|
def hex_format(data):
|
||||||
return ' '.join('{:02X}'.format(byte) for byte in data)
|
return ' '.join('{:02X}'.format(byte) for byte in data)
|
||||||
@@ -37,7 +37,7 @@ def main():
|
|||||||
arr[white_idx] = 1
|
arr[white_idx] = 1
|
||||||
arr[black_idx] = 0
|
arr[black_idx] = 0
|
||||||
|
|
||||||
qlr = QLRaster(args.model)
|
qlr = BrotherQLRaster(args.model)
|
||||||
qlr.set_mode()
|
qlr.set_mode()
|
||||||
qlr.set_clear_command_buffer()
|
qlr.set_clear_command_buffer()
|
||||||
qlr.set_initialize()
|
qlr.set_initialize()
|
||||||
|
|||||||
+2
-17
@@ -36,7 +36,7 @@ dot_widths = {
|
|||||||
def hex_format(data):
|
def hex_format(data):
|
||||||
return ' '.join('{:02X}'.format(byte) for byte in data)
|
return ' '.join('{:02X}'.format(byte) for byte in data)
|
||||||
|
|
||||||
class BrotherReader(object):
|
class BrotherQLReader(object):
|
||||||
|
|
||||||
def __init__(self, brother_file):
|
def __init__(self, brother_file):
|
||||||
if type(brother_file) in (str,):
|
if type(brother_file) in (str,):
|
||||||
@@ -48,7 +48,7 @@ class BrotherReader(object):
|
|||||||
self.compression = False
|
self.compression = False
|
||||||
self.page = 1
|
self.page = 1
|
||||||
|
|
||||||
def analyze(self):
|
def analyse(self):
|
||||||
rem_script = self.brother_file.read()
|
rem_script = self.brother_file.read()
|
||||||
while True:
|
while True:
|
||||||
if len(rem_script) == 0: break
|
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]))
|
logger.error('cmd not found: {0}... ({1}...)'.format(hex_format(rem_script[0:4]), rem_script[0:4]))
|
||||||
rem_script = rem_script[1:]
|
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()
|
|
||||||
|
|||||||
@@ -17,11 +17,11 @@ from .devicedependent import models, \
|
|||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
class QLRaster(object):
|
class BrotherQLRaster(object):
|
||||||
|
|
||||||
def __init__(self, model='QL-500'):
|
def __init__(self, model='QL-500'):
|
||||||
if model not in models:
|
if model not in models:
|
||||||
raise QLRasterUnknownModel()
|
raise BrotherQLRasterUnknownModel()
|
||||||
self.model = model
|
self.model = model
|
||||||
self.data = b''
|
self.data = b''
|
||||||
self._pquality = 1
|
self._pquality = 1
|
||||||
@@ -33,7 +33,7 @@ class QLRaster(object):
|
|||||||
|
|
||||||
def warn(self, problem):
|
def warn(self, problem):
|
||||||
if self.exception_on_warning:
|
if self.exception_on_warning:
|
||||||
raise QLRasterError(problem)
|
raise BrotherQLRasterError(problem)
|
||||||
else:
|
else:
|
||||||
logger.warning(problem)
|
logger.warning(problem)
|
||||||
|
|
||||||
@@ -136,7 +136,7 @@ class QLRaster(object):
|
|||||||
row = bytes(np.packbits(row))
|
row = bytes(np.packbits(row))
|
||||||
if len(row) != nbpr:
|
if len(row) != nbpr:
|
||||||
fmt = 'Wrong number of bytes per row: {}, expected {}'
|
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:
|
if self._compression:
|
||||||
row = packbits.encode(row)
|
row = packbits.encode(row)
|
||||||
self.data += bytes([len(row)])
|
self.data += bytes([len(row)])
|
||||||
@@ -148,6 +148,6 @@ class QLRaster(object):
|
|||||||
else:
|
else:
|
||||||
self.data += b'\x0C'
|
self.data += b'\x0C'
|
||||||
|
|
||||||
class QLRasterError(Exception): pass
|
class BrotherQLRasterError(Exception): pass
|
||||||
class QLRasterUnknownModel(QLRasterError): pass
|
class BrotherQLRasterUnknownModel(BrotherQLRasterError): pass
|
||||||
|
|
||||||
|
|||||||
@@ -16,16 +16,17 @@ setup(name='brother_ql',
|
|||||||
packages = ['brother_ql'],
|
packages = ['brother_ql'],
|
||||||
entry_points = {
|
entry_points = {
|
||||||
'console_scripts': [
|
'console_scripts': [
|
||||||
'brother_ql_read = brother_ql.reader:main',
|
'brother_ql_analyse = brother_ql.analyse:main',
|
||||||
'brother_ql_write = brother_ql.create:main',
|
'brother_ql_create = brother_ql.create:main',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
include_package_data = False,
|
include_package_data = False,
|
||||||
zip_safe = True,
|
zip_safe = True,
|
||||||
platforms = 'any',
|
platforms = 'any',
|
||||||
install_requires = ['numpy', 'packbits', 'pillow'],
|
install_requires = ['numpy', 'packbits', 'pillow', 'matplotlib'],
|
||||||
extras_require = {
|
extras_require = {
|
||||||
'brother_ql_read': ["matplotlib",],
|
#'brother_ql_analyse': ["matplotlib",],
|
||||||
|
#'brother_ql_create' : ["matplotlib",],
|
||||||
},
|
},
|
||||||
keywords = 'Brother QL-500 QL-570 QL-710W QL-720NW',
|
keywords = 'Brother QL-500 QL-570 QL-710W QL-720NW',
|
||||||
classifiers = [
|
classifiers = [
|
||||||
|
|||||||
Reference in New Issue
Block a user