Skip to content

Commit

Permalink
Merge pull request #486 from bburan/bburan/enaml-qt6-fixes
Browse files Browse the repository at this point in the history
Enaml qt6 fixes (for deprecated methods)
  • Loading branch information
MatthieuDartiailh committed Jun 10, 2022
2 parents 6c02905 + 545713b commit aa77d38
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 22 deletions.
20 changes: 12 additions & 8 deletions enaml/qt/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@

from . import QT_API, PYQT6_API, QT_VERSION

def coerce_to_qevent_type(event_value):
if QT_API in PYQT6_API:
return event_value
return QEvent.Type(event_value)


def global_pos_from_event(event):
if QT_VERSION[0] == "6":
if QT_VERSION[0] == '6':
def global_pos_from_event(event):
return event.globalPosition().toPoint()
else:
else:
def global_pos_from_event(event):
return event.globalPos()


if QT_API in PYQT6_API:
def coerce_to_qevent_type(event_value):
return event_value
else:
def coerce_to_qevent_type(event_value):
return QEvent.Type(event_value)
11 changes: 10 additions & 1 deletion enaml/qt/docking/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
#------------------------------------------------------------------------------
# Copyright (c) 2013-2017, Nucleic Development Team.
# Copyright (c) 2013-2022, Nucleic Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file LICENSE, distributed with this software.
#------------------------------------------------------------------------------
from .. import QT_VERSION


if QT_VERSION[0] == "6":
def hover_event_pos(event):
return event.position().toPoint()
else:
def hover_event_pos(event):
return event.pos()
8 changes: 5 additions & 3 deletions enaml/qt/docking/layout_builder.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#------------------------------------------------------------------------------
# Copyright (c) 2013-2017, Nucleic Development Team.
# Copyright (c) 2013-2022, Nucleic Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
Expand Down Expand Up @@ -43,9 +43,11 @@ def ensure_on_screen(rect):
The potentially adjusted QRect which fits on the screen.
"""
d = QApplication.desktop()
pos = rect.topLeft()
drect = d.screenGeometry(pos)
screen = QApplication.screenAt(pos)
if screen is None:
screen = QApplication.primaryScreen()
drect = screen.availableGeometry()
if not drect.contains(pos):
x = pos.x()
if x < drect.x() or x > drect.right():
Expand Down
6 changes: 4 additions & 2 deletions enaml/qt/docking/q_dock_frame.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#------------------------------------------------------------------------------
# Copyright (c) 2013-2017 Nucleic Development Team.
# Copyright (c) 2013-2022 Nucleic Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
Expand All @@ -10,6 +10,8 @@
from enaml.qt.QtCore import Qt, QEvent, QRect, QSize, QPoint, QMargins, Signal
from enaml.qt.QtWidgets import QApplication, QFrame

from . import hover_event_pos


class QDockFrame(QFrame):
""" A QFrame base class for creating dock frames.
Expand Down Expand Up @@ -267,7 +269,7 @@ def hoverMoveEvent(self, event):
return
if state.resize_border != self.NoBorder:
return
self._refreshCursor(event.pos())
self._refreshCursor(hover_event_pos(event))
event.accept()

def titleBarMousePressEvent(self, event):
Expand Down
5 changes: 3 additions & 2 deletions enaml/qt/docking/q_dock_tab_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from weakref import ref

from enaml.qt.compat import global_pos_from_event
from enaml.qt.QtCore import Qt, QPoint, QSize, QMetaObject, QEvent, QRect
from enaml.qt.QtCore import Qt, QPoint, QPointF, QSize, QMetaObject, QEvent, QRect
from enaml.qt.QtGui import (
QMouseEvent, QResizeEvent, QCursor, QPainter, QPixmap
)
Expand Down Expand Up @@ -335,7 +335,8 @@ def mouseMoveEvent(self, event):
# The button must be Qt.LeftButton, not event.button().
btn = Qt.LeftButton
mod = event.modifiers()
evt = QMouseEvent(QEvent.MouseButtonRelease, pos, btn, btn, mod)
evt = QMouseEvent(QEvent.MouseButtonRelease, QPointF(pos), btn,
btn, mod)
QApplication.sendEvent(self, evt)
container = self.parent().widget(self.currentIndex())
container.untab(global_pos_from_event(event))
Expand Down
7 changes: 5 additions & 2 deletions enaml/qt/docking/q_dock_window.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#------------------------------------------------------------------------------
# Copyright (c) 2013-2017, Nucleic Development Team.
# Copyright (c) 2013-2022, Nucleic Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
Expand All @@ -23,6 +23,8 @@
UNLINKED_BUTTON
)

from . import hover_event_pos


class QDockWindowButtons(QFrame):
""" A custom QFrame which provides the buttons for a QDockWindow.
Expand Down Expand Up @@ -430,7 +432,8 @@ def hoverMoveEvent(self, event):
over the dock window buttons.
"""
if self._title_buttons.geometry().contains(event.pos()):
pos = hover_event_pos(event)
if self._title_buttons.geometry().contains(pos):
self.unsetCursor()
else:
super(QDockWindow, self).hoverMoveEvent(event)
Expand Down
5 changes: 3 additions & 2 deletions enaml/qt/q_popup_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -726,18 +726,19 @@ def mousePressEvent(self, event):
if state.close_on_click:
path = state.path
pos = event.pos()
posf = QPointF(pos)
rect = self.rect()
win_type = self.windowType()
if win_type == Qt.Popup:
if not rect.contains(pos):
super(QPopupView, self).mousePressEvent(event)
else:
path = state.path
if not path.isEmpty() and not path.contains(pos):
if not path.isEmpty() and not path.contains(posf):
event.accept()
self.close()
elif win_type == Qt.ToolTip or win_type == Qt.Window:
if path.isEmpty() or path.contains(pos):
if path.isEmpty() or path.contains(posf):
event.accept()
self.close()

Expand Down
5 changes: 4 additions & 1 deletion enaml/qt/qt_date_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#
# The full license is in the file LICENSE, distributed with this software.
#------------------------------------------------------------------------------
import datetime

from atom.api import Typed

from enaml.widgets.date_selector import ProxyDateSelector
Expand Down Expand Up @@ -52,7 +54,8 @@ def get_date(self):
The current control date as a date object.
"""
return self.widget.date().toPython()
date = self.widget.date()
return datetime.date(date.year(), date.month(), date.day())

def set_minimum(self, date):
""" Set the widget's minimum date.
Expand Down
6 changes: 5 additions & 1 deletion enaml/qt/qt_time_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#
# The full license is in the file LICENSE, distributed with this software.
#------------------------------------------------------------------------------
import datetime

from atom.api import Typed

from enaml.widgets.time_selector import ProxyTimeSelector
Expand Down Expand Up @@ -51,7 +53,9 @@ def get_time(self):
The current control time as a time object.
"""
return self.widget.time().toPython()
time = self.widget.time()
return datetime.time(time.hour(), time.minute(), time.second(),
time.msec() * 1000)

def set_minimum(self, time):
""" Set the widget's minimum time.
Expand Down

0 comments on commit aa77d38

Please sign in to comment.