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,24 +590,20 @@ class TextEdit(PlainTextEdit):
|
|||||||
num += 1
|
num += 1
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
def event(self, ev):
|
def override_shortcut(self, ev):
|
||||||
if ev.type() == ev.ToolTip:
|
# Let the global cut/copy/paste/undo/redo shortcuts work, this avoids the nbsp
|
||||||
self.show_tooltip(ev)
|
# problem as well, since they use the overridden copy() method
|
||||||
|
# instead of the one from Qt, and allows proper customization
|
||||||
|
# of the shortcuts
|
||||||
|
if ev in (QKeySequence.Copy, QKeySequence.Cut, QKeySequence.Paste, QKeySequence.Undo, QKeySequence.Redo):
|
||||||
|
ev.ignore()
|
||||||
return True
|
return True
|
||||||
if ev.type() == ev.ShortcutOverride:
|
# This is used to convert typed hex codes into unicode
|
||||||
# Let the global cut/copy/paste/undo/redo shortcuts work, this avoids the nbsp
|
# characters
|
||||||
# problem as well, since they use the overridden copy() method
|
if ev.key() == Qt.Key_X and ev.modifiers() == Qt.AltModifier:
|
||||||
# instead of the one from Qt, and allows proper customization
|
ev.accept()
|
||||||
# of the shortcuts
|
return True
|
||||||
if ev in (QKeySequence.Copy, QKeySequence.Cut, QKeySequence.Paste, QKeySequence.Undo, QKeySequence.Redo):
|
return PlainTextEdit.override_shortcut(self, ev)
|
||||||
ev.ignore()
|
|
||||||
return True
|
|
||||||
# This is used to convert typed hex codes into unicode
|
|
||||||
# characters
|
|
||||||
if ev.key() == Qt.Key_X and ev.modifiers() == Qt.AltModifier:
|
|
||||||
ev.accept()
|
|
||||||
return True
|
|
||||||
return QPlainTextEdit.event(self, ev)
|
|
||||||
|
|
||||||
def text_for_range(self, block, r):
|
def text_for_range(self, block, r):
|
||||||
c = self.textCursor()
|
c = self.textCursor()
|
||||||
|
@ -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__':
|
||||||
|
Loading…
x
Reference in New Issue
Block a user