chiark / gitweb /
editor.py: allow pasting a character description back in.
authorSimon Tatham <anakin@pobox.com>
Fri, 19 Jun 2020 20:33:24 +0000 (21:33 +0100)
committerSimon Tatham <anakin@pobox.com>
Fri, 19 Jun 2020 20:33:24 +0000 (21:33 +0100)
Middle-clicking will paste from the X primary selection and try to
interpret it as a sequence of octal numbers representing bitmap rows.

editor.py

index 0a027056a84e6dc24449c1e64ab89fb9ae05bd9e..aae99ea85d591af4fb493a01ba6ae82b1a52f449 100644 (file)
--- 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("<Button-1>", click)
 cont.canvas.bind("<B1-Motion>", drag)
+cont.canvas.bind("<Button-2>", paste)
 tkroot.bind("<Key>", key)
 cont.canvas.pack()