Example #1
0
def Text(name, theme):
    printer = Adafruit_Thermal("/dev/serial0", 19200, timeout=5)
    # Test inverse on & off
    printer.inverseOn()
    # printer.println("Inverse ON")
    # Test character double-height on & off
    #printer.doubleHeightOn()
    printer.println("On vous recommande le livre suivant :")
    #printer.doubleHeightOff()
    printer.inverseOff()

    # Set justification (right, center, left) -- accepts 'L', 'C', 'R'
    # printer.justify('R')
    # printer.println("Right justified")
    printer.justify('C')
    printer.println(name)

    printer.inverseOn()
    # printer.println("Inverse ON")
    # Test character double-height on & off
    #printer.doubleHeightOn()
    printer.println("Le thème de ce livre est :")
    #printer.doubleHeightOff()
    printer.inverseOff()

    printer.justify('C')
    printer.println(theme)

    # printer.justify('L')
    # printer.println("Left justified")
    # Test more styles
    printer.boldOn()
    printer.println("Bold text")
    printer.boldOff()
    printer.underlineOn()
    printer.println("Underlined text")
    printer.underlineOff()
    printer.setSize('L')  # Set type size, accepts 'S', 'M', 'L'
    printer.println("Large")
    printer.setSize('M')
    printer.println("Medium")
    printer.setSize('S')
    printer.println("Small")
    printer.justify('C')
    printer.println("normal\nline\nspacing")
    printer.setLineHeight(50)
    printer.println("Taller\nline\nspacing")
    printer.setLineHeight()  # Reset to default
    printer.justify('L')
    # Barcode examples
    printer.feed(1)
    # CODE39 is the most common alphanumeric barcode
    printer.printBarcode("ADAFRUT", printer.CODE39)
    printer.setBarcodeHeight(100)
    # Print UPC line on product barcodes
    printer.printBarcode("123456789123", printer.UPC_A)

    printer.sleep()  # Tell printer to sleep
    printer.wake()  # Call wake() before printing again, even if reset
    printer.setDefault()  # Restore printer to defaults
Example #2
0
def __print_poem(poem_text, upc):
    printer = Adafruit_Thermal("/dev/ttyS0", 19200, timeout=60)
    printer.setSize('M')
    printer.justify('C')
    printer.println("1st Regional Bunny Bank\n\n")
    printer.println("\n")
    printer.justify('C')
    printer.println("================================")

    printer.justify('C')
    printer.setSize('M')
    printer.println(poem_text, length=29)

    printer.feed(1)
    printer.setBarcodeHeight(100)
    printer.printBarcode(upc, printer.UPC_A)

    #printer.setSize('S')
    #printer.setSize('S')
    #printer.println(text_format(TOS_MESSAGE))

    printer.feed(30)

    printer.sleep()
    printer.wake()
    printer.setDefault()
Example #3
0
printer.setSize('M')
printer.println("Medium")
printer.setSize('S')
printer.println("Small")

printer.justify('C')
printer.println("normal\nline\nspacing")
printer.setLineHeight(50)
printer.println("Taller\nline\nspacing")
printer.setLineHeight()  # Reset to default
printer.justify('L')

# Barcode examples
printer.feed(1)
# CODE39 is the most common alphanumeric barcode
printer.printBarcode("ADAFRUT", printer.CODE39)
printer.setBarcodeHeight(100)
# Print UPC line on product barcodes
printer.printBarcode("123456789123", printer.UPC_A)

# Print the 75x75 pixel logo in adalogo.py
import gfx.adalogo as adalogo
printer.printBitmap(adalogo.width, adalogo.height, adalogo.data)

# Print the 135x135 pixel QR code in adaqrcode.py
import gfx.adaqrcode as adaqrcode
printer.printBitmap(adaqrcode.width, adaqrcode.height, adaqrcode.data)
printer.println("Adafruit!")
printer.feed(2)

printer.sleep()  # Tell printer to sleep
printer.setSize('M')
printer.println("Medium")
printer.setSize('S')
printer.println("Small")

printer.justify('C')
printer.println("normal\nline\nspacing")
printer.setLineHeight(50)
printer.println("Taller\nline\nspacing")
printer.setLineHeight() # Reset to default
printer.justify('L')

# Barcode examples
printer.feed(1)
# CODE39 is the most common alphanumeric barcode
printer.printBarcode("ADAFRUT", printer.CODE39)
printer.setBarcodeHeight(100)
# Print UPC line on product barcodes
printer.printBarcode("123456789123", printer.UPC_A)

# Print the 75x75 pixel logo in adalogo.py
import gfx.adalogo as adalogo
printer.printBitmap(adalogo.width, adalogo.height, adalogo.data)

# Print the 135x135 pixel QR code in adaqrcode.py
import gfx.adaqrcode as adaqrcode
printer.printBitmap(adaqrcode.width, adaqrcode.height, adaqrcode.data)
printer.println("Adafruit!")
printer.feed(3)

# Reset printer
Example #5
0
(x, y) = (50, 385)
color = 'rgb(0, 0, 0)'
font = ImageFont.truetype('printer/fonts/Bitter-Bold.ttf', size=36)
w, h = draw.textsize(name, font=font)
draw.text(((384-w)/2, y), name, fill=color, font=font)

# Add the voicemsg length to the canvas, e.g. length = '4:20s'
(x, y) = (115, 265)
w, h = draw.textsize(length, font=font)
draw.text((x, y), length, fill=color, font=font)

