Skip to content

Commit 397d26c

Browse files
committed
add usersettings
1 parent 403f918 commit 397d26c

File tree

1 file changed

+41
-20
lines changed

1 file changed

+41
-20
lines changed

main.py

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from settings import SETTINGS
77
import pyttsx3
88
import webbrowser
9+
from configparser import ConfigParser
910

1011
basedir = os.path.dirname(__file__)
1112

@@ -20,18 +21,21 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
2021
def __init__(self):
2122
super(MainWindow, self).__init__()
2223
self.setupUi(self)
24+
self.generateDefaultConfig()
25+
self.config = self.loadConfig()
2326
self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
2427
self.setWindowTitle(SETTINGS['title'])
25-
self.versionLabel.setText(f"Version {SETTINGS['version']} 2023 by {SETTINGS['author']}")
28+
self.versionLabel.setText(f"Version {self.config['DEFAULT']['version']} 2023 by {self.config['DEFAULT']['author']}")
29+
2630
self.engine = pyttsx3.init()
2731
self.volume = self.engine.getProperty('volume')
2832
self.rate = self.engine.getProperty('rate')
2933
self.valumeEdit.setValidator(QtGui.QDoubleValidator(0.1, 1.0, 2))
3034
self.rateEdit.setValidator(QtGui.QDoubleValidator(10, 500, 2))
3135
self.formatList = [".mp3", ".wav", '.ogg', '.aac', '.flac']
32-
self.currentSavepathLabel.setText(os.getcwd()+SETTINGS["savepath"])
36+
self.currentSavepathLabel.setText(self.config['DEFAULT']['savepath'])
3337
self.convertTextEdit.setPlaceholderText("Bitte gebe hier deinen Text ein den du in eine Audioausgabe umwandeln möchtest...")
34-
self.setupFileSystem(os.getcwd()+SETTINGS["savepath"])
38+
self.setupFileSystem(self.config['DEFAULT']['savepath'])
3539
self.setupButtons()
3640
self.setupDials()
3741
self.resetOptions()
@@ -44,6 +48,32 @@ def __init__(self):
4448
#print("Worker started with maximum %d threads" % self.threadpool.maxThreadCount())
4549

4650

51+
def loadConfig(self):
52+
configParser = ConfigParser()
53+
configParser.read('settings.ini')
54+
configParser.sections()
55+
return configParser
56+
57+
def setSavePathConfig(self, path):
58+
configParser = ConfigParser()
59+
configParser.read("settings.ini")
60+
configParser.sections()
61+
configParser['DEFAULT']['savepath'] = path
62+
with open('settings.ini', "w") as f:
63+
configParser.write(f)
64+
65+
def generateDefaultConfig(self):
66+
if os.path.exists("settings.ini"):
67+
return
68+
configParser = ConfigParser()
69+
configParser['DEFAULT'] = {
70+
'version': SETTINGS['version'],
71+
'author': 'S3R43o3',
72+
'savepath': os.getcwd()+ "\\output"
73+
}
74+
with open('settings.ini', "w") as f:
75+
configParser.write(f)
76+
4777
def generateTestFiles(self):
4878
texts = ["test1", "test2", "test3", "test4"]
4979
for t in texts:
@@ -76,7 +106,7 @@ def readAudioFiles(self, path):
76106
return audio_files
77107

78108
def createAudioWidget(self):
79-
files = self.readAudioFiles(os.path.join(basedir+SETTINGS['savepath']))
109+
files = self.readAudioFiles(os.path.join(self.config['DEFAULT']['savepath']))
80110
self.resetAudioTable()
81111

82112
if files:
@@ -102,6 +132,7 @@ def resetAudioTable(self):
102132
self.dataTableWidget.setRowCount(0)
103133
self.dataTableWidget.setHorizontalHeaderLabels(['Name', 'Format', 'Größe'])
104134
self.dataTableWidget.horizontalHeader().setSectionResizeMode(QtWidgets.QHeaderView.ResizeMode.Stretch)
135+
105136

106137
def setupButtons(self):
107138
self.changeSavepathBtn.clicked.connect(self.chooseFolderClicked)
@@ -134,22 +165,11 @@ def setupButtons(self):
134165
self.githubBtn.clicked.connect(self.openGithub)
135166
self.ytBtn.clicked.connect(self.openYoutube)
136167
self.thmBtn.clicked.connect(self.openTHM)
168+
self.eqBtn.clicked.connect(self.showEqPage)
137169

138-
def runMultiKonvert(self):
139-
worker = Worker(self.mulipleConvert)
140-
self.threadpool.start(worker)
141-
142-
def runPlayDemo(self):
143-
worker = Worker(self.playDemo)
144-
self.threadpool.start(worker)
145-
146-
def runSaveAudio(self):
147-
worker = Worker(self.saveAudioClicked)
148-
self.threadpool.start(worker)
149-
150-
def runSpeakText(self):
151-
worker = Worker(self.speakTextClicked)
152-
self.threadpool.start(worker)
170+
def showEqPage(self):
171+
self.stackedWidget.setCurrentWidget(self.eqPage)
172+
self.lastPage = self.stackedWidget.currentIndex()
153173

154174
def setupFileSystem(self, path):
155175
if os.path.exists(path):
@@ -193,6 +213,7 @@ def chooseFolderClicked(self):
193213
folder_path = QtWidgets.QFileDialog.getExistingDirectory(self, 'Select Folder', '', options=options)
194214
if folder_path:
195215
self.currentSavepathLabel.setText(f'{folder_path}')
216+
self.setSavePathConfig(folder_path)
196217

197218
def uploadTextClicked(self):
198219
options = QtWidgets.QFileDialog.Options()
@@ -215,7 +236,7 @@ def saveAudioClicked(self):
215236
if self.convertTextEdit.toPlainText() != "":
216237
if self.filenameEdit.text() != "":
217238
filename = self.filenameEdit.text()
218-
self.engine.save_to_file(self.convertTextEdit.toPlainText(), SETTINGS['savepath']+filename+self.formatComboBox.currentText())
239+
self.engine.save_to_file(self.convertTextEdit.toPlainText(), self.config['DEFAULT']['savepath']+"/"+filename+self.formatComboBox.currentText())
219240
self.engine.runAndWait()
220241
self.convertTextEdit.clear()
221242
self.filenameEdit.clear()

0 commit comments

Comments
 (0)