refactor PEP8 and code style

This commit is contained in:
Patrick Kanzler 2016-06-19 12:25:40 +02:00
parent e814396bd8
commit 6697922b74
7 changed files with 48 additions and 37 deletions

View File

@ -18,6 +18,7 @@ import sys
import six
from . import config
# Must be defined before it's used in DEMO_FUNCTIONS
def str_to_bool(string):
""" Used as a type in argparse so that we get back a proper
@ -34,7 +35,7 @@ REQUIRES_NEWLINE = ('qr', 'barcode', 'text', 'block_text')
# Value: A list of dictionaries to pass to the escpos function as arguments.
DEMO_FUNCTIONS = {
'text': [
{'txt': 'Hello, World!\n',}
{'txt': 'Hello, World!\n', }
],
'qr': [
{'content': 'This tests a QR code'},
@ -427,6 +428,7 @@ ESCPOS_COMMANDS = [
},
]
def main():
"""
@ -504,7 +506,6 @@ def main():
saved_config.load(config_path)
printer = saved_config.printer()
if not printer:
raise Exception('No printers loaded from config')
@ -519,6 +520,7 @@ def main():
command_arguments['printer'] = printer
globals()[target_command](**command_arguments)
def demo(printer, **kwargs):
"""
Prints specificed demos. Called when CLI is passed `demo`. This function

View File

@ -16,6 +16,7 @@ import yaml
from . import printer
from . import exceptions
class Config(object):
""" Configuration handler class.
@ -115,4 +116,3 @@ class Config(object):
self._printer = getattr(printer, self._printer_name)(**self._printer_config)
return self._printer

View File

@ -45,7 +45,7 @@ HW_SELECT = ESC + b'=\x01' # Printer select
HW_RESET = ESC + b'\x3f\x0a\x00' # Reset printer hardware
# (TODO: Where is this specified?)
#{ Cash Drawer (ESC p <pin> <on time: 2*ms> <off time: 2*ms>)
# Cash Drawer (ESC p <pin> <on time: 2*ms> <off time: 2*ms>)
_CASH_DRAWER = lambda m, t1='', t2='': ESC + b'p' + m + six.int2byte(t1) + six.int2byte(t2)
CD_KICK_2 = _CASH_DRAWER(b'\x00', 50, 50) # Sends a pulse to pin 2 []
CD_KICK_5 = _CASH_DRAWER(b'\x01', 50, 50) # Sends a pulse to pin 5 []
@ -137,7 +137,7 @@ BARCODE_FONT_B = _SET_HRI_FONT(b'\x01') # Font type B for HRI barcode chars
BARCODE_HEIGHT = GS + b'h' # Barcode Height [1-255]
BARCODE_WIDTH = GS + b'w' # Barcode Width [2-6]
#NOTE: This isn't actually an ESC/POS command. It's the common prefix to the
# NOTE: This isn't actually an ESC/POS command. It's the common prefix to the
# two "print bar code" commands:
# - Type A: "GS k <type as integer> <data> NUL"
# - TYPE B: "GS k <type as letter> <data length> <data>"
@ -184,13 +184,13 @@ BARCODE_TYPES = {
'B': BARCODE_TYPE_B,
}
## QRCode error correction levels
# QRCode error correction levels
QR_ECLEVEL_L = 0
QR_ECLEVEL_M = 1
QR_ECLEVEL_Q = 2
QR_ECLEVEL_H = 3
## QRcode models
# QRcode models
QR_MODEL_1 = 1
QR_MODEL_2 = 2
QR_MICRO = 3

View File

@ -24,6 +24,7 @@ from .exceptions import *
from abc import ABCMeta, abstractmethod # abstract base class support
from escpos.image import EscposImage
@six.add_metaclass(ABCMeta)
class Escpos(object):
""" ESC/POS Printer object
@ -122,11 +123,14 @@ class Escpos(object):
""" Print QR Code for the provided string
:param content: The content of the code. Numeric data will be more efficiently compacted.
:param ec: Error-correction level to use. One of QR_ECLEVEL_L (default), QR_ECLEVEL_M, QR_ECLEVEL_Q or QR_ECLEVEL_H.
:param ec: Error-correction level to use. One of QR_ECLEVEL_L (default), QR_ECLEVEL_M, QR_ECLEVEL_Q or
QR_ECLEVEL_H.
Higher error correction results in a less compact code.
:param size: Pixel size to use. Must be 1-16 (default 3)
:param model: QR code model to use. Must be one of QR_MODEL_1, QR_MODEL_2 (default) or QR_MICRO (not supported by all printers).
:param native: True to render the code on the printer, False to render the code as an image and send it to the printer (Default)
:param model: QR code model to use. Must be one of QR_MODEL_1, QR_MODEL_2 (default) or QR_MICRO (not supported
by all printers).
:param native: True to render the code on the printer, False to render the code as an image and send it to the
printer (Default)
"""
# Basic validation
if ec not in [QR_ECLEVEL_L, QR_ECLEVEL_M, QR_ECLEVEL_H, QR_ECLEVEL_Q]:
@ -435,7 +439,8 @@ class Escpos(object):
col_count = self.columns if columns is None else columns
self.text(textwrap.fill(txt, col_count))
def set(self, align='left', font='a', text_type='normal', width=1, height=1, density=9, invert=False, smooth=False, flip=False):
def set(self, align='left', font='a', text_type='normal', width=1, height=1, density=9, invert=False, smooth=False,
flip=False):
""" Set text properties by sending them to the printer
:param align: horizontal position for text, possible values are:

View File

@ -210,6 +210,7 @@ class ConfigNotFoundError(Error):
def __str__(self):
return "Configuration not found ({msg})".format(msg=self.msg)
class ConfigSyntaxError(Error):
""" The configuration file is invalid
@ -224,6 +225,7 @@ class ConfigSyntaxError(Error):
def __str__(self):
return "Configuration syntax is invalid ({msg})".format(msg=self.msg)
class ConfigSectionMissingError(Error):
""" The configuration file is missing a section

View File

@ -21,6 +21,7 @@ import socket
from .escpos import Escpos
from .exceptions import *
class Usb(Escpos):
""" USB printer
@ -261,6 +262,7 @@ class File(Escpos):
self.device.flush()
self.device.close()
class Dummy(Escpos):
""" Dummy printer

View File

@ -3,7 +3,7 @@
import os
import sys
from setuptools import setup
from setuptools.command.test import test as TestCommand
from setuptools.command.test import test as test_command
def read(fname):
@ -11,18 +11,18 @@ def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read()
class Tox(TestCommand):
class Tox(test_command):
"""proxy class that enables tox to be run with setup.py test"""
user_options = [('tox-args=', 'a', "Arguments to pass to tox")]
def initialize_options(self):
"""initialize the user-options"""
TestCommand.initialize_options(self)
test_command.initialize_options(self)
self.tox_args = None
def finalize_options(self):
"""finalize user-options"""
TestCommand.finalize_options(self)
test_command.finalize_options(self)
self.test_args = []
self.test_suite = True