From: Simon Tatham Date: Fri, 19 Jun 2020 20:33:24 +0000 (+0100) Subject: editor.py: allow pasting a character description back in. X-Git-Tag: bedstead-002.002~8^2 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~bjharris/git?a=commitdiff_plain;h=bc192756b4e404c4e9df616d75497fa91509dea6;p=bedstead.git editor.py: allow pasting a character description back in. Middle-clicking will paste from the X primary selection and try to interpret it as a sequence of octal numbers representing bitmap rows. --- diff --git a/editor.py b/editor.py index 0a02705..aae99ea 100644 --- a/editor.py +++ b/editor.py @@ -147,6 +147,22 @@ def click(event): regenerate() break +def paste(event): + s = tkroot.selection_get() + pat = re.compile("[0-7]+") + bitmap = [] + for i in range(YSIZE): + m = pat.search(s) + if m is None: + print("gronk") + return + bitmap.append(int(m.group(0), 8) & ((1 << XSIZE) - 1)) + s = s[m.end(0):] + for y in range(YSIZE): + for x in range(XSIZE): + setpixel(x, y, 1 & (bitmap[y] >> (XSIZE-1 - x))) + regenerate() + def drag(event): x = (event.x - cont.dragstartx) // pixel y = (event.y - gutter) // pixel @@ -169,6 +185,7 @@ def key(event): cont.canvas.bind("", click) cont.canvas.bind("", drag) +cont.canvas.bind("", paste) tkroot.bind("", key) cont.canvas.pack()