diff --git a/UI/KeyAddKeyboardGui.py b/UI/KeyAddKeyboardGui.py index 14f6eca..5e4e12c 100644 --- a/UI/KeyAddKeyboardGui.py +++ b/UI/KeyAddKeyboardGui.py @@ -21,6 +21,15 @@ class Ui_MainWindow(object): self.addTips = QtWidgets.QLabel(self.centralwidget) self.addTips.setObjectName("addTips") self.verticalLayout.addWidget(self.addTips) + self.horizontalLayout_3 = QtWidgets.QHBoxLayout() + self.horizontalLayout_3.setObjectName("horizontalLayout_3") + self.exeNameTips = QtWidgets.QLabel(self.centralwidget) + self.exeNameTips.setObjectName("exeNameTips") + self.horizontalLayout_3.addWidget(self.exeNameTips) + self.exeName = QtWidgets.QLineEdit(self.centralwidget) + self.exeName.setObjectName("exeName") + self.horizontalLayout_3.addWidget(self.exeName) + self.verticalLayout.addLayout(self.horizontalLayout_3) self.horizontalLayout = QtWidgets.QHBoxLayout() self.horizontalLayout.setObjectName("horizontalLayout") self.localTips = QtWidgets.QLabel(self.centralwidget) @@ -66,8 +75,9 @@ class Ui_MainWindow(object): def retranslateUi(self, MainWindow): _translate = QtCore.QCoreApplication.translate MainWindow.setWindowTitle(_translate("MainWindow", "添加快捷键")) - self.addTips.setText(_translate("MainWindow", "暂时只支持 Ctrl+Alt+? 和 Alt+? 的组合\n" + self.addTips.setText(_translate("MainWindow", "暂时只支持特定组合\n" "文本框内的只能输入单字母")) + self.exeNameTips.setText(_translate("MainWindow", "可这执行文件名称:")) self.localTips.setText(_translate("MainWindow", "本地映射:")) self.addTips_2.setText(_translate("MainWindow", "+")) self.wineTips.setText(_translate("MainWindow", "Wine 容器映射内容:")) diff --git a/UI/KeyAddKeyboardGui.ui b/UI/KeyAddKeyboardGui.ui index 7fc70d7..b6eb4bc 100644 --- a/UI/KeyAddKeyboardGui.ui +++ b/UI/KeyAddKeyboardGui.ui @@ -14,18 +14,33 @@ 添加快捷键 - + + ../../../.designer/backup../../../.designer/backup - 暂时只支持 Ctrl+Alt+? 和 Alt+? 的组合 + 暂时只支持特定组合 文本框内的只能输入单字母 + + + + + + 可这执行文件名称: + + + + + + + + diff --git a/key/UI/KeyAddGui.ui b/key/UI/KeyAddGui.ui index d672769..c024da2 100644 --- a/key/UI/KeyAddGui.ui +++ b/key/UI/KeyAddGui.ui @@ -18,7 +18,7 @@ - 此工具可以用于设置快捷键到 Wine 容器的映射,以便 Wine 程序可以正常的使用快捷键<br>Deepin/UOS将会使用默认的快捷键服务,其它发行版将使用此运行器提供的快捷键服务 + <html><head/><body><p>此工具可以用于设置快捷键到 Wine 容器的映射,以便 Wine 程序可以正常的使用快捷键<br/>Deepin/UOS将会使用默认的快捷键服务,其它发行版将使用此运行器提供的快捷键服务<br>Deepin/UOS将只会提供快捷键添加功能,请在控制中心进行快捷键的修改管理</p></body></html> @@ -40,6 +40,13 @@ + + + + 添加 + + + diff --git a/key/UI/KeyAddKeyboardGui.py b/key/UI/KeyAddKeyboardGui.py new file mode 100644 index 0000000..46041e3 --- /dev/null +++ b/key/UI/KeyAddKeyboardGui.py @@ -0,0 +1,86 @@ +# -*- coding: utf-8 -*- + +# Form implementation generated from reading ui file 'KeyAddKeyboardGui.ui' +# +# Created by: PyQt5 UI code generator 5.11.3 +# +# WARNING! All changes made in this file will be lost! + +from PyQt5 import QtCore, QtGui, QtWidgets + +class Ui_MainWindow(object): + def setupUi(self, MainWindow): + MainWindow.setObjectName("MainWindow") + MainWindow.resize(800, 195) + icon = QtGui.QIcon.fromTheme("..") + MainWindow.setWindowIcon(icon) + self.centralwidget = QtWidgets.QWidget(MainWindow) + self.centralwidget.setObjectName("centralwidget") + self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget) + self.verticalLayout.setObjectName("verticalLayout") + self.addTips = QtWidgets.QLabel(self.centralwidget) + self.addTips.setObjectName("addTips") + self.verticalLayout.addWidget(self.addTips) + self.horizontalLayout_3 = QtWidgets.QHBoxLayout() + self.horizontalLayout_3.setObjectName("horizontalLayout_3") + self.exeNameTips = QtWidgets.QLabel(self.centralwidget) + self.exeNameTips.setObjectName("exeNameTips") + self.horizontalLayout_3.addWidget(self.exeNameTips) + self.exeName = QtWidgets.QLineEdit(self.centralwidget) + self.exeName.setObjectName("exeName") + self.horizontalLayout_3.addWidget(self.exeName) + self.verticalLayout.addLayout(self.horizontalLayout_3) + self.horizontalLayout = QtWidgets.QHBoxLayout() + self.horizontalLayout.setObjectName("horizontalLayout") + self.localTips = QtWidgets.QLabel(self.centralwidget) + self.localTips.setObjectName("localTips") + self.horizontalLayout.addWidget(self.localTips) + self.localKeyboardChoose = QtWidgets.QComboBox(self.centralwidget) + self.localKeyboardChoose.setObjectName("localKeyboardChoose") + self.horizontalLayout.addWidget(self.localKeyboardChoose) + self.addTips_2 = QtWidgets.QLabel(self.centralwidget) + self.addTips_2.setObjectName("addTips_2") + self.horizontalLayout.addWidget(self.addTips_2) + self.localKey = QtWidgets.QLineEdit(self.centralwidget) + self.localKey.setObjectName("localKey") + self.horizontalLayout.addWidget(self.localKey) + self.wineTips = QtWidgets.QLabel(self.centralwidget) + self.wineTips.setObjectName("wineTips") + self.horizontalLayout.addWidget(self.wineTips) + self.wineKeyboardChoose = QtWidgets.QComboBox(self.centralwidget) + self.wineKeyboardChoose.setObjectName("wineKeyboardChoose") + self.horizontalLayout.addWidget(self.wineKeyboardChoose) + self.addTipsWine = QtWidgets.QLabel(self.centralwidget) + self.addTipsWine.setObjectName("addTipsWine") + self.horizontalLayout.addWidget(self.addTipsWine) + self.wineKey = QtWidgets.QLineEdit(self.centralwidget) + self.wineKey.setObjectName("wineKey") + self.horizontalLayout.addWidget(self.wineKey) + self.verticalLayout.addLayout(self.horizontalLayout) + spacerItem = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding) + self.verticalLayout.addItem(spacerItem) + self.horizontalLayout_2 = QtWidgets.QHBoxLayout() + self.horizontalLayout_2.setObjectName("horizontalLayout_2") + spacerItem1 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) + self.horizontalLayout_2.addItem(spacerItem1) + self.addButton = QtWidgets.QPushButton(self.centralwidget) + self.addButton.setObjectName("addButton") + self.horizontalLayout_2.addWidget(self.addButton) + self.verticalLayout.addLayout(self.horizontalLayout_2) + MainWindow.setCentralWidget(self.centralwidget) + + self.retranslateUi(MainWindow) + QtCore.QMetaObject.connectSlotsByName(MainWindow) + + def retranslateUi(self, MainWindow): + _translate = QtCore.QCoreApplication.translate + MainWindow.setWindowTitle(_translate("MainWindow", "添加快捷键")) + self.addTips.setText(_translate("MainWindow", "暂时只支持 Ctrl+Alt+? 和 Alt+? 的组合\n" +"文本框内的只能输入单字母")) + self.exeNameTips.setText(_translate("MainWindow", "可这执行文件名称:")) + self.localTips.setText(_translate("MainWindow", "本地映射:")) + self.addTips_2.setText(_translate("MainWindow", "+")) + self.wineTips.setText(_translate("MainWindow", "Wine 容器映射内容:")) + self.addTipsWine.setText(_translate("MainWindow", "+")) + self.addButton.setText(_translate("MainWindow", "添加快捷键")) + diff --git a/key/UI/KeyAddKeyboardGui.ui b/key/UI/KeyAddKeyboardGui.ui new file mode 100644 index 0000000..847a464 --- /dev/null +++ b/key/UI/KeyAddKeyboardGui.ui @@ -0,0 +1,130 @@ + + + MainWindow + + + + 0 + 0 + 800 + 195 + + + + 添加快捷键 + + + + ../../../.designer/backup../../../.designer/backup + + + + + + + 暂时只支持 Ctrl+Alt+? 和 Alt+? 的组合 +文本框内的只能输入单字母 + + + + + + + + + 可这执行文件名称: + + + + + + + + + + + + + + 本地映射: + + + + + + + + + + + + + + + + + + + + + Wine 容器映射内容: + + + + + + + + + + + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + 添加快捷键 + + + + + + + + + + + diff --git a/key/UI/__pycache__/KeyAddGui.cpython-37.pyc b/key/UI/__pycache__/KeyAddGui.cpython-37.pyc index cb9a5ca..03b5fff 100644 Binary files a/key/UI/__pycache__/KeyAddGui.cpython-37.pyc and b/key/UI/__pycache__/KeyAddGui.cpython-37.pyc differ diff --git a/key/UI/__pycache__/KeyAddKeyboardGui.cpython-37.pyc b/key/UI/__pycache__/KeyAddKeyboardGui.cpython-37.pyc new file mode 100644 index 0000000..2c41e76 Binary files /dev/null and b/key/UI/__pycache__/KeyAddKeyboardGui.cpython-37.pyc differ diff --git a/key/keyboard-add-gui.py b/key/keyboard-add-gui.py new file mode 100644 index 0000000..9219e4e --- /dev/null +++ b/key/keyboard-add-gui.py @@ -0,0 +1,70 @@ +#!/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 dbus +import threading +from UI.KeyAddKeyboardGui import * +import PyQt5.QtWidgets as QtWidgets + +keyList = ["无快捷键", "shift", "ctrl", "alt", "ctrl+alt", "ctrl+shift", "alt+shift"] +keyListDeepinMap = ["", "", "", "", "", "", ""] +keyListDebianMap = [[], ["shift"], ["ctrl"], ["alt"], ["ctrl", "alt"], ["ctrl", "shift"], ["alt", "shift"]] + +class Check: + def VersionCheck(): + try: + bus = dbus.SessionBus() + bus.get_object("com.deepin.daemon.Keybinding", "/com/deepin/daemon/Keybinding").List() + return True + except: + print("无法检测到 Deepin/UOS 快捷键服务") + return False + +class Click: + def LocalValueChange(): + ui.wineKeyboardChoose.setCurrentIndex(ui.localKeyboardChoose.currentIndex()) + + def LocalKeyChange(): + ui.wineKey.setText(ui.localKey.text()) + + def AddButton(): + # 完整性检测 + if ui.exeName.text() == "" or ui.localKey.text() == "" or ui.wineKey.text() == "": + QtWidgets.QMessageBox.critical(window, "错误", "您的信息暂未填写完整") + return + # Deepin/UOS 的情况 + if Check.VersionCheck(): + # 接入 dbus + try: + bus = dbus.SessionBus() + bus.get_object("com.deepin.daemon.Keybinding", "/com/deepin/daemon/Keybinding").Add( + ui.exeName.text(), + f"'{programPath}/sendkeys.sh' {ui.wineKey.text()[0]} '{ui.exeName.text()}' {ui.wineKeyboardChoose.currentIndex()}", + f"{keyListDeepinMap[ui.localKeyboardChoose.currentIndex()]}{ui.localKey.text()[0]}" + ) + QtWidgets.QMessageBox.information(window, "提示", "添加成功!") + except: + traceback.print_exc() + QtWidgets.QMessageBox.critical(window, "错误", traceback.format_exc()) + return + + +if __name__ == "__main__": + app = QtWidgets.QApplication(sys.argv) + window = QtWidgets.QMainWindow() + ui = Ui_MainWindow() + ui.setupUi(window) + # 连接槽 + 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_()) \ No newline at end of file