diff --git a/clipboardqr.py b/clipboardqr.py deleted file mode 100644 index 6c1e696..0000000 --- a/clipboardqr.py +++ /dev/null @@ -1,4 +0,0 @@ -import pyperclip -import qrcode - -qrcode.make(pyperclip.paste()).show() diff --git a/showqr.py b/showqr.py new file mode 100644 index 0000000..bf67187 --- /dev/null +++ b/showqr.py @@ -0,0 +1,54 @@ +import argparse +import os +import PIL.ImageTk +import qrcode +import sys +import tkinter +import tkinter.filedialog + +from voussoirkit import pipeable + +def save_image(root, image): + filename = tkinter.filedialog.asksaveasfilename( + parent=root, + initialdir=os.getcwd(), + filetypes=[('PNG', '*.png')], + defaultextension='png', + ) + if not filename: + return + image.save(filename) + +def showqr_argparse(args): + text = pipeable.input(args.text, split_lines=False) + image = qrcode.make(text).get_image() + + root = tkinter.Tk() + root.title("QR code") + root.bind('', lambda *args, **kwargs: root.quit()) + root.bind('', lambda *args, **kwargs: save_image(root, image)) + + tk_image = PIL.ImageTk.PhotoImage(image) + tkinter.Label(root, image=tk_image).grid(row=0, column=0) + + root.update() + width = root.winfo_reqwidth() + height = root.winfo_reqheight() + x_offset = (root.winfo_screenwidth() - width) / 2 + y_offset = (root.winfo_screenheight() - height) / 2 + + root.geometry('%dx%d+%d+%d' % (width, height, x_offset, y_offset-50)) + root.mainloop() + return 0 + +def main(argv): + parser = argparse.ArgumentParser(description=__doc__) + + parser.add_argument('text') + parser.set_defaults(func=showqr_argparse) + + args = parser.parse_args(argv) + return args.func(args) + +if __name__ == '__main__': + raise SystemExit(main(sys.argv[1:]))