lint
This commit is contained in:
@@ -1,27 +1,34 @@
|
||||
import json
|
||||
import os
|
||||
|
||||
from PyQt6.QtCore import Qt, pyqtSlot
|
||||
from PyQt6.QtWidgets import QDialog, QListWidgetItem, QAbstractItemView
|
||||
from PyQt6.QtMultimedia import QMediaDevices
|
||||
from PyQt6.QtWidgets import QAbstractItemView, QDialog, QListWidgetItem
|
||||
|
||||
from ui.Preferences import Ui_Dialog
|
||||
|
||||
|
||||
class Preferences(QDialog, Ui_Dialog):
|
||||
_instance = None
|
||||
|
||||
def __new__(cls):
|
||||
if cls._instance:
|
||||
return cls._instance
|
||||
cls._instance = super(Preferences, cls).__new__(cls)
|
||||
return cls._instance
|
||||
|
||||
@pyqtSlot(int)
|
||||
def done(self, r):
|
||||
self.hide()
|
||||
super().done(r)
|
||||
return
|
||||
|
||||
@pyqtSlot()
|
||||
def exec(self):
|
||||
self.show()
|
||||
super().exec()
|
||||
return
|
||||
|
||||
@pyqtSlot()
|
||||
def open(self):
|
||||
self.show()
|
||||
@@ -35,8 +42,12 @@ class Preferences(QDialog, Ui_Dialog):
|
||||
#
|
||||
# Overrides
|
||||
#
|
||||
self.alertList.setSelectionMode(QAbstractItemView.SelectionMode.MultiSelection)
|
||||
self.playerList.setSelectionMode(QAbstractItemView.SelectionMode.MultiSelection)
|
||||
self.alertList.setSelectionMode(
|
||||
QAbstractItemView.SelectionMode.MultiSelection
|
||||
)
|
||||
self.playerList.setSelectionMode(
|
||||
QAbstractItemView.SelectionMode.MultiSelection
|
||||
)
|
||||
self.readerCombo.setEditable(False)
|
||||
self.phoneticsCombo.setEditable(False)
|
||||
#
|
||||
@@ -51,30 +62,34 @@ class Preferences(QDialog, Ui_Dialog):
|
||||
return
|
||||
|
||||
def setCurrent(self):
|
||||
if os.path.exists('preferences.json'):
|
||||
with open('preferences.json','r') as f:
|
||||
if os.path.exists("preferences.json"):
|
||||
with open("preferences.json", "r") as f:
|
||||
self.preferences = json.load(f)
|
||||
else:
|
||||
self.preferences = {
|
||||
'readerFont': 'OpenDyslexic',
|
||||
'phoneticFont': 'Gentium',
|
||||
'alertOutputs': [ 'default' ],
|
||||
'playerOutputs': [ 'Feed for virtual microphone' ]
|
||||
"readerFont": "OpenDyslexic",
|
||||
"phoneticFont": "Gentium",
|
||||
"alertOutputs": ["default"],
|
||||
"playerOutputs": ["Feed for virtual microphone"],
|
||||
}
|
||||
for output in self.preferences['alertOutputs']:
|
||||
if output == 'default':
|
||||
for output in self.preferences["alertOutputs"]:
|
||||
if output == "default":
|
||||
output = QMediaDevices.defaultAudioOutput().description()
|
||||
for item in self.alertList.findItems(output,Qt.MatchFlag.MatchExactly):
|
||||
for item in self.alertList.findItems(
|
||||
output, Qt.MatchFlag.MatchExactly
|
||||
):
|
||||
item.setSelected(True)
|
||||
for output in self.preferences['playerOutputs']:
|
||||
if output == 'default':
|
||||
for output in self.preferences["playerOutputs"]:
|
||||
if output == "default":
|
||||
output = QMediaDevices.defaultAudioOutput().description()
|
||||
for item in self.playerList.findItems(output,Qt.MatchFlag.MatchExactly ):
|
||||
for item in self.playerList.findItems(
|
||||
output, Qt.MatchFlag.MatchExactly
|
||||
):
|
||||
item.setSelected(True)
|
||||
index = self.readerCombo.findText(self.preferences['readerFont'])
|
||||
index = self.readerCombo.findText(self.preferences["readerFont"])
|
||||
if index >= 0:
|
||||
self.readerCombo.setCurrentIndex(index)
|
||||
index = self.phoneticsCombo.findText(self.preferences['phoneticFont'])
|
||||
index = self.phoneticsCombo.findText(self.preferences["phoneticFont"])
|
||||
if index >= 0:
|
||||
self.phoneticsCombo.setCurrentIndex(index)
|
||||
return
|
||||
@@ -85,11 +100,19 @@ class Preferences(QDialog, Ui_Dialog):
|
||||
return self.preferences[name]
|
||||
|
||||
def accept(self):
|
||||
self.preferences['readerFont'] = self.readerCombo.currentFont().family()
|
||||
self.preferences['phoneticFont'] =self.phoneticsCombo.currentFont().family()
|
||||
self.preferences['alertOutputs'] = [ x.data(Qt.ItemDataRole.DisplayRole) for x in self.alertList.selectedItems() ]
|
||||
self.preferences['playerOutputs'] = [ x.data(Qt.ItemDataRole.DisplayRole) for x in self.playerList.selectedItems() ]
|
||||
with open('preferences.json','w') as f:
|
||||
self.preferences["readerFont"] = self.readerCombo.currentFont().family()
|
||||
self.preferences[
|
||||
"phoneticFont"
|
||||
] = self.phoneticsCombo.currentFont().family()
|
||||
self.preferences["alertOutputs"] = [
|
||||
x.data(Qt.ItemDataRole.DisplayRole)
|
||||
for x in self.alertList.selectedItems()
|
||||
]
|
||||
self.preferences["playerOutputs"] = [
|
||||
x.data(Qt.ItemDataRole.DisplayRole)
|
||||
for x in self.playerList.selectedItems()
|
||||
]
|
||||
with open("preferences.json", "w") as f:
|
||||
json.dump(self.preferences, f, indent=2)
|
||||
super().accept()
|
||||
return
|
||||
|
||||
@@ -12,6 +12,7 @@ from PyQt6.QtMultimedia import (
|
||||
|
||||
class SoundOff(QObject):
|
||||
_instance = None
|
||||
|
||||
def __new__(cls):
|
||||
if cls._instance:
|
||||
return cls._instance
|
||||
|
||||
5
main.py
5
main.py
@@ -61,7 +61,6 @@ def query_error(query: QSqlQuery) -> None:
|
||||
|
||||
|
||||
class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
|
||||
def __init__(self) -> None:
|
||||
super(MainWindow, self).__init__()
|
||||
self.setupUi(self)
|
||||
@@ -91,9 +90,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
self.actionRead.enabledChanged.connect(self.readBtn.setEnabled)
|
||||
self.actionAddPerson.triggered.connect(self.addPerson)
|
||||
self.actionEditPerson.triggered.connect(self.editPerson)
|
||||
self.actionEditPerson.enabledChanged.connect(
|
||||
self.editBtn.setEnabled
|
||||
)
|
||||
self.actionEditPerson.enabledChanged.connect(self.editBtn.setEnabled)
|
||||
self.actionPreferences.triggered.connect(self.editPreferences)
|
||||
self.peopleView.doubleClicked.connect(self.editPerson)
|
||||
self.peopleView.clicked.connect(self.selectedPerson)
|
||||
|
||||
Reference in New Issue
Block a user