ADDED change hotkeys

Now you can change hotkeys (f1-f12) to any key on your keyboard
This commit is contained in:
Ninnjah 2020-10-21 00:38:10 +03:00 committed by GitHub
parent 9971375008
commit a7de100c2c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 177 additions and 108 deletions

134
main.py
View file

@ -49,7 +49,7 @@ def found_device(list_): # Поиск микшера VoiceMee
index += 1
return index
def sound_get(mode): # Сбор файлов
def sound_get(mode): # Сбор файлов
if os.path.exists('settings.json') and mode == False:
sounds_list = jsonread('settings.json')
@ -62,7 +62,17 @@ def sound_get(mode): # Сбор файлов
msg.setWindowTitle('Error')
if os.path.exists('sound'):
sounds = os.listdir('sound')
sounds = []
for i in os.listdir('sound'):
format_ = ''
name = i
if os.path.isfile(os.path.join('sound', i)):
while i[-1] != '.':
format_ += i[-1]
i = i[:-1]
format_ = format_[::-1]
if format_ == 'wav':
sounds.append(name)
if len(sounds) == 0:
msg.exec_()
@ -71,8 +81,6 @@ def sound_get(mode): # Сбор файлов
menu = []
sounds_list = ['sound\\']
for i in os.listdir('sound'): # Коонвертируем файлы в .wav
print(f'i = {i}')
print(os.path.join(os.getcwd(), 'sound', i))
name = i
format_ = ''
if os.path.isfile(os.path.join('sound', i)):
@ -87,8 +95,6 @@ def sound_get(mode): # Сбор файлов
else:
sounds_list_cat = [os.path.join('sound', i)]
for x in os.listdir(os.path.join('sound', i)): # Коонвертируем файлы в .wav
print(f'x = {x}')
print(os.path.join('sound', i, x))
name = x
format_ = ''
if os.path.isfile(os.path.join('sound', i, x)):
@ -104,10 +110,10 @@ def sound_get(mode): # Сбор файлов
menu.append(sounds_list)
if os.path.exists('settings.json'):
hotkeys = jsonread('settings.json')[1]
sounds_list = [sounds, hotkeys, menu]
hotkeys = jsonread('settings.json')['hotkeys']
sounds_list = {'sounds':sounds, 'hotkeys':hotkeys, 'menu':menu}
else:
sounds_list = [sounds, ['', '', '', '', '', '', '', '', '', '', '', ''], menu]
sounds_list = {'sounds':sounds, 'hotkeys':{'':''}, 'menu':menu}
for i in COMBOS:
i.addItems(sounds)
@ -118,11 +124,15 @@ def sound_get(mode): # Сбор файлов
return sounds_list
def save(): # Сохранение списка хоткеев
hotkeys = []
hotkeys = {}
sounds = sound_get(False)
for i in COMBOS:
hotkeys.append(i.currentText())
jsonwrite('settings.json', [sounds, hotkeys])
for i in range(len(COMBOS)):
print(COMBOS[i].currentText())
hotkeys.setdefault(HOTKEYS[i].text(), COMBOS[i].currentText())
print(hotkeys)
sounds_list = {'sounds':sounds, 'hotkeys':hotkeys, 'menu':menu}
jsonwrite('settings.json', sounds_list)
sounds = None
hotkeys = None
@ -146,10 +156,17 @@ def play_sound(index): # Проигрываение зву
except:
pass
def hotkey_remap(btn):
button = HOTKEYS[btn]
key = keyboard.read_key()
if key not in ['esc']:
print(key)
print(COMMANDS[COMMANDS.index(button.text())])
COMMANDS[COMMANDS.index(button.text())] = key
button.setText(key)
###! CONTROL !###
def key(arg): # Хоткеи
def select_move(mode):
select[1] += mode[1]
select[0] += mode[0]
@ -162,18 +179,6 @@ def key(arg): # Хоткеи
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('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.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]])
@ -181,20 +186,34 @@ def key(arg): # Хоткеи
keyboard.add_hotkey(76, play_sound, args=[''])
keyboard.add_hotkey(73, sd.stop)
while True:
key = keyboard.read_key()
print(keyboard.key_to_scan_codes(key))
if key == 'esc':
break
elif key in COMMANDS:
print(key)
play_sound(COMMANDS.index(key))
def main(): # Интерфейс
sounds = sound_get(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()
hotkeys_thread.start()
win.save_button.clicked.connect(save)
win.hotkey_1.clicked.connect(lambda: hotkey_remap(0))
win.hotkey_2.clicked.connect(lambda: hotkey_remap(1))
win.hotkey_3.clicked.connect(lambda: hotkey_remap(2))
win.hotkey_4.clicked.connect(lambda: hotkey_remap(3))
win.hotkey_5.clicked.connect(lambda: hotkey_remap(4))
win.hotkey_6.clicked.connect(lambda: hotkey_remap(5))
win.hotkey_7.clicked.connect(lambda: hotkey_remap(6))
win.hotkey_8.clicked.connect(lambda: hotkey_remap(7))
win.hotkey_9.clicked.connect(lambda: hotkey_remap(8))
win.hotkey_10.clicked.connect(lambda: hotkey_remap(9))
win.hotkey_11.clicked.connect(lambda: hotkey_remap(10))
win.hotkey_12.clicked.connect(lambda: hotkey_remap(11))
if __name__ == '__main__':
### Поиск устроства ввода ###
list_ = list(sd.query_devices())
@ -220,10 +239,47 @@ if __name__ == '__main__':
win.combo8,
win.combo9,
win.combo10,
win.combo11,
]
win.combo11,]
HOTKEYS = [
win.hotkey_1,
win.hotkey_2,
win.hotkey_3,
win.hotkey_4,
win.hotkey_5,
win.hotkey_6,
win.hotkey_7,
win.hotkey_8,
win.hotkey_9,
win.hotkey_10,
win.hotkey_11,
win.hotkey_12,]
menu = sound_get(True)[2]
sounds = sound_get(True)['hotkeys']
combo = 0
for i in sounds.items():
index = COMBOS[combo].findText(i[1])
COMBOS[combo].setCurrentIndex(index)
HOTKEYS[combo].setText(i[0])
combo += 1
COMMANDS = [
HOTKEYS[0].text(),
HOTKEYS[1].text(),
HOTKEYS[2].text(),
HOTKEYS[3].text(),
HOTKEYS[4].text(),
HOTKEYS[5].text(),
HOTKEYS[6].text(),
HOTKEYS[7].text(),
HOTKEYS[8].text(),
HOTKEYS[9].text(),
HOTKEYS[10].text(),
HOTKEYS[11].text(),]
menu = sound_get(True)['menu']
hotkeys_thread = threading.Thread(target=key, args=(1,))
hotkeys_thread.setDaemon(True)
main()
sys.exit(app.exec())

