From b7ffd3e6dea2fad78f74ceac07b420ca518de3d3 Mon Sep 17 00:00:00 2001 From: LittleCoder Date: Fri, 15 Jul 2016 16:49:24 +0800 Subject: [PATCH] Use better look cmd QRCode [PR#36: tempdban] --- plugin/QRCode.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/plugin/QRCode.py b/plugin/QRCode.py index 04c02a0..27c578a 100644 --- a/plugin/QRCode.py +++ b/plugin/QRCode.py @@ -1,7 +1,15 @@ from PIL import Image -import sys, os, platform +import sys, os -BLOCK = '\xA1\xF6' if platform.system() == 'Windows' else 'MM' +QR_DIR = '.' +try: + b = u'\u2588'.encode(sys.stdin.encoding) + sys.stdout.write(b + '\r') + sys.stdout.flush() +except: + BLOCK = 'MM' +else: + BLOCK = b class QRCode(): def __init__(self, fileName, size, padding = 0, background = 'BLACK'): @@ -15,16 +23,17 @@ class QRCode(): def print_qr(self): sys.stdout.write(' '*50 + '\r') sys.stdout.flush() - print self.white * (self.size + 2) + print(self.white * (self.size + 2)) startPoint = self.padding + 0.5 for y in range(self.size): sys.stdout.write(self.white) for x in range(self.size): r,g,b = self.rgb.getpixel(((x + startPoint) * self.times, (y + startPoint) * self.times)) sys.stdout.write(self.white if r > 127 else self.black) - print self.white - print self.white * (self.size + 2) + print(self.white) + print(self.white * (self.size + 2)) if __name__ == '__main__': + # 37 is for picture size without padding, 3 is padding q = QRCode(os.path.join(os.path.pardir, 'log', 'QR.jpg'), 37, 3, 'BLACK') q.print_qr() -- GitLab