Python 3 compatibility for the editor.

It still works in Python 2.7 as well.
This commit is contained in:
Ben Harris 2017-11-26 10:21:52 +00:00
parent c33fc255ec
commit 2536b614a2

View File

@ -1,9 +1,15 @@
#!/usr/bin/env python
from __future__ import division, print_function, unicode_literals
import sys
import string
from Tkinter import *
try:
from tkinter import *
except ImportError:
# Fall back to Python 2 name for module
from Tkinter import *
import subprocess
@ -66,15 +72,15 @@ def regenerate():
cont.canvas.delete(pg)
cont.polygons = []
data = subprocess.check_output(["./bedstead"] + map(str, cont.bitmap))
data = subprocess.check_output(["./bedstead"] + list(map(str, cont.bitmap)))
paths = []
path = None
for line in data.splitlines():
words = line.split()
if len(words) >= 3 and words[2] in ["m","l"]:
if len(words) >= 3 and words[2] in [b"m",b"l"]:
x = int((float(words[0])-LEFT)*pixel*0.01 + 2*gutter + XSIZE*pixel)
y = int((TOP - float(words[1]))*pixel*0.01 + gutter)
if words[2] == "m":
if words[2] == b"m":
path = []
paths.append(path)
path.append([x,y])
@ -132,8 +138,8 @@ def regenerate():
def click(event):
for dragstartx in gutter, 2*gutter + XSIZE*pixel:
x = (event.x - dragstartx) / pixel
y = (event.y - gutter) / pixel
x = (event.x - dragstartx) // pixel
y = (event.y - gutter) // pixel
if x >= 0 and x < XSIZE and y >= 0 and y < YSIZE:
cont.dragstartx = dragstartx
cont.dragstate = not getpixel(x,y)
@ -142,8 +148,8 @@ def click(event):
break
def drag(event):
x = (event.x - cont.dragstartx) / pixel
y = (event.y - gutter) / pixel
x = (event.x - cont.dragstartx) // pixel
y = (event.y - gutter) // pixel
if x >= 0 and x < XSIZE and y >= 0 and y < YSIZE:
setpixel(x, y, cont.dragstate)
regenerate()
@ -152,7 +158,7 @@ def drag(event):
def key(event):
if event.char in (' '):
bm = ",".join(map(lambda n: "%03o" % n, cont.bitmap))
print " {{%s}, 0x }," % bm
print(" {{%s}, 0x }," % bm)
elif event.char in ('c','C'):
for y in range(YSIZE):
for x in range(XSIZE):