|
1 | 1 | from ..ui import settings |
2 | 2 | from PyQt5 import QtWidgets |
3 | | -import os |
4 | 3 | from ..core import defaults |
| 4 | +import json |
5 | 5 |
|
6 | 6 |
|
7 | 7 | class ShowSettingsWindow(QtWidgets.QWidget, settings.Ui_Dialog): |
8 | 8 | def __init__(self): |
9 | 9 | super().__init__() |
10 | 10 | self.setupUi(self) |
11 | | - appDir = os.path.dirname(os.path.realpath(__file__)) |
12 | 11 | try: |
13 | | - os.chdir(f"{appDir}/../..") |
14 | | - config = open("vasisualy.conf", "r") |
15 | | - for line in config: |
16 | | - if "voice:" in line: |
17 | | - voice = line.replace("voice:", "") |
18 | | - elif "speed:" in line: |
19 | | - speed = int(line.replace("speed:", "")) |
20 | | - elif "pitch:" in line: |
21 | | - pitch = int(line.replace("pitch:", "")) |
22 | | - elif "sentences:" in line: |
23 | | - sentences = int(line.replace("sentences:", "")) |
24 | | - elif "music:" in line: |
25 | | - musicDir = line.replace("music:", "") |
26 | | - |
| 12 | + voice = defaults.get_value("voice") |
| 13 | + speed = defaults.get_value("speed") |
| 14 | + pitch = defaults.get_value("pitch") |
| 15 | + sentences = defaults.get_value("wiki_sentences") |
| 16 | + musicDir = defaults.get_value("music") |
| 17 | + theme = defaults.get_value("theme") |
| 18 | + to_lang = defaults.get_value("to_lang") |
| 19 | + from_lang = defaults.get_value("from_lang") |
| 20 | + weather_api = defaults.get_value("weather_api") |
| 21 | + weather_city = defaults.get_value("weather_city") |
27 | 22 | self.voiceBox.setCurrentText(voice) |
28 | 23 | self.speedSlider.setSliderPosition(speed) |
29 | 24 | self.pitchSlider.setSliderPosition(pitch) |
30 | 25 | self.wikiSpin.setValue(sentences) |
31 | 26 | self.musicLoc.setText(musicDir) |
| 27 | + self.themeCombo.setCurrentText(theme) |
| 28 | + self.toLangCombo.setCurrentText(to_lang) |
| 29 | + self.fromLangCombo.setCurrentText(from_lang) |
| 30 | + self.weatherApi.setText(weather_api) |
| 31 | + self.weatherCity.setText(weather_city) |
32 | 32 | except Exception: |
33 | 33 | config = defaults.defaults |
34 | 34 | self.voiceBox.setCurrentText(config["voice"]) |
35 | 35 | self.speedSlider.setSliderPosition(config["speed"]) |
36 | 36 | self.pitchSlider.setSliderPosition(config["pitch"]) |
37 | | - self.wikiSpin.setValue(config["sentences"]) |
| 37 | + self.wikiSpin.setValue(config["wiki_sentences"]) |
38 | 38 | self.musicLoc.setText(config["music"]) |
| 39 | + self.themeCombo.setCurrentText(config["theme"]) |
| 40 | + self.toLangCombo.setCurrentText(config["to_lang"]) |
| 41 | + self.fromLangCombo.setCurrentText(config["from_lang"]) |
| 42 | + self.weatherApi.setText(config["weather_api"]) |
| 43 | + self.weatherCity.setText(config["weather_city"]) |
39 | 44 | self.musicDir.clicked.connect(self.selectDir) |
40 | 45 | self.buttonBox.accepted.connect(self.writeChanges) |
| 46 | + self.buttonBox.rejected.connect(self.hide) |
41 | 47 |
|
42 | 48 | def writeChanges(self): |
43 | | - appDir = os.path.dirname(os.path.realpath(__file__)) |
44 | | - os.chdir(f"{appDir}/../..") |
45 | | - config = open("vasisualy.conf", "w") |
46 | | - config.write(f"voice:{self.voiceBox.currentText()}\n" |
47 | | - f"speed:{self.speedSlider.sliderPosition()}\n" |
48 | | - f"pitch:{self.pitchSlider.sliderPosition()}\n" |
49 | | - f"sentences:{self.wikiSpin.value()}\n" |
50 | | - f"music:{self.musicLoc.text()}") |
51 | | - config.close() |
| 49 | + config = { |
| 50 | + "voice": self.voiceBox.currentText(), |
| 51 | + "speed": self.speedSlider.sliderPosition(), |
| 52 | + "pitch": self.pitchSlider.sliderPosition(), |
| 53 | + "wiki_sentences": self.wikiSpin.value(), |
| 54 | + "music": self.musicLoc.text(), |
| 55 | + "theme": self.themeCombo.currentText(), |
| 56 | + "to_lang": self.toLangCombo.currentText(), |
| 57 | + "from_lang": self.fromLangCombo.currentText(), |
| 58 | + "weather_api": self.weatherApi.text(), |
| 59 | + "weather_city": self.weatherCity.text() |
| 60 | + } |
| 61 | + with open("vasisualy.json", "w") as f: |
| 62 | + json.dump(config, f) |
52 | 63 | self.hide() |
53 | 64 |
|
54 | 65 | def selectDir(self): |
|
0 commit comments