Ejemplo n.º 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
Ejemplo n.º 2
0
def print_chat():
    printer = Adafruit_Thermal("/dev/serial0", 19200, timeout=5)
    printer.feed(3)
    printer.setSize('L')
    printer.printTHIS("CHATBOTS ON THE RISE")
    printer.printTHIS("ELIZA (1964)")
    printer.setDefault()

    for chat in session['chats']:
        speaker, message = chat
        if speaker == "eliza":
            printer.inverseOn()
            printer.printTHIS(message)
            printer.inverseOff()
        else:
            printer.printTHIS("> " + message)

        printer.feed(2)

    printer.printTHIS(' -- END --')
    printer.feed(3)
    session.clear()
    return redirect('/')
Ejemplo n.º 3
0
  (searchUrl + 'count=3&since_id=%s&q=%s' %
   (lastId, urllib.quote(queryString))),
  None,
  {'Host'            : host,
   'User-Agent'      : agent,
   'Accept-Encoding' : 'gzip',
   'Authorization'   : 'Bearer ' + token})


# Display results. ---------------------------------------------------------

maxId = data['search_metadata']['max_id_str']

for tweet in data['statuses']:

  printer.inverseOn()
  printer.print(' ' + '{:<31}'.format(tweet['user']['screen_name']))
  printer.inverseOff()

  printer.underlineOn()
  printer.print('{:<32}'.format(tweet['created_at']))
  printer.underlineOff()

  # max_id_str is not always present, so check tweet IDs as fallback
  id = tweet['id_str']
  if(id > maxId): maxId = id # String compare is OK for this

  # Remove HTML escape sequences
  # and remap Unicode values to nearest ASCII equivalents
  printer.print(unidecode(
    HTMLParser.HTMLParser().unescape(tweet['text'])))
Ejemplo n.º 4
0
#!/usr/bin/python

from Adafruit_Thermal import *

printer = Adafruit_Thermal("/dev/ttyUSB0", 19200, timeout=5)

# Test inverse on & off
printer.inverseOn()
printer.println("Inverse ON")
printer.inverseOff()

# Test character double-height on & off
printer.doubleHeightOn()
printer.println("Double Height ON")
printer.doubleHeightOff()

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

# Test more styles
printer.boldOn()
printer.println("Bold text")
printer.boldOff()

printer.underlineOn()
printer.println("Underlined text")
Ejemplo n.º 5
0
class Printer(object):
    """This class represents the printer"""

    def __init__(self, device, baud_rate, timeout):
        """Printer initialization
        
        :param device: Device path
        :type device: str
        :param baud: Baud rate
        :type baud: int
        :param timeout: Timeout in seconds
        :type timeout: int
        """
        self.print_size = 384, 384  # max_width=384

        self.device = Adafruit_Thermal(device, baud_rate, timeout=timeout)

    def _calibrate(self):
        for i in range(0, 256, 15):
            self.device.begin(i)
            self.device.println(i)  # Print heat time
            self.device.inverseOn()
            self.device.print("{:^32}".format(""))  # Print 32 spaces (inverted)
            self.device.inverseOff()

        self.device.begin()  # Reset heat time to default
        self.device.feed(4)

    def print_image(self, image_file_path, event):
        """Print Image

        :param image_file_path: Image file path
        :type image_file_path: str
        """
        # print logo
        self.device.printImage(Image.open(event["logo"]), True)

        self.device.justify("C")

        self.device.doubleHeightOn()
        self.device.println(event["title"])

        self.device.doubleHeightOff()
        self.device.println(datetime.now().strftime("%d-%m-%Y %H:%M:%S"))  # time

        self.device.feed(1)

        # print picture
        image_code = os.path.splitext(os.path.basename(image_file_path))[0]
        image_for_print_path = "{}.print".format(image_file_path)
        image_for_print = Image.open(image_file_path)  # create proxy image for print
        image_for_print = image_for_print.transpose(Image.ROTATE_180)  # rotate image
        w, h = image_for_print.size
        image_for_print.crop((int((w - h) / 2), 0, int((w - h) / 2), 0))
        image_for_print.thumbnail(self.print_size, Image.ANTIALIAS)  # resize
        image_for_print.save(image_for_print_path, "JPEG")  # save
        self.device.printImage(Image.open(image_for_print_path), True)
        self.device.feed(1)

        # print text
        self.device.println(event["place"])
        self.device.feed(1)

        # line
        self.device.println("------------------------------")

        self.device.feed(1)
        self.device.boldOn()
        self.device.println("partagez votre")
        self.device.println("photo avec le code")
        self.device.boldOff()
        self.device.doubleHeightOn()
        self.device.doubleWidthOn()
        self.device.println(image_code)
        self.device.doubleWidthOff()
        self.device.doubleHeightOff()
        self.device.boldOn()
        self.device.println("sur")
        self.device.boldOff()
        self.device.println("shootomatic.net")
        self.device.feed(1)

        # line
        self.device.println("------------------------------")

        # space to detach
        self.device.feed(3)

        # delete proxy image used for print
        os.remove(image_for_print_path)