Exemplo n.º 1
0
def testBarcode(printjob):
    barcodes = [
        'code39', 'itf', 'ean8/upca', 'upce', 'codabar', 'code128', 'gs1-128',
        'rss'
    ]
    labelprinter = Labelprinter(conf=None, printjob=printjob)
    labelprinter.printBarcode("TEST", barcodes[2])
Exemplo n.º 2
0
def testLabel(printjob):
    TEST_FONT = 'lettergothic'
    TEST_CHAR_SIZE = '75'
    TEST_BOLD = 'on'
    TEST_TEXT = "auf deinem Grab"
    labelprinter = Labelprinter(conf=None, printjob=printjob)
    labelprinter.printText(TEST_TEXT,
                           charSize=TEST_CHAR_SIZE,
                           font=TEST_FONT,
                           bold=TEST_BOLD)
Exemplo n.º 3
0
def testQRcode(printjob):
    labelprinter = Labelprinter(conf=None, printjob=printjob)
    # data, cell_size=4, symbol_type=2, partitioned=0, partition=0, parity=0, error_correction=4, data_input=0):

    #printjob.qr_code(**{'data':'noot noot', 'cell_size':10, 'symbol_type':2})
    printjob.qr_code('noot noot', 10)
    printjob.line_feed()
    printjob.select_font('lettergothic')
    printjob.char_size('11')

    printjob.send("noot noot")
    printjob.char_style('normal')
    printjob.print_page('full')
Exemplo n.º 4
0

def text(args, labelprinter):
    bold = 'on' if args.bold else 'off'
    labelprinter.printText(args.text,
                           charSize=args.char_size,
                           font=args.font,
                           align=args.align,
                           bold=bold,
                           charStyle=args.char_style,
                           cut=args.cut)


parser = argparse.ArgumentParser(
    description="A command line interface to Labello.")
subparsers = parser.add_subparsers(help="commands")
parser_text = subparsers.add_parser("text", help="print a text")
parser_text.add_argument("text", type=str, help="the text to print")
parser_text.add_argument("--char_size", type=str, default='42')
parser_text.add_argument("--font", type=str, default='lettergothic')
parser_text.add_argument("--align", type=str, default='left')
parser_text.add_argument("--bold", action='store_true')
parser_text.add_argument("--char_style", type=str, default='normal')
parser_text.add_argument("--cut", type=str, default='full')
parser_text.set_defaults(func=text)

args = parser.parse_args()

labelprinter = Labelprinter(conf=conf)
args.func(args, labelprinter)
Exemplo n.º 5
0
class MyHandler(BaseHTTPRequestHandler):
    labelprinter = Labelprinter(conf=conf)

    def do_GET(self):
        try:
            self.send_response(200)
            self.send_header('Content-type', 'text/html')
            self.end_headers()

            template = ''

            finalPath = self.path
            templateReplaceDict = {}
            print 'self.path', self.path
            if finalPath == '/':
                finalPath = conf.SERVER_DEFAULT_TEMPLATE

            if finalPath == '/base':
                import templates.base
                templateReplaceDict = templates.base.getParseDict()
                template = open('templates/base.html').read()
            elif finalPath == '/barcode':
                import templates.barcode
                templateReplaceDict = templates.barcode.getParseDict()
                template = open('templates/barcode.html').read()
            elif finalPath == '/magic':
                import templates.magic
                templateReplaceDict = templates.magic.getParseDict()
                template = open('templates/magic.html').read()
            elif finalPath == '/choose':
                template = open('templates/choose.html').read()
            elif finalPath == '/app.js':
                import templates.magic
                templateReplaceDict = templates.magic.getParseDict()
                template = open('www/app.js').read()
            else:
                template = open('www' + finalPath).read()

            for replaceKey, replaceValue in templateReplaceDict.iteritems():
                template = template.replace('{{' + replaceKey + '}}',
                                            replaceValue)

            self.wfile.write(template)

            return

        except Exception as ex:
            self.send_error(404, 'File Not Found: {} {}'.format(self.path, ex))

    def do_POST(self):
        self.send_response(301)
        try:
            ctype, pdict = cgi.parse_header(
                self.headers.getheader('content-type'))
            print ctype, pdict
            query = None

            if ctype == 'multipart/form-data':
                query = cgi.parse_multipart(self.rfile, pdict)
            elif ctype == 'application/x-www-form-urlencoded':
                length = int(self.headers.getheader('content-length'))
                query = cgi.parse_qs(self.rfile.read(length),
                                     keep_blank_values=1)

            print query
            self.end_headers()
            text = query.get('text')

            finalTxt = ''
            for txt in text:
                finalTxt += txt

            if finalTxt.strip() == '':
                raise RuntimeError('NO TEXT, NO LABEL!')

            self.wfile.write("POST OK.\n")
            self.wfile.write("start printing: " + finalTxt + "\n")

            print finalTxt

            if query.get('printMode', [''])[0] == 'barcode':
                self.labelprinter.printBarcode(
                    finalTxt,
                    barcode=query.get('barcodeType', ['code39'])[0],
                    characters=query.get('barcodeCharacters', ['on'])[0],
                    height=int(query.get('barcodeHeight', [100])[0]),
                    width=query.get('barcodeWidth', ['medium'])[0],
                    parentheses=query.get('barcodeParentheses', ['on'])[0],
                    ratio=query.get('barcodeRatio', ['3:1'])[0],
                    equalize=query.get('barcodeEqualize', ['off'])[0])
            else:
                self.labelprinter.printText(
                    finalTxt,
                    charSize=query.get('fontSize', [42])[0],
                    font=query.get('font', ['lettergothic'])[0],
                    align=query.get('align', ['left'])[0],
                    bold=query.get('bold', ['off'])[0],
                    charStyle=query.get('charStyle', ['normal'])[0],
                    cut=query.get('cut', ['full'])[0],
                )
        except Exception as ex:
            print 'ERROR:', ex
            self.wfile.write("ERROR: " + str(ex))
