diff --git a/editor b/editor index 03c502e..8ccb1cd 100755 --- a/editor +++ b/editor @@ -7,6 +7,21 @@ # Simon Tatham makes this program available under the CC0 Public # Domain Dedication. +'''Interactive glyph editor for Bedstead. + +Uses Python/Tk to display a window with a pixel grid on the left side, +where the user can click or drag to toggle pixels on and off, and on +the right, shows the output of the Bedstead smoothing algorithm +applied to that grid of pixels. + +This is done by running the `bedstead` executable itself to compute +the smoothed outline, so a copy of that executable is required to use +this editor. + +''' + +import argparse +import os import re import sys import string @@ -20,7 +35,9 @@ XSIZE, YSIZE = 5, 9 LEFT, TOP = 100, 700 # for transforming coordinates returned from bedstead class EditorGui: - def __init__(self): + def __init__(self, bedstead): + self.bedstead = bedstead + self.tkroot = Tk() self.canvas = Canvas(self.tkroot, @@ -75,7 +92,7 @@ class EditorGui: self.polygons = [] data = subprocess.check_output( - ["./bedstead"] + list(map(str, self.bitmap))) + [self.bedstead] + list(map(str, self.bitmap))) paths = [] path = None for line in data.splitlines(): @@ -191,7 +208,20 @@ class EditorGui: mainloop() def main(): - editor = EditorGui() + # By default, assume that the user ran 'make' in the bedstead + # source directory, so that the 'bedstead' executable is alongside + # the binary. + default_executable_path = os.path.join( + os.path.dirname(os.path.abspath(__file__)), "bedstead") + + parser = argparse.ArgumentParser( + description=__doc__, + formatter_class=argparse.RawDescriptionHelpFormatter) + parser.add_argument("--bedstead", default=default_executable_path, + help="Location of the 'bedstead' executable.") + args = parser.parse_args() + + editor = EditorGui(args.bedstead) editor.run() if __name__ == '__main__':