Use QInputMethodEvent to make charmap work with all widgets

This commit is contained in:
Kovid Goyal 2014-01-08 11:28:05 +05:30
parent ab7b6e1e99
commit e0bf82e6e0

View File

@ -15,7 +15,7 @@ from PyQt4.Qt import (
QAbstractItemModel, QModelIndex, Qt, QVariant, pyqtSignal, QApplication, QAbstractItemModel, QModelIndex, Qt, QVariant, pyqtSignal, QApplication,
QTreeView, QSize, QGridLayout, QAbstractListModel, QListView, QPen, QMenu, QTreeView, QSize, QGridLayout, QAbstractListModel, QListView, QPen, QMenu,
QStyledItemDelegate, QSplitter, QLabel, QSizePolicy, QIcon, QMimeData, QStyledItemDelegate, QSplitter, QLabel, QSizePolicy, QIcon, QMimeData,
QPushButton, QToolButton) QPushButton, QToolButton, QInputMethodEvent)
from calibre.constants import ispy3, plugins, cache_dir from calibre.constants import ispy3, plugins, cache_dir
from calibre.gui2 import NONE from calibre.gui2 import NONE
@ -817,17 +817,14 @@ class CharSelect(Dialog):
return return
self.parent().activateWindow() self.parent().activateWindow()
w = self.parent().focusWidget() w = self.parent().focusWidget()
if hasattr(w, 'textCursor'): e = QInputMethodEvent('', [])
cr = w.textCursor() e.setCommitString(c)
cr.insertText(c) if hasattr(w, 'no_popup'):
w.setTextCursor(cr) oval = w.no_popup
elif hasattr(w, 'insert'): w.no_popup = True
if hasattr(w, 'no_popup'): QApplication.sendEvent(w, e)
oval = w.no_popup if hasattr(w, 'no_popup'):
w.no_popup = True w.no_popup = oval
w.insert(c)
if hasattr(w, 'no_popup'):
w.no_popup = oval
if __name__ == '__main__': if __name__ == '__main__':
app = QApplication([]) app = QApplication([])