Exemplo n.º 6
0
    def do_POST(self):
        self.send_response(301)
        try:
            printMode = "default"

            ctype, pdict = cgi.parse_header(self.headers.get('content-type'))
            logging.debug(log_print(ctype, pdict))
            query = None
            clength = int(self.headers.get('content-length'))

            if ctype == 'multipart/form-data':
                logging.debug(log_print(self.rfile))
                for key in pdict.keys():
                    pdict[key] = pdict[key].encode("utf-8")
                pdict["CONTENT-LENGTH"] = clength
                query = cgi.parse_multipart(self.rfile, pdict)
            elif ctype == 'application/x-www-form-urlencoded':
                if sys.version_info.major == 2:
                    data = self.rfile.read(clength)
                else:
                    data = self.rfile.read(clength).decode('utf-8')
                query = parse_qs(data, keep_blank_values=1)
            elif ctype == "application/json":
                query = json.loads(self.rfile.read(clength).decode("utf-8"))

            if ctype != "application/json":
                strip_query(query)

            logging.debug(log_print(query))
            self.end_headers()

            if query['text'].strip() == '':
                raise RuntimeError('NO TEXT, NO LABEL!')

            self.wfile.write(b"POST OK.\n")
            self.wfile.write("start printing: {}\n".format(
                query['text']).encode("utf-8"))

            labelprinter = Labelprinter(conf=conf)

            if query.get('printMode', '') == 'barcode':
                labelprinter.printBarcode(
                    query['text'],
                    barcode=query.get('barcodeType', 'code39'),
                    characters=query.get('barcodeCharacters', 'on'),
                    height=int(query.get('barcodeHeight', 100)),
                    width=query.get('barcodeWidth', 'medium'),
                    parentheses=query.get('barcodeParentheses', 'on'),
                    ratio=query.get('barcodeRatio', '3:1'),
                    equalize=query.get('barcodeEqualize', 'off'))

            elif printMode == 'pictures':
                logging.debug(log_print('pictures!!!!!!'))
                logging.debug(log_print(query.keys()))

                submit_picture = query.get('submitPicture', [None])[0]
                labelprinter.printPicture(submit_picture)
            else:
                labelprinter.printText(
                    query['text'],
                    charSize=query.get('fontSize', 42),
                    font=query.get('font', 'lettergothic'),
                    align=query.get('align', 'left'),
                    bold=query.get('bold', 'off'),
                    charStyle=query.get('charStyle', 'normal'),
                    cut=query.get('cut', 'full'),
                )

        except Exception as ex:
            if "sentry_sdk" in globals():
                sentry_sdk.capture_exception(ex)

            logging.error(log_print('ERROR:', ex))
            import traceback
            traceback.print_exc()
            self.send_error(500, "ERROR: {}".format(ex))