diff options
| author | tassaron | 2022-05-03 08:33:12 -0400 |
|---|---|---|
| committer | tassaron | 2022-05-03 08:33:12 -0400 |
| commit | 7513d1c13b337c1679f44030da553a79c55b91af (patch) | |
| tree | 62820603510072266debf7d44a3e76c2e90182ec /src | |
| parent | 62ca90f0c9a47d4969feadfb22005d86783bd235 (diff) | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/__main__.py | 53 | ||||
| -rw-r--r-- | src/main.py | 53 |
2 files changed, 50 insertions, 56 deletions
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() |
