mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
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:
parent
237e4a9455
commit
a08356207b
@ -590,11 +590,7 @@ class TextEdit(PlainTextEdit):
|
||||
num += 1
|
||||
# }}}
|
||||
|
||||
def event(self, ev):
|
||||
if ev.type() == ev.ToolTip:
|
||||
self.show_tooltip(ev)
|
||||
return True
|
||||
if ev.type() == ev.ShortcutOverride:
|
||||
def override_shortcut(self, ev):
|
||||
# Let the global cut/copy/paste/undo/redo shortcuts work, this avoids the nbsp
|
||||
# problem as well, since they use the overridden copy() method
|
||||
# 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:
|
||||
ev.accept()
|
||||
return True
|
||||
return QPlainTextEdit.event(self, ev)
|
||||
return PlainTextEdit.override_shortcut(self, ev)
|
||||
|
||||
def text_for_range(self, block, r):
|
||||
c = self.textCursor()
|
||||
|
@ -19,6 +19,7 @@ from PyQt5.Qt import (
|
||||
QPixmap, QRect, QPlainTextEdit, QMimeData)
|
||||
|
||||
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.gui2 import error_dialog, choose_files, choose_save_file, info_dialog, choose_images
|
||||
from calibre.gui2.tweak_book import tprefs, current_container
|
||||
@ -1118,7 +1119,7 @@ class AddCover(Dialog):
|
||||
class PlainTextEdit(QPlainTextEdit): # {{{
|
||||
|
||||
''' 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):
|
||||
QPlainTextEdit.__init__(self, parent)
|
||||
@ -1148,6 +1149,31 @@ class PlainTextEdit(QPlainTextEdit): # {{{
|
||||
ans = QMimeData()
|
||||
ans.setText(self.selected_text)
|
||||
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__':
|
||||
|
Loading…
x
Reference in New Issue
Block a user