diff --git "a/assets/\350\267\237\351\232\217\351\274\240\346\240\207\345\205\211\346\240\207\344\275\215\347\275\256\347\232\204\346\226\260\347\211\210\350\276\223\345\205\245\347\212\266\346\200\201\346\217\220\347\244\272\345\212\237\350\203\275.gif" "b/assets/\350\267\237\351\232\217\351\274\240\346\240\207\345\205\211\346\240\207\344\275\215\347\275\256\347\232\204\346\226\260\347\211\210\350\276\223\345\205\245\347\212\266\346\200\201\346\217\220\347\244\272\345\212\237\350\203\275.gif" new file mode 100644 index 0000000..e69c59f Binary files /dev/null and "b/assets/\350\267\237\351\232\217\351\274\240\346\240\207\345\205\211\346\240\207\344\275\215\347\275\256\347\232\204\346\226\260\347\211\210\350\276\223\345\205\245\347\212\266\346\200\201\346\217\220\347\244\272\345\212\237\350\203\275.gif" differ diff --git a/config.py b/config.py index 1919eed..cb6cd7b 100644 --- a/config.py +++ b/config.py @@ -89,6 +89,7 @@ class ClientConfig: # 🤓 Open Home Folder With VSCode # 使用 VSCode 快速打开 CapsWriter 主目录 # 方便调试 + hint_while_recording_at_cursor_position = True class DeepLXConfig: online_translate_port = '1188' diff --git a/readme.md b/readme.md index e38b953..fbcc4db 100644 --- a/readme.md +++ b/readme.md @@ -31,6 +31,10 @@ > ![alt text](assets/将光标选中了中文翻译并替换.gif) +## 跟随鼠标光标位置的新版输入状态提示功能 + +> ![alt text](assets/跟随鼠标光标位置的新版输入状态提示功能.gif) + ## 新版客户端界面: > - 透明;极简 @@ -75,13 +79,14 @@ 12. 支持最小化到系统托盘 13. 已包含所有 Python 环境和 models 模型,解压即用 14. 输入状态提示功能:按下 `Capslock` 键会在光标处提示 [✦ 语音输入中‧‧‧](https://github.com/HaujetZhao/CapsWriter-Offline/issues/52#issuecomment-1905758203);按下 `Shift` 和 `Capslock` 键会在光标处提示 [✦VoiceTrans‧‧‧](https://github.com/HaujetZhao/CapsWriter-Offline/issues/52#issuecomment-1905758203)。注意此功能由 [AutoHotKeyV2](https://www.autohotkey.com/download/) `hint_while_recording.exe` 实现,修改 `config.py` 默认快捷键并**不会**改变提示的按键设置,需要编辑 `hint_while_recording.ahk` 并自行编译替换 `hint_while_recording.exe` -15. 阿拉伯数字化年份功能:默认将\***\*年 大写汉字替换为阿拉伯数字\*\***年,例如一八四八年 替换为 1848 年。通过 `config.py` 中 `Arabic_year` 配置 -16. 启动后自动缩小至托盘功能:默认 服务端 `start_server_gui.exe` 启动后不显示主窗口,自动缩小至托盘;客户端 `start_client_gui.exe` 显示主窗口。通过 `config.py` 中 `shrink_automatically_to_tray` 配置 -17. 禁止多开功能:默认禁止多开,通过 `config.py` 中 `only_run_once` 配置 -18. 一键启动功能:默认服务端 `start_server_gui.exe` 启动后,自动 **🛡️ 以管理员权限** 启动客户端 `start_client_gui_admin.exe`,通过 `config.py` 中 `in_the_meantime_start_the_client_and_run_as_admin` 和 `In_the_meantime_start_the_client_as_admin` 配置 -19. 将文本上传至云剪切板,方便向 ios 设备分享。基于 [cv.j20.cc]() ,一个无依赖即用即走的剪切板。实测 5~1024 字节,不足字节补 `.` ,超出字节 `无效` 。 -20. 将光标选中了中文离线翻译功能:按下 `Ctrl` + `Alt` + `P` ,可以将光标选中了中文离线翻译为英文,并自动覆盖替换原文。通过 `config.py` 中 `offline_translate_and_replace_the_selected_text_shortcut` 配置 -21. 按下键盘上的 `Ctrl` + `Alt` + `[` ,可以将光标选中的 `任意语言` 在线翻译为 `在线翻译目标语言` ,并自动覆盖替换原文。通过 `config.py` 中 `online_translate_and_replace_the_selected_text_shortcut` 和 `online_translate_target_languages` 配置 +15. 输入状态提示功能 V2:按下 `Capslock` 键会在跟随鼠标指针处提示一个小麦克风图标。默认启用,通过 `config.py` 中 `hint_while_recording_at_cursor_position` 配置 +16. 阿拉伯数字化年份功能:默认将\***\*年 大写汉字替换为阿拉伯数字\*\***年,例如一八四八年 替换为 1848 年。通过 `config.py` 中 `Arabic_year` 配置 +17. 启动后自动缩小至托盘功能:默认 服务端 `start_server_gui.exe` 启动后不显示主窗口,自动缩小至托盘;客户端 `start_client_gui.exe` 显示主窗口。通过 `config.py` 中 `shrink_automatically_to_tray` 配置 +18. 禁止多开功能:默认禁止多开,通过 `config.py` 中 `only_run_once` 配置 +19. 一键启动功能:默认服务端 `start_server_gui.exe` 启动后,自动 **🛡️ 以管理员权限** 启动客户端 `start_client_gui_admin.exe`,通过 `config.py` 中 `in_the_meantime_start_the_client_and_run_as_admin` 和 `In_the_meantime_start_the_client_as_admin` 配置 +20. 将文本上传至云剪切板,方便向 ios 设备分享。基于 [cv.j20.cc]() ,一个无依赖即用即走的剪切板。实测 5~1024 字节,不足字节补 `.` ,超出字节 `无效` 。 +21. 将光标选中了中文离线翻译功能:按下 `Ctrl` + `Alt` + `P` ,可以将光标选中了中文离线翻译为英文,并自动覆盖替换原文。通过 `config.py` 中 `offline_translate_and_replace_the_selected_text_shortcut` 配置 +22. 按下键盘上的 `Ctrl` + `Alt` + `[` ,可以将光标选中的 `任意语言` 在线翻译为 `在线翻译目标语言` ,并自动覆盖替换原文。通过 `config.py` 中 `online_translate_and_replace_the_selected_text_shortcut` 和 `online_translate_target_languages` 配置 # ⬇️ 下载地址 diff --git a/start_client_gui.py b/start_client_gui.py index 880ae3f..53e28a0 100644 --- a/start_client_gui.py +++ b/start_client_gui.py @@ -18,6 +18,8 @@ QLabel) from PySide6.QtGui import (QIcon, QAction, + QPalette, + QColor, QFont, QWheelEvent) from PySide6.QtCore import (Qt, @@ -27,6 +29,30 @@ from config import ClientConfig as Config from util.check_process import check_process from util.cloud_clipboard_show_qrcode import CloudClipboardShowQRCode +import win32api +import keyboard +class Hint_While_Recording_At_Cursor_Position(QLabel): + def __init__(self): + super().__init__() + self.setWindowFlags(Qt.ToolTip | Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint) + self.setVisible(False) # 初始时隐藏标签 + + # 创建一个定时器来定期更新鼠标位置 + self.timer = QTimer(self) + self.timer.timeout.connect(self.update_tooltip_position) + self.timer.start(100) # 每100毫秒更新一次 + + def update_tooltip_position(self): + # 使用pywin32获取全局鼠标位置 + x, y = win32api.GetCursorPos() + # 更新标签的位置和文本 + self.move(x+20, y+20) + if keyboard.is_pressed(Config.speech_recognition_shortcut): + self.setText(chr(0xF8B1)) + self.setVisible(True) + else: + self.setVisible(False) + class GUI(QMainWindow): def __init__(self): @@ -490,7 +516,10 @@ def start_client_gui(): raise Exception("已经有一个客户端在运行了!(用户配置了 只允许运行一次,禁止多开;而且检测到 pythonw_CapsWriter_Client.exe 进程已在运行。如果你确定需要启动多个客户端同时运行,请先修改 config.py class ClientConfig: Only_run_once = False 。)") if not check_process('hint_while_recording.exe'): subprocess.Popen(['hint_while_recording.exe'], creationflags=subprocess.CREATE_NO_WINDOW) - app = QApplication([]) + if Config.hint_while_recording_at_cursor_position: + app = QApplication(sys.argv) + tooltip = Hint_While_Recording_At_Cursor_Position() + tooltip.show() apply_stylesheet(app, theme='dark_teal.xml', css_file='util\\client_gui_theme_custom.css') global gui gui = GUI() diff --git a/util/client_gui_theme_custom.css b/util/client_gui_theme_custom.css index dacc88a..750176b 100644 --- a/util/client_gui_theme_custom.css +++ b/util/client_gui_theme_custom.css @@ -18,6 +18,7 @@ QTextEdit {{ }} QLabel {{ + font-family: "Segoe MDL2 Assets"; color: {QTMATERIAL_PRIMARYCOLOR}; font-size: 14px; }} \ No newline at end of file diff --git a/util/hint_while_recording_at_cursor_position_test.py b/util/hint_while_recording_at_cursor_position_test.py new file mode 100644 index 0000000..8c133d2 --- /dev/null +++ b/util/hint_while_recording_at_cursor_position_test.py @@ -0,0 +1,41 @@ +import sys +import win32api +from PySide6.QtWidgets import QApplication, QLabel +from PySide6.QtCore import QTimer, QPoint, Qt +from PySide6.QtGui import QPalette, QColor, QFont +from config import ClientConfig as Config +import keyboard + +class Hint_While_Recording_At_Cursor_Position(QLabel): + def __init__(self): + super().__init__() + self.setWindowFlags(Qt.ToolTip | Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint) + font = QFont("Segoe MDL2 Assets", 14) + self.setFont(font) + palette = self.palette() + palette.setColor(QPalette.Window, QColor("#212121")) # 设置背景颜色 + palette.setColor(QPalette.WindowText, QColor("#00B294")) # 设置文本颜色 + self.setPalette(palette) + self.setVisible(False) # 初始时隐藏标签 + + # 创建一个定时器来定期更新鼠标位置 + self.timer = QTimer(self) + self.timer.timeout.connect(self.update_tooltip_position) + self.timer.start(100) # 每100毫秒更新一次 + + def update_tooltip_position(self): + # 使用pywin32获取全局鼠标位置 + x, y = win32api.GetCursorPos() + # 更新标签的位置和文本 + self.move(x+20, y+20) + if keyboard.is_pressed(Config.speech_recognition_shortcut): + self.setText(chr(0xF8B1)) + self.setVisible(True) + else: + self.setVisible(False) + +if __name__ == "__main__": + app = QApplication(sys.argv) + tooltip = Hint_While_Recording_At_Cursor_Position() + tooltip.show() # 显示标签 + sys.exit(app.exec())