Skip to content

Commit c6648bc

Browse files
authored
v0.7.1
v0.7.1-alpha - Навык анекдотчика - Изменён загрузчик новых навыков - Изменены настройки программы - Изменён GUI настроек
1 parent e40a8cc commit c6648bc

File tree

17 files changed

+356
-116
lines changed

17 files changed

+356
-116
lines changed

vasisualy.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"voice": "Artemiy",
3+
"speed": 30,
4+
"pitch": 0,
5+
"wiki_sentences": 4,
6+
"music": "music/",
7+
"theme": "System",
8+
"to_lang": "en",
9+
"from_lang": "ru",
10+
"weather_api": "",
11+
"weather_city": "Лондон"
12+
}

vasisualy/core/defaults.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
1+
import json
2+
13
defaults = {
24
"voice": "Artemiy",
35
"speed": 30,
46
"pitch": 0,
5-
"sentences": 4,
6-
"music": "music/"
7-
}
7+
"wiki_sentences": 4,
8+
"music": "music/",
9+
"theme": "Dark Red",
10+
"from_lang": "ru",
11+
"to_lang": "en",
12+
"weather_api": "",
13+
"weather_city": "Лондон"
14+
}
15+
16+
17+
def get_value(param):
18+
'''
19+
Получение параметра из файла настройки JSON.
20+
:param param: нужный параметр.
21+
:return: значение, соответствующее параметру.
22+
'''
23+
with open("vasisualy.json", "r") as f:
24+
settings = json.load(f)
25+
value = settings[param]
26+
return value

vasisualy/core/speak.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,25 @@
11
import speechd
22
from . import defaults
3-
import os
43

54
# Настройка синтезатора речи
65
tts_d = speechd.SSIPClient('Vasisya')
76
tts_d.set_output_module('rhvoice')
87
tts_d.set_language('ru')
98
try:
10-
appDir = os.path.dirname(os.path.realpath(__file__))
11-
os.chdir(f"{appDir}/../../")
12-
config = open("vasisualy.conf", "r")
13-
for line in config:
14-
if "voice:" in line:
15-
voice = line.replace("voice:", "")
16-
elif "speed:" in line:
17-
speed = int(line.replace("speed:", ""))
18-
elif "pitch:" in line:
19-
pitch = int(line.replace("pitch:", ""))
20-
except Exception:
9+
voice = defaults.get_value("voice")
10+
speed = defaults.get_value("speed")
11+
pitch = defaults.get_value("pitch")
12+
except FileNotFoundError:
2113
voice = defaults.defaults["voice"]
2214
speed = defaults.defaults["speed"]
2315
pitch = defaults.defaults["pitch"]
2416

2517
tts_d.set_synthesis_voice(voice)
2618
tts_d.set_rate(speed)
27-
tts_d.set_punctuation(speechd.PunctuationMode.NONE)
19+
tts_d.set_punctuation(speechd.PunctuationMode.SOME)
2820
tts_d.set_pitch(pitch)
2921

