Skip to content

Commit

Permalink
test: fix simulating mouse click for web engine view
Browse files Browse the repository at this point in the history
  • Loading branch information
minorua committed Nov 11, 2023
1 parent 205af84 commit 62275ea
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
2 changes: 2 additions & 0 deletions q3dwebkitview.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ def __init__(self, parent=None):
QWebPage.__init__(self, parent)
Q3DWebPageCommon.__init__(self)

self.isWebEnginePage = False

def setup(self, settings, wnd=None, exportMode=False):
"""wnd: Q3DWindow or None (off-screen mode)"""
Q3DWebPageCommon.setup(self, settings, wnd, exportMode)
Expand Down
1 change: 0 additions & 1 deletion q3dwebviewcommon.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class Q3DWebPageCommon:

def __init__(self, _=None):

self.isWebEnginePage = False
self.loadedScripts = {}

if DEBUG_MODE == 2:
Expand Down
21 changes: 17 additions & 4 deletions tests/gui/test_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
# begin: 2023-10-16

import os
from PyQt5.QtCore import Qt, QEventLoop, QPoint, QTimer
from PyQt5.QtWidgets import QDialogButtonBox, QMessageBox
from PyQt5.QtCore import Qt, QEvent, QEventLoop, QPoint, QTimer
from PyQt5.QtGui import QMouseEvent
from PyQt5.QtWidgets import QDialogButtonBox, QMessageBox, QWidget
from PyQt5.QtTest import QTest
from qgis.core import QgsProject, QgsRectangle
from qgis.core import QgsApplication, QgsProject, QgsRectangle
from qgis.testing import unittest

from Qgis2threejs.q3dconst import Script
Expand Down Expand Up @@ -58,7 +59,19 @@ def loadSettings(self, filename):
def mouseClick(self, x, y):
self.WND.runScript("showMarker({}, {}, 400)".format(x, y))
self.sleep(500)
QTest.mouseClick(self.WND.ui.webView, Qt.LeftButton, pos=QPoint(x, y))

pos = QPoint(x, y)
w = self.WND.ui.webView

if w._page.isWebEnginePage:
w = w.findChild(QWidget)
press = QMouseEvent(QEvent.MouseButtonPress, pos, Qt.LeftButton, Qt.NoButton, Qt.NoModifier)
release = QMouseEvent(QEvent.MouseButtonRelease, pos, Qt.LeftButton, Qt.NoButton, Qt.NoModifier)

QgsApplication.postEvent(w, press)
QgsApplication.postEvent(w, release)
else:
QTest.mouseClick(w, Qt.LeftButton, pos=pos)

@classmethod
def sleep(cls, msec=500):
Expand Down

0 comments on commit 62275ea

Please sign in to comment.