Preferences, singletons

Create a Preference dialog for fonts and audio output devices

Turn Preferences and SoundOff into singletons.  No matter how many times
you request a new one, the same instance is returned.

Stop using singals on the parent() to access other instances, such as
sound and Preferences.
This commit is contained in:
Christopher T. Johnson
2023-12-22 10:54:27 -05:00
parent c0482b519c
commit 0adf1d6e44
12 changed files with 325 additions and 31 deletions

View File

@@ -18,7 +18,6 @@ from PyQt6.QtCore import (
from PyQt6.QtGui import (
QBrush,
QColor,
QFont,
QKeyEvent,
QMouseEvent,
QPainter,
@@ -35,21 +34,32 @@ from PyQt6.QtWidgets import QDialog, QPushButton
from main import query_error
from ui.EditDialog import Ui_Dialog
from lib.preferences import Preferences
from lib.sounds import SoundOff
class EditDialog(QDialog, Ui_Dialog):
playSound = pyqtSignal(str)
block: int
paragraphs = True
sessionSignal = pyqtSignal()
displayedWord = pyqtSignal(int)
newParagraph = pyqtSignal(int, int)
def __init__(self, parent, session, person_id: int) -> None:
self.session = session
super(EditDialog, self).__init__(parent)
print(self.parent())
self.person_id = person_id
self.preferences = Preferences().get()
self.sound = SoundOff()
styleSheet = QResource(":/display.css").data().decode("utf-8")
print(styleSheet)
styleSheet = styleSheet.replace(
'{readerFont}',self.preferences['readerFont']
)
styleSheet = styleSheet.replace(
'{phoneticFont}',self.preferences['phoneticFont']
)
print(styleSheet)
self.setupUi(self)
#
# Override UI
@@ -75,8 +85,6 @@ class EditDialog(QDialog, Ui_Dialog):
self.scrollBtn.clicked.connect(self.scrollAction)
self.nextBtn.clicked.connect(self.nextAction)
self.prevBtn.clicked.connect(self.prevAction)
# self.sessionSignal.connect(self.session.timerAction)
# self.sessionBtn.clicked.connect(self.sessionAction)
self.sessionBtn.clicked.connect(self.session.timerAction)
self.paraEdit.verticalScrollBar().valueChanged.connect(self.scrollSlot)
self.defEdit.selectionChanged.connect(self.recursiveDef)
@@ -85,6 +93,8 @@ class EditDialog(QDialog, Ui_Dialog):
#
self.displayedWord.connect(self.session.addWord)
self.newParagraph.connect(self.session.addBlock)
self.playSound.connect(self.sound.playSound)
#self.alert.connect(self.sound.alert)
return
#
@@ -161,14 +171,14 @@ class EditDialog(QDialog, Ui_Dialog):
self.phonetics = data["phonetics"]
else:
self.phonetics = None
print("Checking for phonetics")
if not self.phonetics:
return
print("Looking for audio")
print("Searching for audio file")
for entry in self.phonetics:
if len(entry["audio"]) > 0:
# self.parent().playAlert.emit()
self.parent().playSound.emit(entry["audio"])
print(f"playing {entry['audio']}")
self.playSound.emit(entry["audio"])
return
@pyqtSlot()