Skip to content

Commit

Permalink
Merge pull request #491 from MatthieuDartiailh/qt-tests
Browse files Browse the repository at this point in the history
Fix drag and drop on Qt6
  • Loading branch information
MatthieuDartiailh committed Jun 10, 2022
2 parents aa77d38 + eb24c5e commit d719f11
Show file tree
Hide file tree
Showing 37 changed files with 819 additions and 355 deletions.
13 changes: 8 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,16 @@ jobs:
# QT_DEBUG_PLUGINS=1)
run: |
sudo apt-get update --fix-missing
sudo apt-get install libfontconfig1-dev libfreetype6-dev libx11-dev libxext-dev libxfixes-dev libxi-dev libxrender-dev libxcb1-dev libx11-xcb-dev libxcb-glx0-dev libxcb-keysyms1-dev libxcb-image0-dev libxcb-shm0-dev libxcb-icccm4-dev libxcb-sync0-dev libxcb-xfixes0-dev libxcb-shape0-dev libxcb-randr0-dev libxcb-render-util0-dev libxcb-xinerama0-dev libxcb-xkb-dev libxkbcommon-x11-dev libxcb-xtest0-dev libegl1-mesa xvfb fluxbox --fix-missing
sudo apt-get install -y libfontconfig1-dev libfreetype6-dev libx11-dev libxext-dev libxfixes-dev libxi-dev libxrender-dev libxcb1-dev libx11-xcb-dev libxcb-glx0-dev libxcb-keysyms1-dev libxcb-image0-dev libxcb-shm0-dev libxcb-icccm4-dev libxcb-sync0-dev libxcb-xfixes0-dev libxcb-shape0-dev libxcb-randr0-dev libxcb-render-util0-dev libxcb-xinerama0-dev libxcb-xkb-dev libxkbcommon-x11-dev libxcb-xtest0-dev libegl1-mesa xvfb --fix-missing
sudo apt-get install -y herbstluftwm scrot
- name: Checkout branch
uses: actions/checkout@v2
- name: Get history and tags for SCM versioning to work
run: |
git fetch --prune --unshallow
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand All @@ -77,20 +78,22 @@ jobs:
if: matrix.python-version == '3.9' && matrix.qt-binding == 'pyqt' && matrix.qt-version== 6
run: |
pip install PyQt6-QScintilla
- name: Install pytest
- name: Install test requirements
run: |
pip install pytest pytest-cov pytest-qt
pip install -r test_requirements.txt
- name: Run tests (Windows, Mac)
if: matrix.os != 'ubuntu-latest'
run: python -X dev -m pytest tests --cov enaml --cov-report xml -rs
- name: Run tests (Linux)
if: matrix.os == 'ubuntu-latest'
shell: bash -l {0}
run: |
pip uninstall python3-xlib --yes
pip install python-xlib
export DISPLAY=:99.0
/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -screen 0 1920x1200x24 -ac +extension GLX +render -noreset
sleep 3
exec /usr/bin/startfluxbox &
herbstluftwm &
sleep 1
python -X dev -m pytest tests --cov enaml --cov-report xml -rs
- name: Generate C++ coverage reports
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
git fetch --prune --unshallow
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v3
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
git fetch --prune --unshallow
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
- name: Setup Python
uses: actions/setup-python@v2
uses: actions/setup-python@v3
with:
python-version: '3.9'
- name: Build sdist
Expand Down Expand Up @@ -54,7 +54,7 @@ jobs:
git fetch --prune --unshallow
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
- name: Setup Python
uses: actions/setup-python@v2
uses: actions/setup-python@v3
with:
python-version: '3.9'
- name: Install cibuildwheel
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@

lextab*.py
parsetab*.py
version.py
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = [
'sphinx.ext.napoleon',
'sphinx.ext.autodoc',
'sphinx.ext.doctest',
'sphinx.ext.intersphinx',
Expand All @@ -51,7 +52,6 @@
'sphinx.ext.graphviz',
'sphinx.ext.inheritance_diagram',
'sphinx.ext.autosummary',
'sphinx.ext.napoleon'
]

# Add any paths that contain templates here, relative to this directory.
Expand Down
16 changes: 11 additions & 5 deletions enaml/layout/constrainable.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,32 +88,38 @@ class ConstrainableMixin(Atom):
v_center = Constant()

#: How strongly a widget hugs it's width hint. This is equivalent
#: to the constraint:
#: to the constraint::
#:
#: (width == hint) | hug_width
hug_width = PolicyEnum('strong')

#: How strongly a widget hugs it's height hint. This is equivalent
#: to the constraint:
#: to the constraint::
#:
#: (height == hint) | hug_height
hug_height = PolicyEnum('strong')

#: How strongly a widget resists clipping its width hint. This is
#: equivalent to the constraint:
#:
#: (width >= hint) | resist_width
resist_width = PolicyEnum('strong')

#: How strongly a widget resists clipping its height hint. This is
#: iequivalent to the constraint:
#: equivalent to the constraint::
#:
#: (height >= hint) | resist_height
resist_height = PolicyEnum('strong')

