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.
This commit is contained in:
Simon Tatham 2020-06-19 21:33:24 +01:00
parent 6c0e11d6f5
commit bc192756b4

View File

@ -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()