From 3041e0822e3915551f22b15d00434a3098e13ea1 Mon Sep 17 00:00:00 2001 From: Jan Grewe Date: Fri, 12 Mar 2021 12:12:05 +0100 Subject: [PATCH] [constants] revert finding sounds, do not use qresources --- blipblop/constants.py | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/blipblop/constants.py b/blipblop/constants.py index c4822bd..46f9a80 100644 --- a/blipblop/constants.py +++ b/blipblop/constants.py @@ -2,17 +2,10 @@ import os import glob from PyQt5.QtGui import QIcon from PyQt5.QtMultimedia import QMediaContent -from PyQt5.QtCore import QDirIterator, QUrl +from PyQt5.QtCore import QUrl -import resources +import resources # needs to be imported somewhere in the project to be picked up by qt -SNDS_DICT = {} -it = QDirIterator(":", QDirIterator.Subdirectories); -while it.hasNext(): - name = it.next() - if "sounds/" in name: - SNDS_DICT[name.split("/")[-1]] = "qrc" + name -print(SNDS_DICT) organization_name = "de.uni-tuebingen.neuroetho" application_name = "BlipBlop" application_version = 0.1 @@ -22,6 +15,23 @@ ICONS_FOLDER = os.path.join(PACKAGE_ROOT, "icons") DOCS_ROOT_FILE = os.path.join(PACKAGE_ROOT, "docs", "index.md") SNDS_FOLDER = os.path.join(PACKAGE_ROOT, "sounds") +# Find and list sounds +SNDS_PATHS = glob.glob(os.path.join(SNDS_FOLDER, "*.wav")) +SNDS_PATHS = sorted(SNDS_PATHS) +SNDS_DICT = {} + +for snd in SNDS_PATHS: + SNDS_DICT[snd.split(os.sep)[-1].split(".")[0]] = snd + +""" This snippet is kept because it shows how to iterate the qt resources.py file +it = QDirIterator(":", QDirIterator.Subdirectories); +while it.hasNext(): + name = it.next() + if "sounds/" in name: + SNDS_DICT[name.split("/")[-1]] = "qrc" + name +""" + +# Find and list icons and images ICONS_PATHS = glob.glob(os.path.join(ICONS_FOLDER, "*.png")) ICONS_PATHS.extend(glob.glob(os.path.join(ICONS_FOLDER, "*.icns"))) ICONS_PATHS = sorted(ICONS_PATHS) @@ -30,9 +40,10 @@ ICON_DICT = {} for icon in ICONS_PATHS: ICON_DICT[icon.split(os.sep)[-1].split(".")[0]] = icon + def get_sound(name): if name in SNDS_DICT.keys(): - url = QUrl(SNDS_DICT[name]) + url = QUrl.fromLocalFile(SNDS_DICT[name]) return QMediaContent(url) else: print("Sound %s not found!" % name)