From d97cce3438a3e496794bfa5dae9895fa3011e7d9 Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 30 Apr 2011 16:01:12 -0500 Subject: [PATCH] Add docstrings and ideas for command line options We make minor changes to the docstrings of lib.py We write docstrings for the `binary operation' functions of command line script. The -o --output option was previously called -s --steps --- lib.py | 7 ++++--- script.py | 21 ++++++++++++++++----- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/lib.py b/lib.py index f342992..3371965 100644 --- a/lib.py +++ b/lib.py @@ -16,7 +16,9 @@ class MyFont: class InterpolateFonts: - """Produce a series of fonts using the interpolateFonts method. + """Produce fonts using the interpolateFonts method of FontForge. + + The kern of this class is the interpolate method. FontForge defines an `interpolateFonts' method for its font type. The amount of blending is defined with a `fraction'. From the FontForge @@ -34,8 +36,8 @@ class InterpolateFonts: from_font.interpolateFonts(0, to_font) from_font.interpolateFonts(0.25, to_font) from_font.interpolateFonts(0.5, to_font) + from_font.interpolateFonts(0.75, to_font) from_font.interpolateFonts(1, to_font) - """ def __init__(self, from_font, to_font, button, steps): @@ -52,7 +54,6 @@ class InterpolateFonts: def font_info(self): """Define strings for file and font names based on the input fonts.""" - self.directory = os.path.split(self.from_font)[1] + os.path.split(self.to_font)[1] + self.button.upper() self.fromfont_noextension = os.path.splitext(os.path.split(self.from_font)[1])[0] self.tofont_noextension = os.path.splitext(os.path.split(self.to_font)[1])[0] diff --git a/script.py b/script.py index 5a7a72f..dff48fb 100755 --- a/script.py +++ b/script.py @@ -7,21 +7,32 @@ from stat import * import lib def font_times_font(font0, font1, button, steps): + """Interface to the main method of InterpolateFonts. + + font1 and font2 are font files on disk. + + The `binary operations' that follow are based on this function, ie + font_times_directory, etc. + + """ myfont0_times_myfont1 = lib.InterpolateFonts(font0, font1, button, steps) myfont0_times_myfont1.font_info() myfont0_times_myfont1.interpolate() def font_times_directory(font0, directory, button, steps): + """Interpolates font0 with all the fonts in directory.""" for dirpath, dirnames, filenames in os.walk(directory): for font1 in filenames: font_times_font(font0, os.path.join(dirpath, font1), button, steps) def directory_times_font(directory, font1, button, steps): + """Interpolates all the fonts in directory with font1.""" for dirpath, dirnames, filenames in os.walk(directory): for font0 in filenames: font_times_font(os.path.join(dirpath, font0), font1, button, steps) def directory_times_directory(directory0, directory1, button, steps): + """Interpolates all the fonts in directory0 with all the fonts in directory1.""" for dirpath0, dirnames0, filenames0 in os.walk(directory0): for myfont0 in filenames0: for dirpath1, dirnames1, filenames1 in os.walk(directory1): @@ -31,7 +42,7 @@ def directory_times_directory(directory0, directory1, button, steps): if __name__ == "__main__": gui = OptionParser() - gui.add_option("-s", "--steps", action="store", type="int", dest="steps") + gui.add_option("-o", "--output", action="store", type="int", dest="output_files") gui.add_option("-x", action="store_true", dest="x") gui.add_option("-y", action="store_true", dest="y") gui.add_option("-z", action="store_true", dest="z") @@ -55,13 +66,13 @@ if __name__ == "__main__": if S_ISDIR(mode0) and S_ISDIR(mode1): # Both locations are directories - directory_times_directory(paths[0], paths[1], button, options.steps) + directory_times_directory(paths[0], paths[1], button, options.output_files) elif S_ISREG(mode0) and S_ISREG(mode1): # Both locations are files - font_times_font(paths[0], paths[1], button, options.steps) + font_times_font(paths[0], paths[1], button, options.output_files) elif S_ISREG(mode0): # paths[0] is a file - font_times_directory(paths[0], paths[1], button, options.steps) + font_times_directory(paths[0], paths[1], button, options.output_files) elif S_ISREG(mode1): # paths[1] is a file - directory_times_font(paths[0], paths[1], button, options.steps) + directory_times_font(paths[0], paths[1], button, options.output_files) -- 2.11.4.GIT