#: How strongly a widget resists expanding its width hint. This is
#: equivalent to the constraint:
#: equivalent to the constraint::
#:
#: (width <= hint) | limit_width
limit_width = PolicyEnum('ignore')

#: How strongly a widget resists expanding its height hint. This is
#: equivalent to the constraint:
#: equivalent to the constraint::
#:
#: (height <= hint) | limit_height
limit_height = PolicyEnum('ignore')

Expand Down
72 changes: 42 additions & 30 deletions enaml/qt/docking/dock_images/guide_render.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
""" An extremely hack script that was used to render the dock guide icons.
"""
from enaml.qt.QtCore import *
from enaml.qt.QtGui import *
from enaml.qt.QtCore import QRect, QRectF, QSize, Qt
from enaml.qt.QtGui import (
QBrush,
QColor,
QGradient,
QGuiApplication,
QImage,
QLinearGradient,
QPainter,
QPainterPath,
QPen,
)


class GuidePad(object):
Expand Down Expand Up @@ -122,7 +132,7 @@ def paint(self, painter):
painter.translate(rect.x(), rect.y())

# Draw the background
painter.setOpacity(1.0)#self._opacity)
painter.setOpacity(1.0) # self._opacity)
painter.fillPath(self._path, self._brush)
painter.setPen(self._pen)
painter.drawPath(self._path)
Expand All @@ -133,46 +143,46 @@ def paint(self, painter):
position = self._position
if position == self.TopPosition:
width = rect.width() - 8
height = rect.height() / 2 - 4
height = rect.height() // 2 - 4
painter.drawRect(QRect(4, 4, width, height))
painter.fillRect(QRect(5, 5, width - 1, 3), color)
painter.fillRect(QRect(5, 8, width - 1, height - 4), fill_brush)
painter.setRenderHint(QPainter.Antialiasing)
w = rect.width() / 2 + 5
w = rect.width() // 2 + 5
h = rect.height() - 5
painter.translate(w, h)
painter.rotate(180)
painter.fillPath(self._tri_path, color)
elif position == self.BottomPosition:
width = rect.width() - 8
height = rect.height() / 2 - 4
height = rect.height() // 2 - 4
painter.drawRect(QRect(4, height + 4, width, height))
painter.fillRect(QRect(5, height + 5, width - 1, 3), color)
painter.fillRect(QRect(5, height + 8, width - 1, height - 4), fill_brush)
painter.setRenderHint(QPainter.Antialiasing)
w = rect.width() / 2 - 4
w = rect.width() // 2 - 4
painter.translate(w, 6)
painter.fillPath(self._tri_path, color)
elif position == self.LeftPosition:
width = rect.width() / 2 - 4
width = rect.width() // 2 - 4
height = rect.height() - 8
painter.drawRect(QRect(4, 4, width, height))
painter.fillRect(QRect(5, 5, width - 1, 3), color)
painter.fillRect(QRect(5, 8, width - 1, height - 4), fill_brush)
painter.setRenderHint(QPainter.Antialiasing)
w = rect.width() - 5
h = rect.height() / 2 - 4
h = rect.height() // 2 - 4
painter.translate(w, h)
painter.rotate(90)
painter.fillPath(self._tri_path, color)
elif position == self.RightPosition:
width = rect.width() / 2 - 4
width = rect.width() // 2 - 4
height = rect.height() - 8
painter.drawRect(QRect(width + 4, 4, width, height))
painter.fillRect(QRect(width + 5, 5, width - 1, 3), color)
painter.fillRect(QRect(width + 5, 8, width - 1, height - 4), fill_brush)
painter.setRenderHint(QPainter.Antialiasing)
h = rect.height() / 2 + 5
h = rect.height() // 2 + 5
painter.translate(6, h)
painter.rotate(-90)
painter.fillPath(self._tri_path, color)
Expand Down Expand Up @@ -205,7 +215,7 @@ def paint(self, painter):
height = rect.height() - 8
painter.drawRect(QRect(4, 4, width, height))
painter.fillRect(QRect(5, 5, width - 1, 3), color)
painter.fillRect(QRect(5, 8, width - 1, height / 2 - 2), fill_brush)
painter.fillRect(QRect(5, 8, width - 1, height // 2 - 2), fill_brush)
pen = QPen(color, 0, Qt.DotLine)
pen.setDashPattern([1, 1])
painter.setPen(pen)
Expand Down Expand Up @@ -239,7 +249,7 @@ def paint(self, painter):
height = rect.height() - 8
painter.drawRect(QRect(4, 4, width, height))
painter.fillRect(QRect(5, 5, width - 1, 3), color)
w = width / 2
w = width // 2
h = height - 4
painter.fillRect(QRect(5 + w, 8, w - 1, h), fill_brush)
pen = QPen(color, 0, Qt.DotLine)
Expand All @@ -252,7 +262,7 @@ def paint(self, painter):
height = rect.height() - 8
painter.drawRect(QRect(4, 4, width, height))
painter.fillRect(QRect(5, 5, width - 1, 3), color)
w = width / 4
w = width // 4
h = height - 4
painter.fillRect(QRect(6 + w, 8, 2 * w - 1, h), fill_brush)
pen = QPen(color, 0, Qt.DotLine)
Expand All @@ -266,7 +276,7 @@ def paint(self, painter):
height = rect.height() - 8
painter.drawRect(QRect(4, 4, width, height))
painter.fillRect(QRect(5, 5, width - 1, 3), color)
h = height / 4
h = height // 4
painter.fillRect(QRect(5, 8 + h, width - 1, 2 * h - 2), fill_brush)
pen = QPen(color, 0, Qt.DotLine)
pen.setDashPattern([1, 1])
Expand Down Expand Up @@ -412,20 +422,22 @@ def render_background(painter):
painter.fillRect(QRect(0, 0, 129, 129), brush)


app = QApplication([])
app = QGuiApplication([])
image = QImage(QSize(128, 128), QImage.Format_ARGB32_Premultiplied)
image.fill(0)
painter = QPainter(image)
#render_box(painter)
#render_cross(painter)
#render_cross_ex(painter)
#render_vbar(painter)
#render_hbar(painter)
render_background(painter)
#pad = GuidePad(QRect(0, 0, 30, 30), GuidePad.CenterQuads)
#pad.paint(painter)
painter.end()

import os
path = os.path.join(os.path.dirname(__file__), 'background.png')
image.save(path)

for func in (
render_box,
render_cross,
render_cross_ex,
render_vbar,
render_hbar,
render_background,
):
painter = QPainter(image)
func(painter)
painter.end()

# import os
# path = os.path.join(os.path.dirname(__file__), 'background.png')
# image.save(path)
11 changes: 9 additions & 2 deletions enaml/qt/qt_datetime_selector.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#------------------------------------------------------------------------------
# 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.
#------------------------------------------------------------------------------
import datetime

from atom.api import Typed

from enaml.widgets.datetime_selector import ProxyDatetimeSelector
Expand Down Expand Up @@ -52,7 +54,12 @@ def get_datetime(self):
The current control datetime as a datetime object.
"""
return self.widget.dateTime().toPython()
date_time = self.widget.dateTime()
d = date_time.date()
t = date_time.time()
return datetime.datetime(
d.year(), d.month(), d.day(), t.hour(), t.minute(), t.second()
)

def set_minimum(self, datetime):
""" Set the widget's minimum datetime.
Expand Down
11 changes: 5 additions & 6 deletions enaml/qt/qt_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,19 +344,18 @@ def do_drag(self):
qimg = get_cached_qimage(drag_data.image)
qdrag.setPixmap(QPixmap.fromImage(qimg))
else:
if __version_info__ < (5, ):
qdrag.setPixmap(QPixmap.grabWidget(widget))
else:
qdrag.setPixmap(widget.grab())
qdrag.setPixmap(widget.grab())
if drag_data.hotspot:
qdrag.setHotSpot(QPoint(*drag_data.hotspot))
else:
cursor_position = widget.mapFromGlobal(QCursor.pos())
qdrag.setHotSpot(cursor_position)
default = Qt.DropAction(drag_data.default_drop_action)
supported = Qt.DropActions(drag_data.supported_actions)
supported = Qt.DropAction(drag_data.supported_actions)
qresult = qdrag.exec_(supported, default)
self.declaration.drag_end(drag_data, DropAction(int(qresult)))
self.declaration.drag_end(
drag_data, DropAction(getattr(qresult, "value", qresult))
)

def dragEnterEvent(self, event):
""" Handle the drag enter event for the widget.
Expand Down
4 changes: 3 additions & 1 deletion enaml/scintilla/scintilla.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,10 @@ class Scintilla(Control):
#: An event emitted when the text is changed.
text_changed = d_(Event(), writable=False)

#: Text Editors expand freely in height and width by default.
#: Text Editors expand freely in width by default.
hug_width = set_default('ignore')

#: Text Editors expand freely in height by default.
hug_height = set_default('ignore')

#: Markers to display.
Expand Down
2 changes: 1 addition & 1 deletion enaml/widgets/bounded_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


class ProxyBoundedDatetime(ProxyControl):
""" The abstract defintion of a proxy BoundedDate object.
""" The abstract definition of a proxy BoundedDate object.
"""
#: A reference to the BoundedDatetime declaration.
Expand Down
2 changes: 1 addition & 1 deletion enaml/widgets/date_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class DateSelector(BoundedDate):
than what is provided by Calendar.
"""
#: A python date format string to format the date for display. If
#: A python date format string to format the date for display.
#: If none is supplied (or is invalid) the system locale setting
#: is used. This may not be supported by all backends.
date_format = d_(Str())
Expand Down
3 changes: 3 additions & 0 deletions releasenotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ Dates are written as DD/MM/YYYY
0.15.1 - unreleased
-------------------
- bump qtpy minimal required version for Qt6 PR #490
- fix drag and drop support under Qt6 PR #491
- fix date and time conversion under Qt6 PR #486
- fix handling of mouse press event by popup views PR #486

0.15.0 - 31/03/2022
-------------------
Expand Down
3 changes: 3 additions & 0 deletions test_requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pytest
pytest-cov
pytest-qt

0 comments on commit d719f11

Please sign in to comment.