From f30c2eb36eccf6970c1f1da3250117d8499ad937 Mon Sep 17 00:00:00 2001 From: Jan Grewe Date: Mon, 8 Mar 2021 14:59:32 +0100 Subject: [PATCH] [main] use constants for app info --- .gitignore | 3 ++- blipblop/constants.py | 27 +++++++++++++-------------- blipblop/main.py | 6 +++--- blipblop/ui/audioblop.py | 8 ++++---- blipblop/ui/help.py | 6 +++--- 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/.gitignore b/.gitignore index 4ef3e36..e4897ae 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *.pyc -*__pycache__ \ No newline at end of file +*__pycache__ +resources.py diff --git a/blipblop/constants.py b/blipblop/constants.py index 10b6dfd..f3115f6 100644 --- a/blipblop/constants.py +++ b/blipblop/constants.py @@ -2,13 +2,20 @@ import os import glob from PyQt5.QtGui import QIcon from PyQt5.QtMultimedia import QMediaContent -from PyQt5.QtCore import QUrl +from PyQt5.QtCore import QDirIterator, QUrl import resources -organization = "neuroetho.uni-tuebingen.de" -application = "blipblop" -version = 0.1 +SNDS_DICT = {} +it = QDirIterator(":", QDirIterator.Subdirectories); +while it.hasNext(): + name = it.next() + if "sounds/" in name: + SNDS_DICT[name.split("/")[-1]] = "qrc" + name + +organization_name = "de.uni-tuebingen.neuroetho" +application_name = "BlipBlop" +application_version = 0.1 PACKAGE_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir)) ICONS_FOLDER = os.path.join(PACKAGE_ROOT, "icons") @@ -20,20 +27,12 @@ ICONS_PATHS.extend(glob.glob(os.path.join(ICONS_FOLDER, "*.icns"))) ICONS_PATHS = sorted(ICONS_PATHS) ICON_DICT = {} -SNDS_PATHS = glob.glob(os.path.join(SNDS_FOLDER, "*.wav")) -SNDS_PATHS = sorted(SNDS_PATHS) -SNDS_DICT = {} - for icon in ICONS_PATHS: ICON_DICT[icon.split(os.sep)[-1].split(".")[0]] = icon -for snd in SNDS_PATHS: - SNDS_DICT[snd.split(os.sep)[-1].split(".")[0]] = snd - - def get_sound(name): if name in SNDS_DICT.keys(): - return QMediaContent(QUrl.fromLocalFile(os.path.abspath(SNDS_DICT[name]))) + return QMediaContent(QUrl(SNDS_DICT[name])) else: print("Sound %s not found!" % name) return None @@ -43,5 +42,5 @@ def get_icon(name): if name in ICON_DICT.keys(): return QIcon(ICON_DICT[name]) else: - return QIcon("nix_logo.png") + return QIcon("blipblop_logo.png") diff --git a/blipblop/main.py b/blipblop/main.py index 532fa1a..eda2b1a 100644 --- a/blipblop/main.py +++ b/blipblop/main.py @@ -16,9 +16,9 @@ except ImportError: def main(): app = QApplication(sys.argv) - app.setApplicationName("blipblop") - app.setApplicationVersion("0.1") - app.setOrganizationDomain("neuroetho.uni-tuebingen.de") + app.setApplicationName(cnst.application_name) + app.setApplicationVersion(cnst.application_version) + app.setOrganizationDomain(cnst.organization_name) app.setWindowIcon(QIcon(":/icons/app_icon_png")) settings = QSettings() width = int(settings.value("app/width", 1024)) diff --git a/blipblop/ui/audioblop.py b/blipblop/ui/audioblop.py index 7a5536a..e584e87 100644 --- a/blipblop/ui/audioblop.py +++ b/blipblop/ui/audioblop.py @@ -1,5 +1,5 @@ from PyQt5.QtWidgets import QAction, QComboBox, QFormLayout, QGridLayout, QLabel, QPushButton, QSizePolicy, QSlider, QSpinBox, QSplitter, QTextEdit, QVBoxLayout, QWidget -from PyQt5.QtCore import QPoint, QRandomGenerator, QTimer, Qt, pyqtSignal +from PyQt5.QtCore import QPoint, QRandomGenerator, QTimer, Qt, endl, pyqtSignal from PyQt5.QtGui import QColor, QFont, QIcon, QKeySequence, QPainter, QPen, QPixmap from PyQt5.QtMultimedia import QMediaPlayer @@ -98,7 +98,7 @@ class SettingsPanel(QWidget): self._countdown_spinner.setEnabled(enabled) self._min_delay_spinner.setEnabled(enabled) self._max_delay_spinner.setEnabled(enabled) - self._sound_combo.setEnabled(False) + self._sound_combo.setEnabled(enabled) class AudioBlop(QWidget): @@ -135,10 +135,10 @@ class AudioBlop(QWidget): grid.addWidget(settings_btn, 0, 3, Qt.AlignRight) self._status_label = QLabel("Ready to start, press enter ...") - grid.addWidget(self._status_label, 3, 0, Qt.AlignLeft) + grid.addWidget(self._status_label, 4, 0, Qt.AlignLeft) self._countdown_label = CountdownLabel(text="Next trial in:") - grid.addWidget(self._countdown_label, 3, 1, Qt.AlignCenter) + grid.addWidget(self._countdown_label, 4, 1, Qt.AlignCenter) self._countdown_label.countdown_done.connect(self.run_trial) self._draw_area = QLabel() diff --git a/blipblop/ui/help.py b/blipblop/ui/help.py index 00f68d0..2f482fa 100644 --- a/blipblop/ui/help.py +++ b/blipblop/ui/help.py @@ -16,12 +16,12 @@ class HelpDialog(QDialog): self.help._edit.historyChanged.connect(self._on_history_changed) - self.back_btn = QPushButton(QIcon(":/icons/back_btn"), "back") + self.back_btn = QPushButton(QIcon(":/icons/docs_back"), "back") self.back_btn.setEnabled(False) self.back_btn.clicked.connect(self.help._edit.backward) - self.home_btn = QPushButton(QIcon(":/icons/home_btn"),"home") + self.home_btn = QPushButton(QIcon(":/icons/docs_home"),"home") self.home_btn.clicked.connect(self.help._edit.home) - self.fwd_btn = QPushButton(QIcon(":/icons/fwd_btn"),"forward") + self.fwd_btn = QPushButton(QIcon(":/icons/docs_fwd"),"forward") self.fwd_btn.setEnabled(False) self.fwd_btn.clicked.connect(self.help._edit.forward)