# Add the date and time to the canvas, e.g. date = '07.03.19 | 15:10'
(x, y) = (115, 230)
font = ImageFont.truetype('printer/fonts/Bitter-Italic.ttf', size=30)
w, h = draw.textsize(date, font=font)
draw.text((x, y), date, fill=color, font=font)

# Rotate the image by 180deg and save it next to the voicemsg file
image.rotate(180).save(filePath)

# Print the Barcode, e.g. barcode = '151023'
printer.upsideDownOn()
printer.justify('C')
printer.setBarcodeHeight(100)
printer.printBarcode(bytes(barcode), printer.CODE128)
printer.feed(3)

# Load the generated image and print it
printer.printImage(Image.open(filePath), True)
printer.feed(6)
Example #6
0
                    if winall == 1:
                        printer.justify('C')
                        printer.setSize('M')
                        printer.println("Winner")
                    printer.justify('C')
                    printer.setSize('M')
                    printer.print(garesult)
                    printer.print(' secounds with ')
                    printer.print(quickroundtotal)
                    printer.println(' Hits')

        #Now we print the barcode last and also add print time and date.
        printer.justify('C')
        printer.setSize('M')
        printer.println("Game played: ")
        printer.println(gamename)
        printer.feed(1)
        ocode = gamecode.encode('utf-8')
        printer.printBarcode(ocode, printer.CODE128)
        #Done now remove printjob
        delcurs = db.cursor()
        sql = "DELETE FROM printjob"
        delcurs.execute(sql)
        db.commit()
        startprint = 0

        #printer.sleep()      # Tell printer to sleep
        #printer.wake()       # Call wake() before printing again, even if reset
        printer.setDefault()  # Restore printer to defaults
        printer.begin()
class ThermalPrinter:
    def __init__(self, photo_data=None, image_width=0, image_height=0):
        self.photo_data = photo_data
        self.photo_width = image_width
        self.photo_height = image_height

    def generateRandomNumber(self, digits):
        number = ""
        for x in range(0, digits):
            number += str(random.randint(1, 9))
        return number

    def printLine(self,
                  line,
                  justify='L',
                  fontSize='S',
                  bold=False,
                  underline=False,
                  feed=0):

        if (bold):
            self.printer.boldOn()
        if (underline):
            self.printer.underlineOn()

        self.printer.justify(justify)
        self.printer.setSize(fontSize)
        self.printer.println(line)
        self.printer.boldOff()
        self.printer.underlineOff()

        if (feed > 0):
            self.printer.feed(feed)

    def printReceipt(self, fee):
        self.printer = Adafruit_Thermal("/dev/serial0", 19200, timeout=5)
        self.printData(fee.age, fee.makeup, fee.pyjama, fee.hipster,
                       fee.youngster, fee.oldie, fee.badMood, fee.aggressive)
        self.printer.sleep()  # Tell printer to sleep
        self.printer.wake()  # Call wake() before printing again, even if reset
        self.printer.setDefault()  # Restore printer to defaults

    def formattedCurrency(self, number):
        if (number < 10):
            return "  " + str(number)
        if (number < 100):
            return " " + str(number)
        return str(number)

    def printData(self, age, makeupFee, pyjamaFee, hipsterFee, youngsterFee,
                  oldieFee, badMoodFee, aggressiveFee):
        #Print logo
        import gfx.logo as logo
        self.printer.printBitmap(logo.width, logo.height, logo.data)
        self.printLine("BRUTUS", 'C', 'L', True, False, 1)

        #Print photo
        if self.photo_data is not None:
            self.printer.printBitmap(self.photo_width, self.photo_height,
                                     self.photo_data)

        self.printer.feed(1)
        self.printer.setLineHeight(36)

        baseFee = 8
        totalFee = baseFee + makeupFee + pyjamaFee + hipsterFee + youngsterFee + oldieFee + badMoodFee + aggressiveFee

        #Print Content
        self.printLine("Estimated age                " + str(age), 'L', 'S',
                       True)
        self.printLine(
            "Base Fee                EUR " + self.formattedCurrency(baseFee),
            'L', 'S', False, False, 1)

        self.printLine("Appearance Cost", 'L', 'S', True)
        self.printLine("No-Make-Up Fee          EUR " +
                       self.formattedCurrency(makeupFee))
        self.printLine("Underdressed Fee        EUR " +
                       self.formattedCurrency(pyjamaFee))
        self.printLine("Hipster Fee             EUR " +
                       self.formattedCurrency(hipsterFee))
        self.printer.feed(1)

        self.printLine("General Cost", 'L', 'S', True)
        self.printLine("Youngster Fee           EUR " +
                       self.formattedCurrency(youngsterFee))
        self.printLine("Oldie Fee               EUR " +
                       self.formattedCurrency(oldieFee))
        self.printLine("Bad Mood Fee            EUR " +
                       self.formattedCurrency(badMoodFee))
        self.printLine("Aggressive Behavior Fee EUR " +
                       self.formattedCurrency(aggressiveFee))
        self.printer.feed(1)

        #Print Total
        self.printLine(
            "Total                   EUR " + self.formattedCurrency(totalFee),
            'L', 'S', True, True, 1)

        #Print Barcode
        self.printer.setBarcodeHeight(100)
        number = self.generateRandomNumber(13)
        self.printer.printBarcode(number, self.printer.EAN13)

        self.printer.feed(2)