chiark / gitweb /
editor: better ways to find the bedstead executable.
authorSimon Tatham <anakin@pobox.com>
Sun, 13 Oct 2024 09:50:37 +0000 (10:50 +0100)
committerBen Harris <bjh21@bjh21.me.uk>
Sun, 13 Oct 2024 14:04:53 +0000 (15:04 +0100)
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

diff --git a/editor b/editor
index 03c502e608138714244fbb06cd6071a14affafae..8ccb1cdc935397f5cc6cf12b29f9cdf1cb1ab334 100755 (executable)
--- 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__':