Release update

release
This commit is contained in:
Ninnjah 2020-10-17 23:51:55 +03:00 committed by GitHub
parent 4aba40a327
commit e900665150
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 331 additions and 39 deletions

148
main.py
View file

@ -5,8 +5,29 @@ import threading
import keyboard import keyboard
import soundfile as sf import soundfile as sf
import sounddevice as sd import sounddevice as sd
from PyQt5 import QtWidgets, uic, QtGui, QtCore from PyQt5 import QtWidgets, QtGui, QtCore
import ui_sundpood
import ui_overlay
class OverlayUi(QtWidgets.QMainWindow, ui_overlay.Ui_MainWindow):
def __init__(self, parent=None):
super().__init__(parent)
self.setupUi(self)
def keyPressEvent(self, e):
if e.key() == QtCore.Qt.Key_F1:
self.hide()
win.show()
class MainUi(QtWidgets.QMainWindow, ui_sundpood.Ui_MainWindow):
def __init__(self, parent=None):
super().__init__(parent)
self.setupUi(self)
def keyPressEvent(self, e):
if e.key() == QtCore.Qt.Key_F1:
self.hide()
over.show()
###! JSON !### ###! JSON !###
def jsonread(file): ## Чтение JSON def jsonread(file): ## Чтение JSON
@ -28,55 +49,87 @@ def found_device(list_): # Поиск микшера VoiceMee
index += 1 index += 1
return index return index
def sound_get(filename, mode): # Сбор файлов def sound_get(mode): # Сбор файлов
if os.path.exists(filename) and mode == False: MUSIC = ['Music']
sounds_list = jsonread(filename) MEME = ['Meme']
elif not os.path.exists(filename) or mode == True: OTHER = ['Other']
CATS = [MUSIC, MEME, OTHER]
if os.path.exists('settings.json') and mode == False:
sounds_list = jsonread('settings.json')
elif not os.path.exists('settings.json') or mode == True:
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 / .mp3 / .m4a format')
msg.setWindowTitle('Error')
if os.path.exists('sound'): if os.path.exists('sound'):
sounds = os.listdir('sound') sounds = os.listdir('sound')
if len(sounds) == 0: 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_() msg.exec_()
exit() exit()
for i in os.listdir('sound'): # Коонвертируем файлы в .wav
name = i
format_ = ''
while i[-1] != '.':
format_ += i[-1]
i = i[:-1]
format_ = format_[::-1]
if format_ in ['mp3', 'm4a']:
os.system(f'ffmpeg.exe -i "sound\\{name}" "sound\\{i}wav"')
os.remove(f'sound\\{name}')
sounds = os.listdir('sound')
for i in sounds: # Ищем ключевые слова в названиях песен
tag = ''
for x in i:
if x not in [' ', '.', '-', '_']:
tag += x
else:
break
if tag.lower() == 'music':
MUSIC.append(i)
elif tag.lower() == 'meme':
MEME.append(i)
else:
OTHER.append(i)
menu = []
for i in CATS:
menu.append(i)
if os.path.exists('settings.json'): if os.path.exists('settings.json'):
hotkeys = jsonread(filename)[1] hotkeys = jsonread('settings.json')[1]
sounds_list = [sounds, hotkeys] sounds_list = [sounds, hotkeys, menu]
else: else:
sounds_list = [sounds, ['', '', '', '', '', '', '', '', '', '', '', '']] sounds_list = [sounds, ['', '', '', '', '', '', '', '', '', '', '', ''], menu]
for i in COMBOS: for i in COMBOS:
i.addItems(sounds) i.addItems(sounds)
jsonwrite(filename, sounds_list) jsonwrite('settings.json', sounds_list)
else: 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_() msg.exec_()
exit() exit()
return sounds_list return sounds_list
def save(): # Сохранение списка хоткеев def save(): # Сохранение списка хоткеев
hotkeys = [] hotkeys = []
sounds = sound_get('settings.json', False) sounds = sound_get(False)
for i in COMBOS: for i in COMBOS:
hotkeys.append(i.currentText()) hotkeys.append(i.currentText())
jsonwrite('settings.json', [sounds, hotkeys]) jsonwrite('settings.json', [sounds, hotkeys])
sounds = None sounds = None
hotkeys = None hotkeys = None
#def sounds_explore(): # Оверлей
# print('showing everlay')
# overlay.show()
def play_sound(index): # Проигрываение звука def play_sound(index): # Проигрываение звука
filename = COMBOS[index].currentText() try:
filename = COMBOS[index].currentText()
except:
filename = index
try: try:
data, fs = sf.read(os.path.join('sound', filename), dtype='float32') data, fs = sf.read(os.path.join('sound', filename), dtype='float32')
sd.play(data, fs) sd.play(data, fs)
@ -85,9 +138,24 @@ def play_sound(index): # Проигрываение зву
except: except:
pass pass
###! CONTROL !###
###! CONTROL !###
def key(arg): # Хоткеи def key(arg): # Хоткеи
select = [0, 0]
def select_move(mode):
select[1] += mode[1]
select[0] += mode[0]
if select[0] > len(menu)-1 or select[0] < -len(menu)+1:
select[0] = 0
if select[1] > len(menu[select[0]])-1 or select[1] < -len(menu[select[0]])+1:
select[1] = 0
if mode[0] > 0:
select[1] = 0
over.label.setText(menu[select[0]][select[1]])
win.select_label.setText(menu[select[0]][select[1]])
keyboard.add_hotkey('f1', play_sound, args=[0]) keyboard.add_hotkey('f1', play_sound, args=[0])
keyboard.add_hotkey('f2', play_sound, args=[1]) keyboard.add_hotkey('f2', play_sound, args=[1])
keyboard.add_hotkey('f3', play_sound, args=[2]) keyboard.add_hotkey('f3', play_sound, args=[2])
@ -100,15 +168,15 @@ def key(arg): # Хоткеи
keyboard.add_hotkey('f10', play_sound, args=[9]) keyboard.add_hotkey('f10', play_sound, args=[9])
keyboard.add_hotkey('f11', play_sound, args=[10]) keyboard.add_hotkey('f11', play_sound, args=[10])
keyboard.add_hotkey('f12', play_sound, args=[11]) keyboard.add_hotkey('f12', play_sound, args=[11])
keyboard.add_hotkey(72, select_move, args=[[0, -1]])
keyboard.add_hotkey(80, select_move, args=[[0, 1]])
keyboard.add_hotkey(77, select_move, args=[[1, 0]])
keyboard.add_hotkey(75, select_move, args=[[-1, 0]])
keyboard.add_hotkey(76, play_sound, args=[menu[select[0]][select[1]]])
keyboard.add_hotkey(73, sd.stop) keyboard.add_hotkey(73, sd.stop)
#keyboard.add_hotkey('shift+f2', sounds_explore)
keyboard.wait()
main()
def main(): # Интерфейс def main(): # Интерфейс
win.start_button.setText('Save') sounds = sound_get(True)[1]
win.show()
sounds = sound_get('settings.json', True)[1]
combo = 0 combo = 0
for i in sounds: for i in sounds:
@ -119,19 +187,19 @@ def main(): # Интерфейс
x = threading.Thread(target=key, args=(1,)) x = threading.Thread(target=key, args=(1,))
x.setDaemon(True) x.setDaemon(True)
x.start() x.start()
win.start_button.clicked.connect(save) win.save_button.clicked.connect(save)
if __name__ == '__main__': if __name__ == '__main__':
# Поиск устроства ввода ### Поиск устроства ввода ###
list_ = list(sd.query_devices()) list_ = list(sd.query_devices())
index = found_device(list_) index = found_device(list_)
sd.default.device = list_[index]['name'] sd.default.device = list_[index]['name']
### Создание окна ###
app = QtWidgets.QApplication([]) app = QtWidgets.QApplication([])
win = uic.loadUi("sundpood.ui") over = OverlayUi()
#overlay = uic.loadUi("overlay.ui") win = MainUi()
#overlay.setWindowFlags(QtCore.Qt.ToolTip) win.show()
COMBOS = [ COMBOS = [
win.combo0, win.combo0,
@ -148,5 +216,7 @@ if __name__ == '__main__':
win.combo11, win.combo11,
] ]
menu = sound_get(True)[2]
main() main()
sys.exit(app.exec()) sys.exit(app.exec())

