Add files via upload

This commit is contained in:
Ninnjah 2020-09-07 15:32:38 +03:00 committed by GitHub
commit 81130ac087
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 408 additions and 0 deletions

145
main.py Normal file
View file

@ -0,0 +1,145 @@
import os
import sys
import json
import threading
import keyboard
import soundfile as sf
import sounddevice as sd
from PyQt5 import QtWidgets, uic, QtGui, QtCore
###! JSON !###
def jsonread(file): ## Чтение JSON
with open(file, "r", encoding='utf-8') as read_file:
data = json.load(read_file)
return data
def jsonwrite(file, data): ## Запись JSON
with open(file, 'w', encoding='utf-8') as write_file:
write_file.write(json.dumps(data))
###! FUNCTIONS !###
def found_device(list_): # Поиск микшера VoiceMeeter
index = 0
for i in list_:
if 'VoiceMeeter Input' in i['name']:
break
index += 1
return index
def sound_get(filename, mode): # Сбор файлов
if os.path.exists(filename) and mode == False:
sounds_list = jsonread(filename)
elif not os.path.exists(filename) or mode == True:
if os.path.exists('sound'):
sounds = os.listdir('sound')
if len(sounds) == 0:
msg = QtWidgets.QMessageBox()
msg.setIcon(QtWidgets.QMessageBox.Critical)
msg.setText("You don't have any sounds in 'sound' folder")
msg.setInformativeText('download sound in .wav format')
msg.setWindowTitle('Error')
msg.exec_()
exit()
if os.path.exists('settings.json'):
hotkeys = jsonread(filename)[1]
sounds_list = [sounds, hotkeys]
else:
sounds_list = [sounds, ['', '', '', '', '', '', '', '', '', '', '', '']]
for i in COMBOS:
i.addItems(sounds)
jsonwrite(filename, sounds_list)
else:
os.mkdir('sound')
msg = QtWidgets.QMessageBox()
msg.setIcon(QtWidgets.QMessageBox.Critical)
msg.setText("You don't have any sounds in 'sound' folder")
msg.setInformativeText('download sound in .wav format')
msg.setWindowTitle('Error')
msg.exec_()
exit()
return sounds_list
def play_sound(index): # Проигрываение звука
#filename = sound_get('settings.json', False)[1][index]
filename = COMBOS[index].currentText()
try:
data, fs = sf.read(os.path.join('sound', filename), dtype='float32')
sd.play(data, fs)
sd.wait()
except:
pass
def start():
hotkeys = []
sounds = sound_get('settings.json', False)
for i in COMBOS:
hotkeys.append(i.currentText())
jsonwrite('settings.json', [sounds, hotkeys])
sounds = None
hotkeys = None
###! CONTROL !###
def key(arg): # Хоткеи
keyboard.add_hotkey('f1', play_sound, args=[0])
keyboard.add_hotkey('f2', play_sound, args=[1])
keyboard.add_hotkey('f3', play_sound, args=[2])
keyboard.add_hotkey('f4', play_sound, args=[3])
keyboard.add_hotkey('f5', play_sound, args=[4])
keyboard.add_hotkey('f6', play_sound, args=[5])
keyboard.add_hotkey('f7', play_sound, args=[6])
keyboard.add_hotkey('f8', play_sound, args=[7])
keyboard.add_hotkey('f9', play_sound, args=[8])
keyboard.add_hotkey('f10', play_sound, args=[9])
keyboard.add_hotkey('f11', play_sound, args=[10])
keyboard.add_hotkey('f12', play_sound, args=[11])
keyboard.wait(hotkey='alt+x')
main()
def main(): # Интерфейс
win.show()
win.start_button.setText('Save')
sounds = sound_get('settings.json', True)[1]
combo = 0
for i in sounds:
index = COMBOS[combo].findText(i)
COMBOS[combo].setCurrentIndex(index)
combo += 1
x = threading.Thread(target=key, args=(1,))
x.setDaemon(True)
x.start()
win.start_button.clicked.connect(start)
if __name__ == '__main__':
# Поиск устроства ввода
list_ = list(sd.query_devices())
index = found_device(list_)
sd.default.device = list_[index]['name']
app = QtWidgets.QApplication([])
win = uic.loadUi("sundpood.ui")
COMBOS = [
win.combo0,
win.combo1,
win.combo2,
win.combo3,
win.combo4,
win.combo5,
win.combo6,
win.combo7,
win.combo8,
win.combo9,
win.combo10,
win.combo11,
]
main()
sys.exit(app.exec())

263
sundpood.ui Normal file
View file

@ -0,0 +1,263 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>420</width>
<height>450</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>420</width>
<height>450</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>420</width>
<height>450</height>
</size>
</property>
<property name="windowTitle">
<string>SundPood</string>
</property>
<property name="windowIcon">
<iconset theme="icon.ico"/>
</property>
<widget class="QWidget" name="centralwidget">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>420</width>
<height>450</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>420</width>
<height>450</height>
</size>
</property>
<widget class="QPushButton" name="start_button">
<property name="geometry">
<rect>
<x>10</x>
<y>330</y>
<width>401</width>
<height>101</height>
</rect>
</property>
<property name="font">
<font>
<family>Consolas</family>
<pointsize>28</pointsize>
</font>
</property>
<property name="text">
<string>START</string>
</property>
</widget>
<widget class="QWidget" name="verticalLayoutWidget">
<property name="geometry">
<rect>
<x>110</x>
<y>10</y>
<width>301</width>
<height>308</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QComboBox" name="combo0"/>
</item>
<item>
<widget class="QComboBox" name="combo1"/>
</item>
<item>
<widget class="QComboBox" name="combo2"/>
</item>
<item>
<widget class="QComboBox" name="combo3"/>
</item>
<item>
<widget class="QComboBox" name="combo4"/>
</item>
<item>
<widget class="QComboBox" name="combo5"/>
</item>
<item>
<widget class="QComboBox" name="combo6"/>
</item>
<item>
<widget class="QComboBox" name="combo7"/>
</item>
<item>
<widget class="QComboBox" name="combo8"/>
</item>
<item>
<widget class="QComboBox" name="combo9"/>
</item>
<item>
<widget class="QComboBox" name="combo10"/>
</item>
<item>
<widget class="QComboBox" name="combo11"/>
</item>
</layout>
</widget>
<widget class="QWidget" name="verticalLayoutWidget_2">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>91</width>
<height>308</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>F1</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>F2</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>F3</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>F4</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>F5</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_6">
<property name="text">
<string>F6</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_7">
<property name="text">
<string>F7</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_8">
<property name="text">
<string>F8</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_9">
<property name="text">
<string>F9</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_10">
<property name="text">
<string>F10</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_11">
<property name="text">
<string>F11</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_12">
<property name="text">
<string>F12</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>