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:
33
main.py
33
main.py
@@ -44,6 +44,7 @@ from PyQt6.QtWidgets import (
|
||||
)
|
||||
|
||||
from lib import *
|
||||
from lib.preferences import Preferences
|
||||
from ui.MainWindow import Ui_MainWindow
|
||||
|
||||
|
||||
@@ -60,8 +61,6 @@ def query_error(query: QSqlQuery) -> None:
|
||||
|
||||
|
||||
class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
playAlert = pyqtSignal()
|
||||
playSound = pyqtSignal(str)
|
||||
|
||||
def __init__(self) -> None:
|
||||
super(MainWindow, self).__init__()
|
||||
@@ -73,8 +72,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
os.path.join(os.path.dirname(__file__), "ui/resources.rcc"), "/"
|
||||
):
|
||||
raise Exception("Unable to register resources.rcc")
|
||||
self.soundOff = SoundOff()
|
||||
|
||||
|
||||
model = QSqlQueryModel()
|
||||
query = QSqlQuery("SELECT * FROM people ORDER BY name")
|
||||
model.setQuery(query)
|
||||
@@ -86,23 +84,28 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
#
|
||||
# Action Connections
|
||||
#
|
||||
self.actionQuit.triggered.connect(self.close) # Y
|
||||
self.actionAddBook.triggered.connect(self.addBook) # Y
|
||||
self.actionEditBook.triggered.connect(self.editBook) # Y
|
||||
self.actionRead.triggered.connect(self.readBook) # Y
|
||||
self.actionQuit.triggered.connect(self.close)
|
||||
self.actionAddBook.triggered.connect(self.addBook)
|
||||
self.actionEditBook.triggered.connect(self.editBook)
|
||||
self.actionRead.triggered.connect(self.readBook)
|
||||
self.actionRead.enabledChanged.connect(self.readBtn.setEnabled)
|
||||
self.actionAddPerson.triggered.connect(self.addPerson) # Y
|
||||
self.actionEditPerson.triggered.connect(self.editPerson) # Y
|
||||
self.actionAddPerson.triggered.connect(self.addPerson)
|
||||
self.actionEditPerson.triggered.connect(self.editPerson)
|
||||
self.actionEditPerson.enabledChanged.connect(
|
||||
self.editBtn.setEnabled
|
||||
) # Y
|
||||
self.peopleView.doubleClicked.connect(self.editPerson) # Y
|
||||
self.peopleView.clicked.connect(self.selectedPerson) # Y
|
||||
self.playAlert.connect(self.soundOff.alert)
|
||||
self.playSound.connect(self.soundOff.playSound)
|
||||
)
|
||||
self.actionPreferences.triggered.connect(self.editPreferences)
|
||||
self.peopleView.doubleClicked.connect(self.editPerson)
|
||||
self.peopleView.clicked.connect(self.selectedPerson)
|
||||
self.show()
|
||||
return
|
||||
|
||||
@pyqtSlot()
|
||||
def editPreferences(self):
|
||||
dlg = Preferences()
|
||||
dlg.exec()
|
||||
return
|
||||
|
||||
@pyqtSlot(QModelIndex)
|
||||
def selectedPerson(self, index: QModelIndex) -> None:
|
||||
person_id = index.siblingAtColumn(0).data()
|
||||
|
||||
Reference in New Issue
Block a user