41
ui_overlay.py Normal file
View file

@ -0,0 +1,41 @@
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'overlay.ui'
#
# Created by: PyQt5 UI code generator 5.15.0
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(250, 20)
MainWindow.setMinimumSize(QtCore.QSize(250, 20))
MainWindow.setMaximumSize(QtCore.QSize(250, 20))
MainWindow.setGeometry(QtCore.QRect(0, 0, 250, 20))
MainWindow.setWindowFlags(QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowStaysOnTopHint)
icon = QtGui.QIcon.fromTheme("icon.ico")
MainWindow.setWindowIcon(icon)
MainWindow.setWindowOpacity(0.5)
MainWindow.setToolTipDuration(5)
MainWindow.setStyleSheet("background-color: black;\n"
"color: white;")
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(0, 0, 251, 21))
self.label.setText("")
self.label.setObjectName("label")
MainWindow.setCentralWidget(self.centralwidget)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate(" ", " "))

181
ui_sundpood.py Normal file
View file

@ -0,0 +1,181 @@
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'sundpood.ui'
#
# Created by: PyQt5 UI code generator 5.15.0
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(420, 450)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(MainWindow.sizePolicy().hasHeightForWidth())
MainWindow.setSizePolicy(sizePolicy)
MainWindow.setMinimumSize(QtCore.QSize(420, 450))
MainWindow.setMaximumSize(QtCore.QSize(420, 450))
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap("icon.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
MainWindow.setWindowIcon(icon)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setEnabled(True)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.centralwidget.sizePolicy().hasHeightForWidth())
self.centralwidget.setSizePolicy(sizePolicy)
self.centralwidget.setMinimumSize(QtCore.QSize(420, 450))
self.centralwidget.setMaximumSize(QtCore.QSize(420, 450))
self.centralwidget.setObjectName("centralwidget")
self.save_button = QtWidgets.QPushButton(self.centralwidget)
self.save_button.setGeometry(QtCore.QRect(10, 360, 401, 71))
font = QtGui.QFont()
font.setFamily("Consolas")
font.setPointSize(28)
self.save_button.setFont(font)
self.save_button.setObjectName("save_button")
self.verticalLayoutWidget = QtWidgets.QWidget(self.centralwidget)
self.verticalLayoutWidget.setGeometry(QtCore.QRect(110, 10, 301, 308))
self.verticalLayoutWidget.setObjectName("verticalLayoutWidget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget)
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
self.verticalLayout.setObjectName("verticalLayout")
self.combo0 = QtWidgets.QComboBox(self.verticalLayoutWidget)
self.combo0.setObjectName("combo0")
self.verticalLayout.addWidget(self.combo0)
self.combo1 = QtWidgets.QComboBox(self.verticalLayoutWidget)
self.combo1.setObjectName("combo1")
self.verticalLayout.addWidget(self.combo1)
self.combo2 = QtWidgets.QComboBox(self.verticalLayoutWidget)
self.combo2.setObjectName("combo2")
self.verticalLayout.addWidget(self.combo2)
self.combo3 = QtWidgets.QComboBox(self.verticalLayoutWidget)
self.combo3.setObjectName("combo3")
self.verticalLayout.addWidget(self.combo3)
self.combo4 = QtWidgets.QComboBox(self.verticalLayoutWidget)
self.combo4.setObjectName("combo4")
self.verticalLayout.addWidget(self.combo4)
self.combo5 = QtWidgets.QComboBox(self.verticalLayoutWidget)
self.combo5.setObjectName("combo5")
self.verticalLayout.addWidget(self.combo5)
self.combo6 = QtWidgets.QComboBox(self.verticalLayoutWidget)
self.combo6.setObjectName("combo6")
self.verticalLayout.addWidget(self.combo6)
self.combo7 = QtWidgets.QComboBox(self.verticalLayoutWidget)
self.combo7.setObjectName("combo7")
self.verticalLayout.addWidget(self.combo7)
self.combo8 = QtWidgets.QComboBox(self.verticalLayoutWidget)
self.combo8.setObjectName("combo8")
self.verticalLayout.addWidget(self.combo8)
self.combo9 = QtWidgets.QComboBox(self.verticalLayoutWidget)
self.combo9.setObjectName("combo9")
self.verticalLayout.addWidget(self.combo9)
self.combo10 = QtWidgets.QComboBox(self.verticalLayoutWidget)
self.combo10.setObjectName("combo10")
self.verticalLayout.addWidget(self.combo10)
self.combo11 = QtWidgets.QComboBox(self.verticalLayoutWidget)
self.combo11.setObjectName("combo11")
self.verticalLayout.addWidget(self.combo11)
self.verticalLayoutWidget_2 = QtWidgets.QWidget(self.centralwidget)
self.verticalLayoutWidget_2.setGeometry(QtCore.QRect(10, 10, 91, 308))
self.verticalLayoutWidget_2.setObjectName("verticalLayoutWidget_2")
self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.verticalLayoutWidget_2)
self.verticalLayout_2.setContentsMargins(0, 0, 0, 0)
self.verticalLayout_2.setObjectName("verticalLayout_2")
self.label = QtWidgets.QLabel(self.verticalLayoutWidget_2)
self.label.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
self.label.setObjectName("label")
self.verticalLayout_2.addWidget(self.label)
self.label_2 = QtWidgets.QLabel(self.verticalLayoutWidget_2)
self.label_2.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
self.label_2.setObjectName("label_2")
self.verticalLayout_2.addWidget(self.label_2)
self.label_3 = QtWidgets.QLabel(self.verticalLayoutWidget_2)
self.label_3.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
self.label_3.setObjectName("label_3")
self.verticalLayout_2.addWidget(self.label_3)
self.label_4 = QtWidgets.QLabel(self.verticalLayoutWidget_2)
self.label_4.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
self.label_4.setObjectName("label_4")
self.verticalLayout_2.addWidget(self.label_4)
self.label_5 = QtWidgets.QLabel(self.verticalLayoutWidget_2)
self.label_5.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
self.label_5.setObjectName("label_5")
self.verticalLayout_2.addWidget(self.label_5)
self.label_6 = QtWidgets.QLabel(self.verticalLayoutWidget_2)
self.label_6.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
self.label_6.setObjectName("label_6")
self.verticalLayout_2.addWidget(self.label_6)
self.label_7 = QtWidgets.QLabel(self.verticalLayoutWidget_2)
self.label_7.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
self.label_7.setObjectName("label_7")
self.verticalLayout_2.addWidget(self.label_7)
self.label_8 = QtWidgets.QLabel(self.verticalLayoutWidget_2)
self.label_8.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
self.label_8.setObjectName("label_8")
self.verticalLayout_2.addWidget(self.label_8)
self.label_9 = QtWidgets.QLabel(self.verticalLayoutWidget_2)
self.label_9.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
self.label_9.setObjectName("label_9")
self.verticalLayout_2.addWidget(self.label_9)
self.label_10 = QtWidgets.QLabel(self.verticalLayoutWidget_2)
self.label_10.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
self.label_10.setObjectName("label_10")
self.verticalLayout_2.addWidget(self.label_10)
self.label_11 = QtWidgets.QLabel(self.verticalLayoutWidget_2)
self.label_11.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
self.label_11.setObjectName("label_11")
self.verticalLayout_2.addWidget(self.label_11)
self.label_12 = QtWidgets.QLabel(self.verticalLayoutWidget_2)
self.label_12.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
self.label_12.setObjectName("label_12")
self.verticalLayout_2.addWidget(self.label_12)
self.select_label = QtWidgets.QLabel(self.centralwidget)
self.select_label.setGeometry(QtCore.QRect(10, 320, 401, 41))
self.select_label.setLayoutDirection(QtCore.Qt.LeftToRight)
self.select_label.setStyleSheet("background-color: black;")
self.select_label.setText("")
self.select_label.setAlignment(QtCore.Qt.AlignCenter)
self.select_label.setObjectName("select_label")
self.info_label = QtWidgets.QLabel(self.centralwidget)
self.info_label.setGeometry(QtCore.QRect(10, 430, 401, 20))
font = QtGui.QFont()
font.setFamily("Consolas")
self.info_label.setFont(font)
self.info_label.setLayoutDirection(QtCore.Qt.LeftToRight)
self.info_label.setStyleSheet("color: #505050;")
self.info_label.setMidLineWidth(0)
self.info_label.setObjectName("info_label")
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "SundPood"))
self.save_button.setText(_translate("MainWindow", "Save"))
self.label.setText(_translate("MainWindow", "F1"))
self.label_2.setText(_translate("MainWindow", "F2"))
self.label_3.setText(_translate("MainWindow", "F3"))
self.label_4.setText(_translate("MainWindow", "F4"))
self.label_5.setText(_translate("MainWindow", "F5"))
self.label_6.setText(_translate("MainWindow", "F6"))
self.label_7.setText(_translate("MainWindow", "F7"))
self.label_8.setText(_translate("MainWindow", "F8"))
self.label_9.setText(_translate("MainWindow", "F9"))
self.label_10.setText(_translate("MainWindow", "F10"))
self.label_11.setText(_translate("MainWindow", "F11"))
self.label_12.setText(_translate("MainWindow", "F12"))
self.info_label.setText(_translate("MainWindow", "Press F1 to open overlay"))