mirror of
https://gitee.com/gfdgd-xi/deep-wine-runner
synced 2025-12-13 18:42:03 +08:00
快捷键编辑
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
#!/usr/bin/env python3
|
||||
import os
|
||||
import sys
|
||||
import traceback
|
||||
programPath = os.path.split(os.path.realpath(__file__))[0] # 返回 string
|
||||
sys.path.append(f"{programPath}/..")
|
||||
|
||||
import os
|
||||
import sys
|
||||
import dbus
|
||||
import json
|
||||
import threading
|
||||
import traceback
|
||||
from UI.KeyAddKeyboardGui import *
|
||||
import PyQt5.QtWidgets as QtWidgets
|
||||
|
||||
@@ -19,6 +22,7 @@ class Check:
|
||||
try:
|
||||
bus = dbus.SessionBus()
|
||||
bus.get_object("com.deepin.daemon.Keybinding", "/com/deepin/daemon/Keybinding").List()
|
||||
int("a")
|
||||
return True
|
||||
except:
|
||||
print("无法检测到 Deepin/UOS 快捷键服务")
|
||||
@@ -36,6 +40,9 @@ class Click:
|
||||
if ui.exeName.text() == "" or ui.localKey.text() == "" or ui.wineKey.text() == "":
|
||||
QtWidgets.QMessageBox.critical(window, "错误", "您的信息暂未填写完整")
|
||||
return
|
||||
if ui.localKey.text()[0] == " " or ui.wineKey.text()[0] == " ":
|
||||
QtWidgets.QMessageBox.critical(window, "错误", "映射快捷键的第一位不能为空格")
|
||||
return
|
||||
# Deepin/UOS 的情况
|
||||
if Check.VersionCheck():
|
||||
# 接入 dbus
|
||||
@@ -51,6 +58,36 @@ class Click:
|
||||
traceback.print_exc()
|
||||
QtWidgets.QMessageBox.critical(window, "错误", traceback.format_exc())
|
||||
return
|
||||
keyboardList = []
|
||||
if os.path.exists(f"{programPath}/list/KeyList.json"):
|
||||
try:
|
||||
with open(f"{programPath}/list/KeyList.json") as file:
|
||||
keyboardList = json.loads(file.read())
|
||||
except:
|
||||
traceback.print_exc()
|
||||
QtWidgets.QMessageBox.critical(window, "错误", traceback.format_exc())
|
||||
return
|
||||
print(keyboardList)
|
||||
addList = []
|
||||
addList = keyListDebianMap[ui.wineKeyboardChoose.currentIndex()][:]
|
||||
print(keyListDebianMap)
|
||||
print(addList)
|
||||
addList.append(ui.localKey.text()[0])
|
||||
print(1, addList)
|
||||
addList.append(f"'{programPath}/sendkeys.sh' {ui.wineKey.text()[0]} '{ui.exeName.text()}' {ui.wineKeyboardChoose.currentIndex()}")
|
||||
print(2, addList)
|
||||
print(addList)
|
||||
try:
|
||||
keyboardList[int(sys.argv[1])] = addList
|
||||
except:
|
||||
keyboardList.append(addList)
|
||||
try:
|
||||
with open(f"{programPath}/list/KeyList.json", "w") as file:
|
||||
file.write(json.dumps(keyboardList))
|
||||
QtWidgets.QMessageBox.information(window, "提示", "添加成功!")
|
||||
except:
|
||||
traceback.print_exc()
|
||||
QtWidgets.QMessageBox.critical(window, "错误", traceback.format_exc())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
@@ -58,13 +95,34 @@ if __name__ == "__main__":
|
||||
window = QtWidgets.QMainWindow()
|
||||
ui = Ui_MainWindow()
|
||||
ui.setupUi(window)
|
||||
# 添加选项
|
||||
ui.localKeyboardChoose.addItems(keyList)
|
||||
ui.wineKeyboardChoose.addItems(keyList)
|
||||
# 读取程序参数
|
||||
try:
|
||||
with open(f"{programPath}/list/KeyList.json") as file:
|
||||
keyboardList = json.loads(file.read())
|
||||
choice = keyboardList[int(sys.argv[1])]
|
||||
ui.localKeyboardChoose.setCurrentIndex(keyListDebianMap.index(choice[:-2]))
|
||||
ui.localKey.setText(choice[-2])
|
||||
# 解析命令
|
||||
command = choice[-1]
|
||||
# 筛掉路径
|
||||
command = command[command[1:].index("'") + 2:].strip()
|
||||
# 筛出其中一个快捷键
|
||||
ui.wineKey.setText(command[command.index(" ") - 1])
|
||||
command = command[command.index(" ") + 2:]
|
||||
# 读 exe
|
||||
ui.exeName.setText(command[:command.index("'")])
|
||||
command = command[command.index("'") + 1: ].strip()
|
||||
# 读最后的快捷键
|
||||
ui.wineKeyboardChoose.setCurrentIndex(int(command))
|
||||
except:
|
||||
pass
|
||||
# 连接槽
|
||||
ui.addButton.clicked.connect(Click.AddButton)
|
||||
ui.localKeyboardChoose.currentIndexChanged.connect(Click.LocalValueChange)
|
||||
ui.localKey.textChanged.connect(Click.LocalKeyChange)
|
||||
window.show()
|
||||
# 添加选项
|
||||
ui.localKeyboardChoose.addItems(keyList)
|
||||
ui.wineKeyboardChoose.addItems(keyList)
|
||||
#threading.Thread(target=Check.CheckThreading).start()
|
||||
sys.exit(app.exec_())
|
||||
Reference in New Issue
Block a user