From 4ce96879d8c384bf0fc44705f778c39947d6564f Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sun, 13 Oct 2024 10:50:37 +0100 Subject: [PATCH] editor: better ways to find the bedstead executable. Previously the editor just expected to find it in your cwd. Now by default it looks in the same directory as its own script, which means you can run it from some other directory. Also, I've provided a command-line option to override the default, in case you keep the executable somewhere else again. --- editor | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) 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__': -- 2.30.2