Merge pull request #1575 from pijyoi/reduce_shim

Reduce number of shims for PyQt6
This commit is contained in:
Ogi Moore 2021-02-19 09:40:06 -08:00 committed by GitHub
commit d9eb8e1afb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 8 deletions

View File

@ -425,18 +425,18 @@ if QT_LIB == PYQT6:
# QKeyEvent::key() returns an int
# so comparison with a Key_* enum will always be False
# here we convert the enum to its int value
for e in QtCore.Qt.Key:
keys = ['Up', 'Down', 'Right', 'Left', 'Return', 'Enter', 'Delete', 'Backspace',
'PageUp', 'PageDown', 'Home', 'End', 'Tab', 'Backtab', 'Escape', 'Space']
for name in keys:
e = getattr(QtCore.Qt.Key, 'Key_' + name)
setattr(QtCore.Qt, e.name, e.value)
# shim the old names for QPointF mouse coords
QtGui.QSinglePointEvent.localPos = lambda o : o.position()
QtGui.QSinglePointEvent.windowPos = lambda o : o.scenePosition()
QtGui.QSinglePointEvent.screenPos = lambda o : o.globalPosition()
QtGui.QDropEvent.posF = lambda o : o.position()
QtWidgets.QApplication.exec_ = QtWidgets.QApplication.exec
QtWidgets.QDialog.exec_ = lambda o : o.exec()
QtGui.QDrag.exec_ = lambda o : o.exec()
# PyQt6 6.0.0 has a bug where it can't handle certain Type values returned
# by the Qt library.

View File

@ -198,7 +198,7 @@ class Dock(QtGui.QWidget, DockDrop):
self.drag.setMimeData(mime)
self.widgetArea.setStyleSheet(self.dragStyle)
self.update()
action = self.drag.exec_()
action = self.drag.exec_() if hasattr(self.drag, 'exec_') else self.drag.exec()
self.updateStyle()
def float(self):

View File

@ -30,9 +30,12 @@ class DockDrop(object):
def dragMoveEvent(self, ev):
#print "drag move"
ld = ev.posF().x()
# QDragMoveEvent inherits QDropEvent which provides posF()
# PyQt6 provides only position()
posF = ev.posF() if hasattr(ev, 'posF') else ev.position()
ld = posF.x()
rd = self.width() - ld
td = ev.posF().y()
td = posF.y()
bd = self.height() - td
mn = min(ld, rd, td, bd)

View File

@ -368,7 +368,7 @@ class TableWidget(QtGui.QTableWidget):
self.contextMenu.popup(ev.globalPos())
def keyPressEvent(self, ev):
if ev.key() == QtCore.Qt.Key_C and ev.modifiers() == QtCore.Qt.ControlModifier:
if ev.matches(QtGui.QKeySequence.Copy):
ev.accept()
self.copySel()
else: