Skip to content

Commit

Permalink
Use pyautogui only for platforms != from win32 because is too slow.
Browse files Browse the repository at this point in the history
  • Loading branch information
tov101 committed Jul 22, 2024
1 parent 26337db commit d8ae470
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
3 changes: 2 additions & 1 deletion run_black_and_ruff.bat
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pip install -U black ruff && ^
black --config pyproject.toml . && ^
black --config pyproject.toml ./src && ^
black --config pyproject.toml ./test && ^
black --config pyproject.toml asammdf.spec && ^
black --config pyproject.toml setup.py && ^
ruff check --fix ./src && ^
Expand Down
35 changes: 20 additions & 15 deletions test/asammdf/gui/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class DragAndDrop
from unittest import mock

import numpy as np
import pyautogui
import pyqtgraph
from PySide6 import QtCore, QtGui, QtTest, QtWidgets

Expand Down Expand Up @@ -291,35 +292,39 @@ def __init__(self, src_widget, dst_widget, src_pos, dst_pos):

while t_move.is_alive():
QtWidgets.QApplication.instance().processEvents()
time.sleep(0.01)
QtWidgets.QApplication.instance().processEvents()
time.sleep(0.001)

time.sleep(0.05)
QtWidgets.QApplication.instance().processEvents()

if sys.platform == "win32":

def dnd_worker(start, end):
x_vals = np.linspace(start.x(), end.x(), 10)
y_vals = np.linspace(start.y(), end.y(), len(x_vals))
print(x_vals, y_vals)
def dnd_worker(start, end):
x_vals = np.linspace(start.x(), end.x(), 10)
y_vals = np.linspace(start.y(), end.y(), len(x_vals))

# Move the mouse to the starting position
if sys.platform == "win32":
win32api.SetCursorPos((start.x(), start.y()))

# Perform left mouse button down event
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, start.x(), start.y(), 0, 0)

# Move the mouse to the ending position
for x, y in zip(x_vals, y_vals):
win32api.SetCursorPos((int(x), int(y)))
time.sleep(0.01)

# Perform left mouse button up event
win32api.SetCursorPos((end.x(), end.y()))
time.sleep(0.01)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, end.x(), end.y(), 0, 0)
time.sleep(0.1)

else:

def dnd_worker(start, end):
pass
else:
# Move the mouse to the starting position
pyautogui.moveTo(start.x(), start.y())
# Perform left mouse button down event
pyautogui.mouseDown()
# Move the mouse to the ending position
for x, y in zip(x_vals, y_vals):
pyautogui.moveTo(int(x), int(y))
time.sleep(0.001)
# Perform left mouse button up event
pyautogui.moveTo(end.x(), end.y())
pyautogui.mouseUp()
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ deps =
-rtest/requirements.txt
coverage
pytest-timeout
pyautogui; sys_platform != "win32"
pywin32; sys_platform == "win32"
passenv = DISPLAY,XAUTHORITY
setenv =
Expand Down Expand Up @@ -46,4 +47,4 @@ python =
python_classes =
testpaths = test
addopts = -vv --color=yes --code-highlight=yes --junitxml=test-reports/unit-tests-results.xml
timeout = 600
timeout = 600

0 comments on commit d8ae470

Please sign in to comment.