完成Deepin/UOS快捷键添加功能

This commit is contained in:
gfdgd xi 2022-10-09 21:43:56 +08:00
parent ea7c456620
commit 5e7e567a18
8 changed files with 322 additions and 4 deletions

View File

@ -21,6 +21,15 @@ class Ui_MainWindow(object):
self.addTips = QtWidgets.QLabel(self.centralwidget) self.addTips = QtWidgets.QLabel(self.centralwidget)
self.addTips.setObjectName("addTips") self.addTips.setObjectName("addTips")
self.verticalLayout.addWidget(self.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 = QtWidgets.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout") self.horizontalLayout.setObjectName("horizontalLayout")
self.localTips = QtWidgets.QLabel(self.centralwidget) self.localTips = QtWidgets.QLabel(self.centralwidget)
@ -66,8 +75,9 @@ class Ui_MainWindow(object):
def retranslateUi(self, MainWindow): def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate _translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "添加快捷键")) 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.localTips.setText(_translate("MainWindow", "本地映射:"))
self.addTips_2.setText(_translate("MainWindow", "+")) self.addTips_2.setText(_translate("MainWindow", "+"))
self.wineTips.setText(_translate("MainWindow", "Wine 容器映射内容:")) self.wineTips.setText(_translate("MainWindow", "Wine 容器映射内容:"))

View File

@ -14,18 +14,33 @@
<string>添加快捷键</string> <string>添加快捷键</string>
</property> </property>
<property name="windowIcon"> <property name="windowIcon">
<iconset theme=".."/> <iconset theme="..">
<normaloff>../../../.designer/backup</normaloff>../../../.designer/backup</iconset>
</property> </property>
<widget class="QWidget" name="centralwidget"> <widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<widget class="QLabel" name="addTips"> <widget class="QLabel" name="addTips">
<property name="text"> <property name="text">
<string>暂时只支持 Ctrl+Alt+? 和 Alt+? 的组合 <string>暂时只支持特定组合
文本框内的只能输入单字母</string> 文本框内的只能输入单字母</string>
</property> </property>
</widget> </widget>
</item> </item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="exeNameTips">
<property name="text">
<string>可这执行文件名称:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="exeName"/>
</item>
</layout>
</item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
<item> <item>

View File

@ -18,7 +18,7 @@
<item> <item>
<widget class="QLabel" name="tips"> <widget class="QLabel" name="tips">
<property name="text"> <property name="text">
<string>此工具可以用于设置快捷键到 Wine 容器的映射,以便 Wine 程序可以正常的使用快捷键&lt;br&gt;Deepin/UOS将会使用默认的快捷键服务其它发行版将使用此运行器提供的快捷键服务</string> <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;此工具可以用于设置快捷键到 Wine 容器的映射,以便 Wine 程序可以正常的使用快捷键&lt;br/&gt;Deepin/UOS将会使用默认的快捷键服务其它发行版将使用此运行器提供的快捷键服务&lt;br&gt;Deepin/UOS将只会提供快捷键添加功能请在控制中心进行快捷键的修改管理&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -40,6 +40,13 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item>
<widget class="QPushButton" name="addButton">
<property name="text">
<string>添加</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QPushButton" name="editButton"> <widget class="QPushButton" name="editButton">
<property name="text"> <property name="text">

View File

@ -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", "添加快捷键"))

130
key/UI/KeyAddKeyboardGui.ui Normal file
View File

@ -0,0 +1,130 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>195</height>
</rect>
</property>
<property name="windowTitle">
<string>添加快捷键</string>
</property>
<property name="windowIcon">
<iconset theme="..">
<normaloff>../../../.designer/backup</normaloff>../../../.designer/backup</iconset>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="addTips">
<property name="text">
<string>暂时只支持 Ctrl+Alt+? 和 Alt+? 的组合
文本框内的只能输入单字母</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="exeNameTips">
<property name="text">
<string>可这执行文件名称:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="exeName"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="localTips">
<property name="text">
<string>本地映射:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="localKeyboardChoose"/>
</item>
<item>
<widget class="QLabel" name="addTips_2">
<property name="text">
<string>+</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="localKey"/>
</item>
<item>
<widget class="QLabel" name="wineTips">
<property name="text">
<string>Wine 容器映射内容:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="wineKeyboardChoose"/>
</item>
<item>
<widget class="QLabel" name="addTipsWine">
<property name="text">
<string>+</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="wineKey"/>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="addButton">
<property name="text">
<string>添加快捷键</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
<resources/>
<connections/>
</ui>

Binary file not shown.

70
key/keyboard-add-gui.py Normal file
View File

@ -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 = ["", "<Shift>", "<Control>", "<Alt>", "<Control><Alt>", "<Control><Shift>", "<Alt><Shift>"]
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_())