From 7513d1c13b337c1679f44030da553a79c55b91af Mon Sep 17 00:00:00 2001 From: tassaron Date: Tue, 3 May 2022 08:33:12 -0400 Subject: Suggest pipx for installation. Fix `avp` command. Allegedly the gui_scripts is only different from console_scripts on Windows, and it has the effect of hiding the console window. This seemed to make the `avp` entrypoint crash, possibly because the app already contains its own logic for hiding the console window(?). I've tested this on Windows 11 and it seems to work better using console_scripts. --- README.md | 23 ++++++++++++++--------- setup.py | 4 ++-- src/__main__.py | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++--- src/main.py | 53 ----------------------------------------------------- 4 files changed, 66 insertions(+), 67 deletions(-) delete mode 100644 src/main.py diff --git a/README.md b/README.md index 825e899..7121eae 100644 --- a/README.md +++ b/README.md @@ -31,20 +31,25 @@ The program works on Linux, macOS, and Windows. If you encounter problems runnin # Installation +* On any platform, you may wish to install the app within an isolated Python environment so it doesn't affect other Python packages on your system. An easy way to do this is by using [Pipx](https://pypi.org/project/pipx/), which works similarly to Pip but automatically handles isolation. +* If you have problems running the `avp` command, try using `python -m avp` instead. (Note: python is called python3 on some systems.) + + ## Manual installation on Ubuntu 22.04 * Install dependencies: `sudo apt install ffmpeg python3-pip python3-pyqt5` -* Download this repo and run `pip install .` in this directory -* Run the program with `python3 -m avp` +* Download this repo and run `pip install .` in this directory (or use `pipx` for isolation) +* Run the program with `avp` or `python3 -m avp` ## Manual installation on Windows * Install Python from the Windows Store * Add Python to your system PATH (it should ask during the installation process) -* Download this repo -* Open command prompt, `cd` into the repo directory, and run: `pip install .` -* Download and install [FFmpeg](https://www.ffmpeg.org/download.html). You can use the static builds. -* Add FFmpeg to the system PATH as well, or copy ffmpeg.exe into the directory with the rest of the app -* Now run `python -m avp` from a command prompt window to start the app +* Download this repo (extract from zip if needed) +* Download and install [FFmpeg](https://www.ffmpeg.org/download.html). Use the GPL-licensed static builds. +* Add FFmpeg to the system PATH as well (program will then work anywhere) + * Alternatively, copy ffmpeg.exe into the folder that you want to run the program within +* Open command prompt, `cd` into the repo directory, and run: `pip install .` (or use `pipx` for isolation) +* Now run `avp` or `python -m avp` from a command prompt window to start the app ## Manual installation on macOS @@ -59,8 +64,8 @@ brew install sip --with-python3 brew install pyqt --with-python3 pip3 install --upgrade pip ``` -* Download audio-visualizer-python from this repository and install it using Pip: `pip3 install .` -* Start the app with `python3 -m avp` +* Download this repository and install it using Pip: `pip3 install .` (or use `pipx` for isolation) +* Start the app with `avp` or `python3 -m avp` # Faster Export Times diff --git a/setup.py b/setup.py index 3709e7b..0ed943c 100644 --- a/setup.py +++ b/setup.py @@ -55,8 +55,8 @@ setup( 'pytest' ], entry_points={ - 'gui_scripts': [ - f'avp = {PACKAGE_NAME}.main:main' + 'console_scripts': [ + f'avp = {PACKAGE_NAME}.__main__:main' ], } ) diff --git a/src/__main__.py b/src/__main__.py index 3206bc8..bd35e32 100644 --- a/src/__main__.py +++ b/src/__main__.py @@ -1,5 +1,52 @@ -# Allows for launching with python3 -m avp +from PyQt5.QtWidgets import QApplication +import sys +import logging +import re +import string -from .main import main -main() +log = logging.getLogger('AVP.Main') + + +def main() -> int: + """Returns an exit code (0 for success)""" + proj = None + mode = 'GUI' + + # Determine whether we're in GUI or commandline mode + if len(sys.argv) > 2: + mode = 'commandline' + elif len(sys.argv) == 2: + if sys.argv[1].startswith('-'): + mode = 'commandline' + else: + # remove unsafe punctuation characters such as \/?*&^%$# + sys.argv[1] = re.sub(f'[{re.escape(string.punctuation)}]', '', sys.argv[1]) + # opening a project file with gui + proj = sys.argv[1] + + # Create Qt Application + app = QApplication(sys.argv) + app.setApplicationName("audio-visualizer") + + # Launch program + if mode == 'commandline': + from .command import Command + + main = Command() + mode = main.parseArgs() + log.debug("Finished creating command object") + + # Both branches here may occur in one execution: + # Commandline parsing could change mode back to GUI + if mode == 'GUI': + from .gui.mainwindow import MainWindow + + mainWindow = MainWindow(proj) + log.debug("Finished creating MainWindow") + mainWindow.raise_() + + return app.exec_() + +if __name__ == '__main__': + sys.exit(main()) \ No newline at end of file diff --git a/src/main.py b/src/main.py deleted file mode 100644 index 709e5e7..0000000 --- a/src/main.py +++ /dev/null @@ -1,53 +0,0 @@ -from PyQt5 import uic, QtWidgets -import sys -import os -import logging -import re -import string - -from .__init__ import wd - - -log = logging.getLogger('AVP.Main') - - -def main(): - # Determine primary mode - proj = None - mode = 'GUI' - if len(sys.argv) > 2: - mode = 'commandline' - elif len(sys.argv) == 2: - if sys.argv[1].startswith('-'): - mode = 'commandline' - else: - # remove unsafe punctuation characters such as \/?*&^%$# - sys.argv[1] = re.sub(f'[{re.escape(string.punctuation)}]', '', sys.argv[1]) - # opening a project file with gui - proj = sys.argv[1] - - # Create Qt Application - app = QtWidgets.QApplication(sys.argv) - app.setApplicationName("audio-visualizer") - # Launch program - if mode == 'commandline': - from .command import Command - - main = Command() - mode = main.parseArgs() - log.debug("Finished creating command object") - - # Both branches here may occur in one execution: - # Commandline parsing could change mode back to GUI - if mode == 'GUI': - from .gui.mainwindow import MainWindow - - mainWindow = MainWindow(proj) - log.debug("Finished creating MainWindow") - mainWindow.raise_() - - sys.exit(app.exec_()) - - -if __name__ == "__main__": - main() -- cgit v1.2.3