Edit Book: On windows do not trigger shortcuts when using the right Alt (AltGr) key. This allows it to be used for entering special characters instead. Fixes #1627487 [bug in Polish mode of Calibre (error in keyboard shortcut)](https://bugs.launchpad.net/calibre/+bug/1627487)

This commit is contained in:
Kovid Goyal 2016-09-26 13:04:36 +05:30
parent 237e4a9455
commit a08356207b
2 changed files with 40 additions and 18 deletions

View File

@ -590,11 +590,7 @@ class TextEdit(PlainTextEdit):
num += 1 num += 1
# }}} # }}}
def event(self, ev): def override_shortcut(self, ev):
if ev.type() == ev.ToolTip:
self.show_tooltip(ev)
return True
if ev.type() == ev.ShortcutOverride:
# Let the global cut/copy/paste/undo/redo shortcuts work, this avoids the nbsp # Let the global cut/copy/paste/undo/redo shortcuts work, this avoids the nbsp
# problem as well, since they use the overridden copy() method # problem as well, since they use the overridden copy() method
# instead of the one from Qt, and allows proper customization # instead of the one from Qt, and allows proper customization
@ -607,7 +603,7 @@ class TextEdit(PlainTextEdit):
if ev.key() == Qt.Key_X and ev.modifiers() == Qt.AltModifier: if ev.key() == Qt.Key_X and ev.modifiers() == Qt.AltModifier:
ev.accept() ev.accept()
return True return True
return QPlainTextEdit.event(self, ev) return PlainTextEdit.override_shortcut(self, ev)
def text_for_range(self, block, r): def text_for_range(self, block, r):
c = self.textCursor() c = self.textCursor()

View File

@ -19,6 +19,7 @@ from PyQt5.Qt import (
QPixmap, QRect, QPlainTextEdit, QMimeData) QPixmap, QRect, QPlainTextEdit, QMimeData)
from calibre import prepare_string_for_xml, human_readable from calibre import prepare_string_for_xml, human_readable
from calibre.constants import iswindows
from calibre.ebooks.oeb.polish.utils import lead_text, guess_type from calibre.ebooks.oeb.polish.utils import lead_text, guess_type
from calibre.gui2 import error_dialog, choose_files, choose_save_file, info_dialog, choose_images from calibre.gui2 import error_dialog, choose_files, choose_save_file, info_dialog, choose_images
from calibre.gui2.tweak_book import tprefs, current_container from calibre.gui2.tweak_book import tprefs, current_container
@ -1118,7 +1119,7 @@ class AddCover(Dialog):
class PlainTextEdit(QPlainTextEdit): # {{{ class PlainTextEdit(QPlainTextEdit): # {{{
''' A class that overrides some methods from QPlainTextEdit to fix handling ''' A class that overrides some methods from QPlainTextEdit to fix handling
of the nbsp unicode character. ''' of the nbsp unicode character and AltGr input method on windows. '''
def __init__(self, parent=None): def __init__(self, parent=None):
QPlainTextEdit.__init__(self, parent) QPlainTextEdit.__init__(self, parent)
@ -1148,6 +1149,31 @@ class PlainTextEdit(QPlainTextEdit): # {{{
ans = QMimeData() ans = QMimeData()
ans.setText(self.selected_text) ans.setText(self.selected_text)
return ans return ans
def show_tooltip(self, ev):
pass
def override_shortcut(self, ev):
if iswindows and self.windows_ignore_altgr_shortcut(ev):
ev.accept()
return True
def windows_ignore_altgr_shortcut(self, ev):
import win32api, win32con
s = win32api.GetAsyncKeyState(win32con.VK_RMENU) & 0xffff # VK_RMENU == R_ALT
return s & 0x8000
def event(self, ev):
et = ev.type()
if et == ev.ToolTip:
self.show_tooltip(ev)
return True
if et == ev.ShortcutOverride:
ret = self.override_shortcut(ev)
if ret:
return True
return QPlainTextEdit.event(self, ev)
# }}} # }}}
if __name__ == '__main__': if __name__ == '__main__':