aboutsummaryrefslogtreecommitdiff
path: root/src/command.py
diff options
context:
space:
mode:
authortassaron2026-01-11 14:29:58 -0500
committertassaron2026-01-11 14:29:58 -0500
commit669756b391d26661cf2e2a97a304e73343ef6655 (patch)
tree9cf2d4858c209bdab9f44d5c7f95c2a30b37f7a6 /src/command.py
parent9d45f7f1a986aaa5d3c084c7ae747442b94a61b1 (diff)
update to Qt 6 and Pillow 12
and yeah, I accidentally ran black on the codebase. I don't want to spend more free time fixing that. All of these changes are simple renames or removals, nothing too major.
Diffstat (limited to 'src/command.py')
-rw-r--r--src/command.py152
1 files changed, 77 insertions, 75 deletions
diff --git a/src/command.py b/src/command.py
index 53801fa..783ac26 100644
--- a/src/command.py
+++ b/src/command.py
@@ -1,9 +1,10 @@
-'''
- When using commandline mode, this module's object handles interpreting
- the arguments and giving them to Core, which tracks the main program state.
- Then it immediately exports a video.
-'''
-from PyQt5 import QtCore
+"""
+When using commandline mode, this module's object handles interpreting
+the arguments and giving them to Core, which tracks the main program state.
+Then it immediately exports a video.
+"""
+
+from PyQt6 import QtCore
import argparse
import os
import sys
@@ -16,12 +17,12 @@ import logging
from . import core
-log = logging.getLogger('AVP.Commandline')
+log = logging.getLogger("AVP.Commandline")
class Command(QtCore.QObject):
"""
- This replaces the GUI MainWindow when in commandline mode.
+ This replaces the GUI MainWindow when in commandline mode.
"""
createVideo = QtCore.pyqtSignal()
@@ -29,7 +30,7 @@ class Command(QtCore.QObject):
def __init__(self):
super().__init__()
self.core = core.Core()
- core.Core.mode = 'commandline'
+ core.Core.mode = "commandline"
self.dataDir = self.core.dataDir
self.canceled = False
self.settings = core.Core.settings
@@ -39,52 +40,58 @@ class Command(QtCore.QObject):
def parseArgs(self):
parser = argparse.ArgumentParser(
- prog='avp' if os.path.basename(sys.argv[0]) == "__main__.py" else None,
- description='Create a visualization for an audio file',
- epilog='EXAMPLE COMMAND: avp myvideotemplate '
- '-i ~/Music/song.mp3 -o ~/video.mp4 '
- '-c 0 image path=~/Pictures/thisWeeksPicture.jpg '
- '-c 1 video "preset=My Logo" -c 2 vis layout=classic'
+ prog="avp" if os.path.basename(sys.argv[0]) == "__main__.py" else None,
+ description="Create a visualization for an audio file",
+ epilog="EXAMPLE COMMAND: avp myvideotemplate "
+ "-i ~/Music/song.mp3 -o ~/video.mp4 "
+ "-c 0 image path=~/Pictures/thisWeeksPicture.jpg "
+ '-c 1 video "preset=My Logo" -c 2 vis layout=classic',
)
-
# input/output automatic-export commands
+ parser.add_argument("-i", "--input", metavar="SOUND", help="input audio file")
parser.add_argument(
- '-i', '--input', metavar='SOUND',
- help='input audio file'
+ "-o", "--output", metavar="OUTPUT", help="output video file"
)
parser.add_argument(
- '-o', '--output', metavar='OUTPUT',
- help='output video file'
- )
- parser.add_argument(
- '--export-project', action='store_true',
- help='use input and output files from project file if -i or -o is missing'
+ "--export-project",
+ action="store_true",
+ help="use input and output files from project file if -i or -o is missing",
)
# mutually exclusive debug options
debugCommands = parser.add_mutually_exclusive_group()
debugCommands.add_argument(
- '--test', action='store_true',
- help='run tests and create a report full of debugging info'
+ "--test",
+ action="store_true",
+ help="run tests and create a report full of debugging info",
)
debugCommands.add_argument(
- '--debug', action='store_true',
- help='create bigger logfiles while program is running'
+ "--debug",
+ action="store_true",
+ help="create bigger logfiles while program is running",
)
# project/GUI options
parser.add_argument(
- 'projpath', metavar='path-to-project',
- help='open a project file (.avp)', nargs='?')
+ "projpath",
+ metavar="path-to-project",
+ help="open a project file (.avp)",
+ nargs="?",
+ )
parser.add_argument(
- '-c', '--comp', metavar=('LAYER', 'ARG'),
- help='first arg must be component NAME to insert at LAYER.'
+ "-c",
+ "--comp",
+ metavar=("LAYER", "ARG"),
+ help="first arg must be component NAME to insert at LAYER."
'"help" for information about possible args for a component.',
- nargs='*', action='append')
+ nargs="*",
+ action="append",
+ )
parser.add_argument(
- '--no-preview', action='store_true',
- help='disable live preview during export'
+ "--no-preview",
+ action="store_true",
+ help="disable live preview during export",
)
args = parser.parse_args()
@@ -101,15 +108,11 @@ class Command(QtCore.QObject):
if args.projpath:
projPath = args.projpath
if not os.path.dirname(projPath):
- projPath = os.path.join(
- self.settings.value("projectDir"),
- projPath
- )
- if not projPath.endswith('.avp'):
- projPath += '.avp'
+ projPath = os.path.join(self.settings.value("projectDir"), projPath)
+ if not projPath.endswith(".avp"):
+ projPath += ".avp"
self.core.openProject(self, projPath)
- self.core.selectedComponents = list(
- reversed(self.core.selectedComponents))
+ self.core.selectedComponents = list(reversed(self.core.selectedComponents))
self.core.componentListChanged()
if args.comp:
@@ -120,14 +123,17 @@ class Command(QtCore.QObject):
try:
pos = int(pos)
except ValueError:
- print(pos, 'is not a layer number.')
+ print(pos, "is not a layer number.")
quit(1)
realName = self.parseCompName(name)
if not realName:
- print(name, 'is not a valid component name.')
+ print(name, "is not a valid component name.")
quit(1)
modI = self.core.moduleIndexFor(realName)
i = self.core.insertComponent(pos, modI, self)
+ if i is None:
+ print(name, "could not be initialized.")
+ quit(1)
for arg in compargs:
self.core.selectedComponents[i].command(arg)
@@ -135,15 +141,12 @@ class Command(QtCore.QObject):
errcode, data = self.core.parseAvFile(projPath)
input_ = None
output = None
- for key, value in data['WindowFields']:
- if 'outputFile' in key:
+ for key, value in data["WindowFields"]:
+ if "outputFile" in key:
output = value
if output and not os.path.dirname(value):
- output = os.path.join(
- os.path.expanduser('~'),
- output
- )
- if 'audioFile' in key:
+ output = os.path.join(os.path.expanduser("~"), output)
+ if "audioFile" in key:
input_ = value
# use input/output from project file, overwritten by -i and -o
@@ -153,7 +156,7 @@ class Command(QtCore.QObject):
self.createAudioVisualization(
input_ if not args.input else args.input,
- output if not args.output else args.output
+ output if not args.output else args.output,
)
return "commandline"
@@ -165,11 +168,11 @@ class Command(QtCore.QObject):
core.Core.previewEnabled = False
elif (
- args.projpath is None and
- 'help' not in sys.argv and
- '--debug' not in sys.argv and
- '--test' not in sys.argv
- ):
+ args.projpath is None
+ and "help" not in sys.argv
+ and "--debug" not in sys.argv
+ and "--test" not in sys.argv
+ ):
parser.print_help()
quit(1)
@@ -180,12 +183,9 @@ class Command(QtCore.QObject):
print("No components selected. Adding a default visualizer.")
time.sleep(1)
self.core.insertComponent(0, 0, self)
- self.core.selectedComponents = list(
- reversed(self.core.selectedComponents))
+ self.core.selectedComponents = list(reversed(self.core.selectedComponents))
self.core.componentListChanged()
- self.worker = self.core.newVideoWorker(
- self, input, output
- )
+ self.worker = self.core.newVideoWorker(self, input, output)
# quit(0) after video is created
self.worker.videoCreated.connect(self.videoCreated)
self.lastProgressUpdate = time.time()
@@ -199,16 +199,18 @@ class Command(QtCore.QObject):
@QtCore.pyqtSlot(str)
def progressBarSetText(self, value):
- if 'Export ' in value:
+ if "Export " in value:
# Don't duplicate completion/failure messages
return
- if not value.startswith('Exporting') \
- and time.time() - self.lastProgressUpdate >= 0.05:
+ if (
+ not value.startswith("Exporting")
+ and time.time() - self.lastProgressUpdate >= 0.05
+ ):
# Show most messages very often
print(value)
elif time.time() - self.lastProgressUpdate >= 2.0:
# Give user time to read ffmpeg's output during the export
- print('##### %s' % value)
+ print("##### %s" % value)
else:
return
self.lastProgressUpdate = time.time()
@@ -221,9 +223,9 @@ class Command(QtCore.QObject):
quit(code)
def showMessage(self, **kwargs):
- print(kwargs['msg'])
- if 'detail' in kwargs:
- print(kwargs['detail'])
+ print(kwargs["msg"])
+ if "detail" in kwargs:
+ print(kwargs["detail"])
@QtCore.pyqtSlot(str, str)
def videoThreadError(self, msg, detail):
@@ -235,7 +237,7 @@ class Command(QtCore.QObject):
pass
def parseCompName(self, name):
- '''Deduces a proper component name out of a commandline arg'''
+ """Deduces a proper component name out of a commandline arg"""
if name.title() in self.core.compNames:
return name.title()
@@ -244,9 +246,7 @@ class Command(QtCore.QObject):
return compName
compFileNames = [
- os.path.splitext(
- os.path.basename(mod.__file__)
- )[0]
+ os.path.splitext(os.path.basename(mod.__file__))[0]
for mod in self.core.modules
]
for i, compFileName in enumerate(compFileNames):
@@ -258,15 +258,17 @@ class Command(QtCore.QObject):
def runTests(self):
from . import tests
+
test_report = os.path.join(core.Core.logDir, "test_report.log")
tests.run(test_report)
# Choose a numbered location to put the output file
logNumber = 0
+
def getFilename():
"""Get a numbered filename for the final test report"""
nonlocal logNumber
- name = os.path.join(os.path.expanduser('~'), "avp_test_report")
+ name = os.path.join(os.path.expanduser("~"), "avp_test_report")
while True:
possibleName = f"{name}{logNumber:0>2}.txt"
if os.path.exists(possibleName) and logNumber < 100: