From 82011de966f95afa88ec9e11e0ce86cbd04d5fc0 Mon Sep 17 00:00:00 2001 From: tassaron Date: Sun, 18 Jun 2017 21:49:00 -0400 Subject: [PATCH] able to create components from commandline TODO: make components respond to argument --- command.py | 47 ++++++++++++++++++++++++++++++++++++++++++++--- core.py | 4 ++-- 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/command.py b/command.py index 1b07afc..d56c64b 100644 --- a/command.py +++ b/command.py @@ -18,16 +18,27 @@ class Command(QtCore.QObject): self.dataDir = self.core.dataDir self.parser = argparse.ArgumentParser( - description='Create a visualization for an audio file') + description='Create a visualization for an audio file', + epilog='EXAMPLE COMMAND: main.py myvideotemplate.avp ' + '-i ~/Music/song.mp3 -o ~/video.mp4 ' + '-c 0 image ~/Pictures/thisWeeksPicture.jpg ' + '-c 1 vis classic') self.parser.add_argument( - '-i', '--input', help='input audio file', required=True) + '-i', '--input', metavar='SOUND', + help='input audio file', required=True) self.parser.add_argument( - '-o', '--output', help='output video file', required=True) + '-o', '--output', metavar='OUTPUT', + help='output video file', required=True) # optional arguments self.parser.add_argument( 'projpath', metavar='path-to-project', help='open a project file (.avp)', nargs='?') + self.parser.add_argument( + '-c', '--comp', metavar=('LAYER', 'NAME', 'ARG'), + help='create/edit component NAME at LAYER.' + '"help" for information about possible args', nargs=3, + action='append') ''' self.parser.add_argument( @@ -66,6 +77,16 @@ class Command(QtCore.QObject): if self.args.projpath: self.core.openProject(self, self.args.projpath) + if self.args.comp: + for comp in self.args.comp: + pos, name, arg = comp + realName = self.parseCompName(name) + if not realName: + print(name, 'is not a valid component name.') + quit() + modI = self.core.moduleIndexFor(realName) + self.core.insertComponent(int(pos), modI, self) + self.createAudioVisualisation() def createAudioVisualisation(self): @@ -95,3 +116,23 @@ class Command(QtCore.QObject): def cleanUp(self, *args): pass + + def parseCompName(self, name): + '''Deduces a proper component name out of a commandline arg''' + compFileNames = [ \ + os.path.splitext(os.path.basename( + mod.__file__))[0] \ + for mod in self.core.modules \ + ] + + if name.title() in self.core.compNames: + return name.title() + for compName in self.core.compNames: + if name.capitalize() in compName: + return compName + for i, compFileName in enumerate(compFileNames): + if name.lower() in compFileName: + return self.core.compNames[i] + return + + return None diff --git a/core.py b/core.py index 5e4071a..2dde464 100644 --- a/core.py +++ b/core.py @@ -72,6 +72,7 @@ class Core(): for name in findComponents() ] self.moduleIndexes = [i for i in range(len(self.modules))] + self.compNames = [mod.Component.__doc__ for mod in self.modules] def componentListChanged(self): for i, component in enumerate(self.selectedComponents): @@ -119,8 +120,7 @@ class Core(): self.selectedComponents[i].update() def moduleIndexFor(self, compName): - compNames = [mod.Component.__doc__ for mod in self.modules] - index = compNames.index(compName) + index = self.compNames.index(compName) return self.moduleIndexes[index] def clearPreset(self, compIndex):