bookfere / Ebook-Translator-Calibre-Plugin

A Calibre plugin to translate ebook into a specified language.
https://translator.bookfere.com
GNU General Public License v3.0
1.54k stars 102 forks source link

[功能请求] 为常用按钮添加访问键 #277

Closed Andy-AO closed 2 months ago

Andy-AO commented 2 months ago

常用的按钮「保存」,在很多程序中都有类似Alt+s的访问键,可以用来快速点击,提高效率,而该插件目前没有快速访问键,想要添加一下。

很多GUI用&Save保存(&S)命名就可以自动实现,Qt或许也有类似的功能,如果是这样则并不困难。

Andy-AO commented 2 months ago

@bookfere 对于中文来讲,通常是用保存(&S),使用括号在后面加上快捷键。 可是对于其他表音的文字,该如何处理? 比如

msgid "&Start"
msgstr "Iniciar"

&Iniciar还是Iniciar(&S),我认为应该使用前者,想听听你的看法。

bookfere commented 2 months ago

感谢 PR。是不是使用 QShortcutQKeySequence 这两个类会更灵活些?PyQt 也提供了一些标准快捷键(Standard Shortcuts),可以同时兼容多个平台。这样不需要依赖字符,也不需要更改多个翻译文件,想自定义快捷键也容易改动。

我刚提交了一个简单的实现,把 Alt+S 改成了 Ctrl+S,快捷键没体现在按钮上,只是以工具提示的形式出现。

Andy-AO commented 2 months ago

@bookfere 谢谢

  1. 用下划线体现在按钮文本上,好处是直观,不用去想按钮对应的快捷键到底是哪个,坏处是多语言处理起来麻烦。
  2. 不清楚该功能是否兼容多平台,如果不兼容,还是用Qt的机制比较好。
bookfere commented 2 months ago

QShortcut 文档对助记符号快捷键用法包括兼容问题做了说明。可以看出,唯一的区别是是否为字符显示下划线。Windows 系统可控制是否显示下划线字符,而 macOS 需额外启用这种快捷键,且不会显示下划线字符。

In widget applications, certain widgets can use ‘&’ in front of a character. This will automatically create a mnemonic (a shortcut) for that character, e.g. “E&xit” will create the shortcut Alt+X (use ‘&&’ to display an actual ampersand). The widget might consume and perform an action on a given shortcut. On X11 the ampersand will not be shown and the character will be underlined. On Windows, shortcuts are normally not displayed until the user presses the Alt key, but this is a setting the user can change. On Mac, shortcuts are disabled by default. Call qt_set_sequence_auto_mnemonic() to enable them. However, because mnemonic shortcuts do not fit in with Aqua’s guidelines, Qt will not show the shortcut character underlined.

如果要加这种快捷键而不修改翻译文件可以这样做(即采用第二种方案,不同语言用不同字符应该没必要):

save_button = QPushButton(_('Save') + ' (&S)')

我只记得曾在菜单中用过 Alt+X 这种快捷键,很少在按钮上用。不知道是否是个人习惯,想看看其他人意见。

Andy-AO commented 2 months ago

@bookfere 估计每个系统有不同的习惯,在Windows上,习惯给一些元素添加助记符快捷键,比如选择框、选项卡、菜单、某些按钮。看了一下维基百科,感觉这是Windows的特色功能。

image image image_1354 image_1355 image_1356 image

Andy-AO commented 2 months ago

根据我搜索到的资料,在软件国际化的过程中,助记符应该跟随文本,而快捷键则应该保持不变。

如果语言不使用罗马字符,那么才会在标签后用括号标出助记符。

测试之后发现的确如此,比如Windows上著名的文件管理器,改成法语之后就采用法语首字母作为助记符

image

image

又比如Windows记事本俄语版是这样

image

Andy-AO commented 2 months ago

@bookfere 我的想法是,标准的快捷键对于涵盖在内的场景的确很有帮助,可是对于很多与之无关的按钮还是需要额外处理,这个时候至少在Windows和X11上助记符还是个不错的方案,如果Mac上没有下划线了,那么意义不大,可是支持下无妨,因为如果没有,也不会有什么坏处。

bookfere commented 2 months ago

根据快捷键的介绍和上面的讨论,快捷键不受本地化影响是统一的,而助记符号需要依赖本地化字符。我之前没太弄清楚这两者的关系。给有使用助记符号习惯的系统添加这种用法是合理的。助记符号需要依赖本地化字符,更改语言文件也是合理的。