22+
3023
def speak(message, widget):
3124
'''Выводит сообщение пользователю и озвучивает его.
3225
:param message: сообщение, которое нужно вывести и озвучить (string).

vasisualy/main.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
from qt_material import apply_stylesheet
99

1010
# Core
11-
from .core import (speak, talk, recognise)
11+
from .core import (speak, talk, recognise, defaults)
1212
import random
1313

1414
# Skills
15-
from .skills import (skill_loader, time_date, exit, joke, weather, music, open, screenshot, search, poweroff, ytvideo,
15+
from .skills import (skill_loader, time_date, exit, weather, music, open, screenshot, search, poweroff, ytvideo,
1616
resay, map, wiki, location, weather_no_city, translate, news, coin, upd_upg, shoplist, todolist,
1717
netconnection, record, guess_num, rulette, math, audio, crystal_ball, random_num, timer,
1818
show_about, show_settings, old_skills)
@@ -29,6 +29,27 @@
2929
"Ты ошибаешься.", "Я не понимаю твоего вопроса.", "Мне не понятен твой вопрос.",
3030
"Не могу понять о чём ты говоришь.", "Я не понимаю.", "О чём ты?", "Я не могу распознать вопрос.")
3131

32+
styles = {
33+
"Dark Amber": "dark_amber.xml",
34+
"Dark Blue": "dark_blue.xml",
35+
"Dark Cyan": "dark_cyan.xml",
36+
"Dark Lightgreen": "dark_lightgreen.xml",
37+
"Dark Pink": "dark_pink.xml",
38+
"Dark Purple": "dark_purple.xml",
39+
"Dark Red": "dark_red.xml",
40+
"Dark Teal": "dark_teal.xml",
41+
"Dark Yellow": "dark_yellow.xml",
42+
"Light Amber": "light_amber.xml",
43+
"Light Blue": "light_blue.xml",
44+
"Light Cyan": "light_cyan.xml",
45+
"Light Lightgreen": "light_lightgreen.xml",
46+
"Light Pink": "light_pink.xml",
47+
"Light Purple": "light_purple.xml",
48+
"Light Red": "light_red.xml",
49+
"Light Teal": "light_teal.xml",
50+
"Light Yellow": "light_yellow.xml",
51+
}
52+
3253
randnum = -1
3354
isGuessNum = False
3455
isRuLette = False
@@ -122,7 +143,14 @@ def program(self):
122143
def main():
123144
app = QtWidgets.QApplication(sys.argv)
124145
window = Main()
125-
apply_stylesheet(app, theme='dark_red.xml')
146+
147+
try:
148+
theme = defaults.get_value("theme")
149+
except FileNotFoundError:
150+
theme = defaults.defaults["theme"]
151+
152+
if theme != "System":
153+
apply_stylesheet(app, theme=styles[theme])
126154
window.show()
127155
app.exec_()
128156
speak.tts_d.close()

vasisualy/skills/jokes/__init__.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from vasisualy.skills.vas_skill.vas_skill import Skill # Импорт родительского класса навыков
2+
import requests
3+
from bs4 import BeautifulSoup
4+
import random
5+
6+
7+
class Jokes(Skill):
8+
def get_jokes(self):
9+
site = requests.get("http://anekdotme.ru/random")
10+
bs = BeautifulSoup(site.text, "html.parser")
11+
selections = bs.select(".anekdot_text")
12+
13+
jokes = []
14+
15+
for selection in selections:
16+
selections = (selection.getText().strip())
17+
jokes.append(selections)
18+
19+
return jokes
20+
21+
def main(self, user_message):
22+
if super(Jokes, self)._is_triggered(user_message, super(Jokes, self)._get_triggers()):
23+
toSpeak = random.choice(self.get_jokes())
24+
return toSpeak
25+
else:
26+
return ''
27+
28+
def main(user_message):
29+
skill = Jokes("jokes", user_message) # Вывод сообщения, переданного навыком, пользователю.
30+
return skill.main(user_message)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Анекдот
2+
анекдот
3+
Смех
4+
смех
5+
Рассмеши
6+
рассмеши
7+
Расскажи анекдот
8+
расскажи анекдот
9+
Рассмеши меня
10+
рассмеши меня
11+
Смешной анекдот
12+
смешной анекдот
13+
Хочу смеяться
14+
хочу смеяться
15+
Хочу посмеяться
16+
хочу посмеяться
17+
Шутка
18+
шутка
19+
Юмор
20+
юмор
21+
Давай анекдот
22+
давай анекдот
23+
Давай шутку
24+
давай шутку
25+
Расскажи шутку
26+
расскажи шутку
27+
Смейся
28+
смейся

vasisualy/skills/music.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,8 @@ def main(say, widget):
9696
def playFromDir():
9797
global musicIsPlayed, usrPlayer
9898
try:
99-
appDir = os.path.dirname(os.path.realpath(__file__))
100-
os.chdir(f"{appDir}/../..")
101-
config = open("vasisualy.conf", "r")
102-
for line in config:
103-
if "music:" in line:
104-
musicDir = line.replace("music:", "")
105-
except Exception:
99+
musicDir = defaults.get_value("music")
100+
except FileNotFoundError:
106101
musicDir = defaults.defaults["music"]
107102
playlist = os.listdir(musicDir) # Получение списка файлов из директории music в корне проекта
108103
if musicIsPlayed:

vasisualy/skills/old_skills.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def old_skills_activate(user_message, widget, _cls):
77
:param: user_message - сообщение пользователя (string)
88
:param: widget - виджет, в который должно выводиться сообщение навыка (QWidget)
99
'''
10-
skills = ("time_date", "exit", "joke", "weather", "music", "open", "screenshot", "search", "poweroff",
10+
skills = ("time_date", "exit", "weather", "music", "open", "screenshot", "search", "poweroff",
1111
"ytvideo", "resay", "map", "wiki", "location", "weather_no_city", "translate", "news", "coin",
1212
"upd_upg", "shoplist", "todolist", "netconnection", "record", "math", "audio", "crystal_ball",
1313
"random_num", "timer")

vasisualy/skills/show_settings.py

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,65 @@
11
from ..ui import settings
22
from PyQt5 import QtWidgets
3-
import os
43
from ..core import defaults
4+
import json
55

66

77
class ShowSettingsWindow(QtWidgets.QWidget, settings.Ui_Dialog):
88
def __init__(self):
99
super().__init__()
1010
self.setupUi(self)
11-
appDir = os.path.dirname(os.path.realpath(__file__))
1211
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")
2722
self.voiceBox.setCurrentText(voice)
2823
self.speedSlider.setSliderPosition(speed)
2924
self.pitchSlider.setSliderPosition(pitch)
3025
self.wikiSpin.setValue(sentences)
3126
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)
3232
except Exception:
3333
config = defaults.defaults
3434
self.voiceBox.setCurrentText(config["voice"])
3535
self.speedSlider.setSliderPosition(config["speed"])
3636
self.pitchSlider.setSliderPosition(config["pitch"])
37-
self.wikiSpin.setValue(config["sentences"])
37+
self.wikiSpin.setValue(config["wiki_sentences"])
3838
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"])
3944
self.musicDir.clicked.connect(self.selectDir)
4045
self.buttonBox.accepted.connect(self.writeChanges)
46+
self.buttonBox.rejected.connect(self.hide)
4147

4248
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)
5263
self.hide()
5364

5465
def selectDir(self):

vasisualy/skills/skill_loader.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ def load():
5252

5353
def run_skills(user_message, widget):
5454
# Активирует навыки
55+
result = ''
5556
for skill in _relation():
5657
result = sys.modules[skill].main(user_message)
5758

58-
if result == '':
59-
return None
60-
else:
59+
if result:
6160
speak.speak(result, widget)
62-
return result
63-
break
61+
break
62+
63+
return result

0 commit comments

Comments
 (0)