From 3c903794e3588560f2b9d342214009d55a675d5a Mon Sep 17 00:00:00 2001 From: tassaron Date: Thu, 22 Jun 2017 22:23:04 -0400 Subject: [PATCH] more commandline component options commandline options that existed before the redesign are now back --- command.py | 15 ++++++++++----- components/__base__.py | 2 +- components/color.py | 11 +++++++++++ components/image.py | 14 +++++++------- components/original.py | 23 +++++++++++++++-------- components/text.py | 28 ++++++++++++++++++++++------ components/video.py | 16 ++++++++-------- 7 files changed, 74 insertions(+), 35 deletions(-) diff --git a/command.py b/command.py index 9012ca4..1a1e810 100644 --- a/command.py +++ b/command.py @@ -2,6 +2,7 @@ from PyQt4 import QtCore from PyQt4.QtCore import QSettings import argparse import os +import sys import core import video_thread @@ -22,14 +23,14 @@ class Command(QtCore.QObject): 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 video "preset=My Logo" -c 2 vis classic') + '-c 0 image path=~/Pictures/thisWeeksPicture.jpg ' + '-c 1 video "preset=My Logo" -c 2 vis layout=classic') self.parser.add_argument( '-i', '--input', metavar='SOUND', - help='input audio file', required=True) + help='input audio file') self.parser.add_argument( '-o', '--output', metavar='OUTPUT', - help='output video file', required=True) + help='output video file') # optional arguments self.parser.add_argument( @@ -71,7 +72,11 @@ class Command(QtCore.QObject): for arg in args: self.core.selectedComponents[i].command(arg) - self.createAudioVisualisation() + if self.args.input and self.args.output: + self.createAudioVisualisation() + elif 'help' not in sys.argv: + self.parser.print_help() + quit(1) def createAudioVisualisation(self): self.videoThread = QtCore.QThread(self) diff --git a/components/__base__.py b/components/__base__.py index 5c8865d..bef7f0e 100644 --- a/components/__base__.py +++ b/components/__base__.py @@ -73,7 +73,7 @@ class Component(QtCore.QObject): print( self.__doc__, 'Usage:\n' 'Open a preset for this component:\n' - ' "preset=Preset Name"\n') + ' "preset=Preset Name"') self.commandHelp() quit(0) diff --git a/components/color.py b/components/color.py index cb75839..5ffcdea 100644 --- a/components/color.py +++ b/components/color.py @@ -233,3 +233,14 @@ class Component(__base__.Component): else: self.page.lineEdit_color2.setText(RGBstring) self.page.pushButton_color2.setStyleSheet(btnStyle) + + def commandHelp(self): + print('Specify a color:\n color=255,255,255') + + def command(self, arg): + if not arg.startswith('preset=') and '=' in arg: + key, arg = arg.split('=', 1) + if key == 'color': + self.page.lineEdit_color1.setText(arg) + return + super().command(arg) diff --git a/components/image.py b/components/image.py index d0e1894..f8ae64e 100644 --- a/components/image.py +++ b/components/image.py @@ -94,18 +94,18 @@ class Component(__base__.Component): self.update() def command(self, arg): - if not arg.startswith('preset='): - if os.path.exists(arg): + if not arg.startswith('preset=') and '=' in arg: + key, arg = arg.split('=', 1) + if key == 'path' and os.path.exists(arg): try: Image.open(arg) - self.imagePath = arg - self.stretched = True - return True + self.page.lineEdit_image.setText(arg) + self.page.checkBox_stretch.setChecked(True) + return except OSError as e: print("Not a supported image format") quit(1) super().command(arg) def commandHelp(self): - print('Give a complete filepath to an image to load that ' - 'image with default settings.') + print('Load an image:\n path=/filepath/to/image.png') diff --git a/components/original.py b/components/original.py index 328d64f..6222157 100644 --- a/components/original.py +++ b/components/original.py @@ -184,14 +184,21 @@ class Component(__base__.Component): return im def command(self, arg): - if not arg.startswith('preset='): - if arg == 'classic': - self.layout = 0; return - elif arg == 'split': - self.layout = 1; return - elif arg == 'bottom': - self.layout = 2; return + if not arg.startswith('preset=') and '=' in arg: + key, arg = arg.split('=', 1) + if key == 'color': + self.page.lineEdit_visColor.setText(arg) + return + elif key == 'layout': + if arg == 'classic': + self.page.comboBox_visLayout.setCurrentIndex(0) + elif arg == 'split': + self.page.comboBox_visLayout.setCurrentIndex(1) + elif arg == 'bottom': + self.page.comboBox_visLayout.setCurrentIndex(2) + return super().command(arg) def commandHelp(self): - print('Give a layout name: classic, split, or bottom') + print('Give a layout name:\n layout=[classic/split/bottom]') + print('Specify a color:\n color=255,255,255') diff --git a/components/text.py b/components/text.py index 536a9ba..2375dcd 100644 --- a/components/text.py +++ b/components/text.py @@ -149,12 +149,28 @@ class Component(__base__.Component): self.page.lineEdit_textColor.setText(RGBstring) self.page.pushButton_textColor.setStyleSheet(btnStyle) - def commandHelp(self, arg): - print('Enter a string to use as centred white text. ' - 'Use quotes around the string to escape spaces.') + def commandHelp(self): + print('Enter a string to use as centred white text:') + print(' "title=User Error"') + print('Specify a text color:\n color=255,255,255') + print('Set custom x, y position:\n x=500 y=500') def command(self, arg): - if not arg.startswith('preset='): - self.title = arg - return True + if not arg.startswith('preset=') and '=' in arg: + key, arg = arg.split('=', 1) + if key == 'color': + self.page.lineEdit_textColor.setText(arg) + return + elif key == 'size': + self.page.spinBox_fontSize.setValue(int(arg)) + return + elif key == 'x': + self.page.spinBox_xTextAlign.setValue(int(arg)) + return + elif key == 'y': + self.page.spinBox_yTextAlign.setValue(int(arg)) + return + elif key == 'title': + self.page.lineEdit_title.setText(arg) + return super().command(arg) diff --git a/components/video.py b/components/video.py index 66c98ce..1d250bd 100644 --- a/components/video.py +++ b/components/video.py @@ -222,21 +222,21 @@ class Component(__base__.Component): self.chunkSize = 4*width*height def command(self, arg): - if not arg.startswith('preset='): - if os.path.exists(arg): + if not arg.startswith('preset=') and '=' in arg: + key, arg = arg.split('=', 1) + if key == 'path' and os.path.exists(arg): if os.path.splitext(arg)[1] in self.core.videoFormats: - self.videoPath = arg - self.scale = 100 - self.loopVideo = True - return True + self.page.lineEdit_video.setText(arg) + self.page.spinBox_scale.setValue(100) + self.page.checkBox_loop.setChecked(True) + return else: print("Not a supported video format") quit(1) super().command(arg) def commandHelp(self): - print('Give a complete filepath to a video to load that ' - 'video with default settings.') + print('Load a video:\n path=/filepath/to/video.mp4') def scale(scale, width, height, returntype=None): width = (float(width) / 100.0) * float(scale)