View file

@ -43,7 +43,7 @@ class Ui_MainWindow(object):
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.setGeometry(QtCore.QRect(110, 10, 301, 311))
self.verticalLayoutWidget.setObjectName("verticalLayoutWidget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget)
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
@ -85,66 +85,72 @@ class Ui_MainWindow(object):
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.setGeometry(QtCore.QRect(10, 10, 91, 311))
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.hotkey_1 = QtWidgets.QPushButton(self.verticalLayoutWidget_2)
self.hotkey_1.setLayoutDirection(QtCore.Qt.LeftToRight)
self.hotkey_1.setStyleSheet("text-align: right;")
self.hotkey_1.setFlat(True)
self.hotkey_1.setObjectName("hotkey_1")
self.verticalLayout_2.addWidget(self.hotkey_1)
self.hotkey_2 = QtWidgets.QPushButton(self.verticalLayoutWidget_2)
self.hotkey_2.setStyleSheet("text-align: right;")
self.hotkey_2.setFlat(True)
self.hotkey_2.setObjectName("hotkey_2")
self.verticalLayout_2.addWidget(self.hotkey_2)
self.hotkey_3 = QtWidgets.QPushButton(self.verticalLayoutWidget_2)
self.hotkey_3.setStyleSheet("text-align: right;")
self.hotkey_3.setFlat(True)
self.hotkey_3.setObjectName("hotkey_3")
self.verticalLayout_2.addWidget(self.hotkey_3)
self.hotkey_4 = QtWidgets.QPushButton(self.verticalLayoutWidget_2)
self.hotkey_4.setStyleSheet("text-align: right;")
self.hotkey_4.setFlat(True)
self.hotkey_4.setObjectName("hotkey_4")
self.verticalLayout_2.addWidget(self.hotkey_4)
self.hotkey_5 = QtWidgets.QPushButton(self.verticalLayoutWidget_2)
self.hotkey_5.setStyleSheet("text-align: right;")
self.hotkey_5.setFlat(True)
self.hotkey_5.setObjectName("hotkey_5")
self.verticalLayout_2.addWidget(self.hotkey_5)
self.hotkey_6 = QtWidgets.QPushButton(self.verticalLayoutWidget_2)
self.hotkey_6.setStyleSheet("text-align: right;")
self.hotkey_6.setFlat(True)
self.hotkey_6.setObjectName("hotkey_6")
self.verticalLayout_2.addWidget(self.hotkey_6)
self.hotkey_7 = QtWidgets.QPushButton(self.verticalLayoutWidget_2)
self.hotkey_7.setStyleSheet("text-align: right;")
self.hotkey_7.setFlat(True)
self.hotkey_7.setObjectName("hotkey_7")
self.verticalLayout_2.addWidget(self.hotkey_7)
self.hotkey_8 = QtWidgets.QPushButton(self.verticalLayoutWidget_2)
self.hotkey_8.setStyleSheet("text-align: right;")
self.hotkey_8.setFlat(True)
self.hotkey_8.setObjectName("hotkey_8")
self.verticalLayout_2.addWidget(self.hotkey_8)
self.hotkey_9 = QtWidgets.QPushButton(self.verticalLayoutWidget_2)
self.hotkey_9.setStyleSheet("text-align: right;")
self.hotkey_9.setFlat(True)
self.hotkey_9.setObjectName("hotkey_9")
self.verticalLayout_2.addWidget(self.hotkey_9)
self.hotkey_10 = QtWidgets.QPushButton(self.verticalLayoutWidget_2)
self.hotkey_10.setStyleSheet("text-align: right;")
self.hotkey_10.setFlat(True)
self.hotkey_10.setObjectName("hotkey_10")
self.verticalLayout_2.addWidget(self.hotkey_10)
self.hotkey_11 = QtWidgets.QPushButton(self.verticalLayoutWidget_2)
self.hotkey_11.setStyleSheet("text-align: right;")
self.hotkey_11.setFlat(True)
self.hotkey_11.setObjectName("hotkey_11")
self.verticalLayout_2.addWidget(self.hotkey_11)
self.hotkey_12 = QtWidgets.QPushButton(self.verticalLayoutWidget_2)
self.hotkey_12.setStyleSheet("text-align: right;")
self.hotkey_12.setFlat(True)
self.hotkey_12.setObjectName("hotkey_12")
self.verticalLayout_2.addWidget(self.hotkey_12)
self.info_label = QtWidgets.QLabel(self.centralwidget)
self.info_label.setGeometry(QtCore.QRect(10, 430, 401, 20))
font = QtGui.QFont()
@ -154,6 +160,13 @@ class Ui_MainWindow(object):
self.info_label.setStyleSheet("color: #505050;")
self.info_label.setMidLineWidth(0)
self.info_label.setObjectName("info_label")
self.select_label = QtWidgets.QLabel(self.centralwidget)
self.select_label.setGeometry(QtCore.QRect(8, 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")
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
@ -166,16 +179,16 @@ class Ui_MainWindow(object):
_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.hotkey_1.setText(_translate("MainWindow", "hotkey 1"))
self.hotkey_2.setText(_translate("MainWindow", "PushButton"))
self.hotkey_3.setText(_translate("MainWindow", "PushButton"))
self.hotkey_4.setText(_translate("MainWindow", "PushButton"))
self.hotkey_5.setText(_translate("MainWindow", "PushButton"))
self.hotkey_6.setText(_translate("MainWindow", "PushButton"))
self.hotkey_7.setText(_translate("MainWindow", "PushButton"))
self.hotkey_8.setText(_translate("MainWindow", "PushButton"))
self.hotkey_9.setText(_translate("MainWindow", "PushButton"))
self.hotkey_10.setText(_translate("MainWindow", "PushButton"))
self.hotkey_11.setText(_translate("MainWindow", "PushButton"))
self.hotkey_12.setText(_translate("MainWindow", "PushButton"))
self.info_label.setText(_translate("MainWindow", "Press F1 to open overlay"))