Skip to content

Commit

Permalink
新增 可选 跟随鼠标光标位置的新版输入状态提示功能
Browse files Browse the repository at this point in the history
  • Loading branch information
H1DDENADM1N committed Mar 6, 2024
1 parent b0e224c commit 873b3fc
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 8 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
19 changes: 12 additions & 7 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@

> ![alt text](assets/将光标选中了中文翻译并替换.gif)
## 跟随鼠标光标位置的新版输入状态提示功能

> ![alt text](assets/跟随鼠标光标位置的新版输入状态提示功能.gif)
## 新版客户端界面:

> - 透明;极简
Expand Down Expand Up @@ -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` 配置

# ⬇️ 下载地址

Expand Down
31 changes: 30 additions & 1 deletion start_client_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
QLabel)
from PySide6.QtGui import (QIcon,
QAction,
QPalette,
QColor,
QFont,
QWheelEvent)
from PySide6.QtCore import (Qt,
Expand All @@ -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):
Expand Down Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions util/client_gui_theme_custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ QTextEdit {{
}}

QLabel {{
font-family: "Segoe MDL2 Assets";
color: {QTMATERIAL_PRIMARYCOLOR};
font-size: 14px;
}}
41 changes: 41 additions & 0 deletions util/hint_while_recording_at_cursor_position_test.py
Original file line number Diff line number Diff line change
@@ -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())

0 comments on commit 873b3fc

Please sign in to comment.