Restore various missing enum values from various PyQt classes

This commit is contained in:
Kovid Goyal 2021-11-22 08:44:57 +05:30
parent a6b29994e1
commit a484a02dfd
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -7,8 +7,9 @@
# party plugin code, we NEED backward compat.
from qt.core import (
QAction, QDialog, QDrag, QEventLoop, QMenu, QMessageBox, QSinglePointEvent,
QThread, QModelIndex
QAbstractItemView, QAction, QComboBox, QDialog, QDialogButtonBox, QDrag,
QEventLoop, QFrame, QLineEdit, QMenu, QMessageBox, QModelIndex,
QSinglePointEvent, Qt, QThread, QToolButton
)
from calibre_extensions import progress_indicator
@ -25,12 +26,17 @@ QSinglePointEvent.windowPos = lambda self: self.scenePosition()
# Restore the removed exec_ method
QDialog.exec_ = QDialog.exec
QMenu.exec_ = QMenu.exec
QDrag.exec_ = QDrag.exec
QEventLoop.exec_ = QEventLoop.exec
QThread.exec_ = QThread.exec
QMessageBox.exec_ = QMessageBox.exec
def exec_(self):
return self.exec()
QDialog.exec_ = exec_
QMenu.exec_ = exec_
QDrag.exec_ = exec_
QEventLoop.exec_ = exec_
QThread.exec_ = exec_
QMessageBox.exec_ = exec_
# Restore ability to associate a menu with an action
@ -43,5 +49,14 @@ QAction.setMenu = set_menu
QAction.menu = lambda self: progress_indicator.menu_for_action(self)
# Restore QModelIndex child
# Restore QModelIndex::child
QModelIndex.child = lambda self, row, column: self.model().index(row, column, self)
# Restore enum values to various classes
for cls in (Qt, QDialog, QToolButton, QAbstractItemView, QDialogButtonBox, QFrame, QComboBox, QLineEdit, QAction):
for var in tuple(vars(cls).values()):
m = getattr(var, '__members__', {})
for k, v in m.items():
if not hasattr(cls, k):
setattr(cls, k, v)