История изменений
Исправление CrX, (текущая версия) :
if event.key() == Qt.Key.Key_A:
self.launch_application("/usr/lib64/LibreOffice-still/program/scalc")
elif event.key() == Qt.Key.Key_B:
self.launch_application("brave")
elif event.key() == Qt.Key.Key_C:
self.launch_application("qtcreator")
elif event.key() == Qt.Key.Key_D:
self.launch_application("dia")
elif event.key() == Qt.Key.Key_E:
self.launch_application("emacs")
elif event.key() == Qt.Key.Key_F:
self.launch_application("firefox")
elif event.key() == Qt.Key.Key_G:
self.launch_application("gambas3")
elif event.key() == Qt.Key.Key_I:
self.launch_application("qbittorrent")
elif event.key() == Qt.Key.Key_K:
self.launch_application("konversation")
elif event.key() == Qt.Key.Key_L:
self.launch_application("lazarus")
elif event.key() == Qt.Key.Key_M:
self.launch_application("qmmp-1")
elif event.key() == Qt.Key.Key_P:
self.launch_application("psi-plus")
elif event.key() == Qt.Key.Key_Q:
self.launch_application("qalculate-gtk")
elif event.key() == Qt.Key.Key_S:
self.launch_application("skypeforlinux")
elif event.key() == Qt.Key.Key_T:
self.launch_application("telegram-desktop")
elif event.key() == Qt.Key.Key_U:
self.launch_application("thunderbird")
elif event.key() == Qt.Key.Key_W:
self.launch_application("/usr/lib64/LibreOffice-still/program/swriter")
elif event.key() == Qt.Key.Key_Y:
self.launch_application("yandex-browser-stable")
elif event.key() == Qt.Key.Key_1:
self.launch_application("gimp")
elif event.key() == Qt.Key.Key_2:
self.launch_application("inkscape")
elif event.key() == Qt.Key.Key_3:
self.launch_application("librecad")
elif event.key() == Qt.Key.Key_0:
self.launch_application("terminology")
Во-первых, не надо дёргать функцию столько раз, оно ж для каждой ветки запускается — один раз вызови этот event.key() и присвой значение переменной.
Ну а во-вторых… Не задолбался эти elif, и elf.launch_application() писать 100500 раз, и править это дело в случае желания изменить хоткей — тоже тот ещё кайф… Смотри:
mappings = {
Qt.Key.Key_A: "/usr/lib64/LibreOffice-still/program/scalc",
Qt.Key.Key_B: "brave",
Qt.Key.Key_C: "qtcreator",
# ...
# и т.д.
# ...
Qt.Key.Key_0: "terminology"
}
key = event.key()
if key in mappings:
self.launch_application(mappings[key])
Исправление CrX, :
if event.key() == Qt.Key.Key_A:
self.launch_application("/usr/lib64/LibreOffice-still/program/scalc")
elif event.key() == Qt.Key.Key_B:
self.launch_application("brave")
elif event.key() == Qt.Key.Key_C:
self.launch_application("qtcreator")
elif event.key() == Qt.Key.Key_D:
self.launch_application("dia")
elif event.key() == Qt.Key.Key_E:
self.launch_application("emacs")
elif event.key() == Qt.Key.Key_F:
self.launch_application("firefox")
elif event.key() == Qt.Key.Key_G:
self.launch_application("gambas3")
elif event.key() == Qt.Key.Key_I:
self.launch_application("qbittorrent")
elif event.key() == Qt.Key.Key_K:
self.launch_application("konversation")
elif event.key() == Qt.Key.Key_L:
self.launch_application("lazarus")
elif event.key() == Qt.Key.Key_M:
self.launch_application("qmmp-1")
elif event.key() == Qt.Key.Key_P:
self.launch_application("psi-plus")
elif event.key() == Qt.Key.Key_Q:
self.launch_application("qalculate-gtk")
elif event.key() == Qt.Key.Key_S:
self.launch_application("skypeforlinux")
elif event.key() == Qt.Key.Key_T:
self.launch_application("telegram-desktop")
elif event.key() == Qt.Key.Key_U:
self.launch_application("thunderbird")
elif event.key() == Qt.Key.Key_W:
self.launch_application("/usr/lib64/LibreOffice-still/program/swriter")
elif event.key() == Qt.Key.Key_Y:
self.launch_application("yandex-browser-stable")
elif event.key() == Qt.Key.Key_1:
self.launch_application("gimp")
elif event.key() == Qt.Key.Key_2:
self.launch_application("inkscape")
elif event.key() == Qt.Key.Key_3:
self.launch_application("librecad")
elif event.key() == Qt.Key.Key_0:
self.launch_application("terminology")
Во-первых, не надо дёргать функцию столько раз, оно ж для каждой ветки запускается — один раз вызови этот event.key() и присвой значение переменной.
Ну а во-вторых…
mappings = {
Qt.Key.Key_A: "/usr/lib64/LibreOffice-still/program/scalc",
Qt.Key.Key_B: "brave",
Qt.Key.Key_C: "qtcreator",
# ...
# и т.д.
# ...
Qt.Key.Key_0: "terminology"
}
key = event.key()
if key in mappings:
self.launch_application(mappings[key])
Исправление CrX, :
if event.key() == Qt.Key.Key_A:
self.launch_application("/usr/lib64/LibreOffice-still/program/scalc")
elif event.key() == Qt.Key.Key_B:
self.launch_application("brave")
elif event.key() == Qt.Key.Key_C:
self.launch_application("qtcreator")
elif event.key() == Qt.Key.Key_D:
self.launch_application("dia")
elif event.key() == Qt.Key.Key_E:
self.launch_application("emacs")
elif event.key() == Qt.Key.Key_F:
self.launch_application("firefox")
elif event.key() == Qt.Key.Key_G:
self.launch_application("gambas3")
elif event.key() == Qt.Key.Key_I:
self.launch_application("qbittorrent")
elif event.key() == Qt.Key.Key_K:
self.launch_application("konversation")
elif event.key() == Qt.Key.Key_L:
self.launch_application("lazarus")
elif event.key() == Qt.Key.Key_M:
self.launch_application("qmmp-1")
elif event.key() == Qt.Key.Key_P:
self.launch_application("psi-plus")
elif event.key() == Qt.Key.Key_Q:
self.launch_application("qalculate-gtk")
elif event.key() == Qt.Key.Key_S:
self.launch_application("skypeforlinux")
elif event.key() == Qt.Key.Key_T:
self.launch_application("telegram-desktop")
elif event.key() == Qt.Key.Key_U:
self.launch_application("thunderbird")
elif event.key() == Qt.Key.Key_W:
self.launch_application("/usr/lib64/LibreOffice-still/program/swriter")
elif event.key() == Qt.Key.Key_Y:
self.launch_application("yandex-browser-stable")
elif event.key() == Qt.Key.Key_1:
self.launch_application("gimp")
elif event.key() == Qt.Key.Key_2:
self.launch_application("inkscape")
elif event.key() == Qt.Key.Key_3:
self.launch_application("librecad")
elif event.key() == Qt.Key.Key_0:
self.launch_application("terminology")
mappings = {
Qt.Key.Key_A: "/usr/lib64/LibreOffice-still/program/scalc",
Qt.Key.Key_B: "brave",
Qt.Key.Key_C: "qtcreator",
# ...
# и т.д.
# ...
Qt.Key.Key_0: "terminology"
}
key = event.key()
if key in mappings:
self.launch_application(mappings[key])
Исправление CrX, :
if event.key() == Qt.Key.Key_A:
self.launch_application("/usr/lib64/LibreOffice-still/program/scalc")
elif event.key() == Qt.Key.Key_B:
self.launch_application("brave")
elif event.key() == Qt.Key.Key_C:
self.launch_application("qtcreator")
elif event.key() == Qt.Key.Key_D:
self.launch_application("dia")
elif event.key() == Qt.Key.Key_E:
self.launch_application("emacs")
elif event.key() == Qt.Key.Key_F:
self.launch_application("firefox")
elif event.key() == Qt.Key.Key_G:
self.launch_application("gambas3")
elif event.key() == Qt.Key.Key_I:
self.launch_application("qbittorrent")
elif event.key() == Qt.Key.Key_K:
self.launch_application("konversation")
elif event.key() == Qt.Key.Key_L:
self.launch_application("lazarus")
elif event.key() == Qt.Key.Key_M:
self.launch_application("qmmp-1")
elif event.key() == Qt.Key.Key_P:
self.launch_application("psi-plus")
elif event.key() == Qt.Key.Key_Q:
self.launch_application("qalculate-gtk")
elif event.key() == Qt.Key.Key_S:
self.launch_application("skypeforlinux")
elif event.key() == Qt.Key.Key_T:
self.launch_application("telegram-desktop")
elif event.key() == Qt.Key.Key_U:
self.launch_application("thunderbird")
elif event.key() == Qt.Key.Key_W:
self.launch_application("/usr/lib64/LibreOffice-still/program/swriter")
elif event.key() == Qt.Key.Key_Y:
self.launch_application("yandex-browser-stable")
elif event.key() == Qt.Key.Key_1:
self.launch_application("gimp")
elif event.key() == Qt.Key.Key_2:
self.launch_application("inkscape")
elif event.key() == Qt.Key.Key_3:
self.launch_application("librecad")
elif event.key() == Qt.Key.Key_0:
self.launch_application("terminology")
mappings = {
Qt.Key.Key_A: "/usr/lib64/LibreOffice-still/program/scalc",
Qt.Key.Key_B: "brave",
Qt.Key.Key_C: "qtcreator",
# ...
# и т.д.
# ...
Qt.Key.Key_0: "terminology"
}
self.launch_application(mappings[event.key()])
Исходная версия CrX, :
if event.key() == Qt.Key.Key_A:
self.launch_application("/usr/lib64/LibreOffice-still/program/scalc")
elif event.key() == Qt.Key.Key_B:
self.launch_application("brave")
elif event.key() == Qt.Key.Key_C:
self.launch_application("qtcreator")
elif event.key() == Qt.Key.Key_D:
self.launch_application("dia")
elif event.key() == Qt.Key.Key_E:
self.launch_application("emacs")
elif event.key() == Qt.Key.Key_F:
self.launch_application("firefox")
elif event.key() == Qt.Key.Key_G:
self.launch_application("gambas3")
elif event.key() == Qt.Key.Key_I:
self.launch_application("qbittorrent")
elif event.key() == Qt.Key.Key_K:
self.launch_application("konversation")
elif event.key() == Qt.Key.Key_L:
self.launch_application("lazarus")
elif event.key() == Qt.Key.Key_M:
self.launch_application("qmmp-1")
elif event.key() == Qt.Key.Key_P:
self.launch_application("psi-plus")
elif event.key() == Qt.Key.Key_Q:
self.launch_application("qalculate-gtk")
elif event.key() == Qt.Key.Key_S:
self.launch_application("skypeforlinux")
elif event.key() == Qt.Key.Key_T:
self.launch_application("telegram-desktop")
elif event.key() == Qt.Key.Key_U:
self.launch_application("thunderbird")
elif event.key() == Qt.Key.Key_W:
self.launch_application("/usr/lib64/LibreOffice-still/program/swriter")
elif event.key() == Qt.Key.Key_Y:
self.launch_application("yandex-browser-stable")
elif event.key() == Qt.Key.Key_1:
self.launch_application("gimp")
elif event.key() == Qt.Key.Key_2:
self.launch_application("inkscape")
elif event.key() == Qt.Key.Key_3:
self.launch_application("librecad")
elif event.key() == Qt.Key.Key_0:
self.launch_application("terminology")
mappings = {
Qt.Key.Key_A: "/usr/lib64/LibreOffice-still/program/scalc",
Qt.Key.Key_B: "brave",
Qt.Key.Key_C: "qtcreator",
# и т.д.
}
self.launch_application(mappings[event.key()])