Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweening not working as expected (win 7, Python) #5

Closed
bleuetnoir opened this issue Nov 17, 2014 · 10 comments
Closed

Tweening not working as expected (win 7, Python) #5

bleuetnoir opened this issue Nov 17, 2014 · 10 comments

Comments

@bleuetnoir
Copy link

Hello,

Tween was not working for me and found that the value tween function was receiving was not within the 0..1 range.

I have not looked further for the why and quickly modified the code to this:

if duration <= MINIMUM_DURATION:
    print("duration check")   
    if moveOrDrag == 'move':
        print("move") 
        platformModule._moveTo(x, y)
    else:
        print("drag") 
        platformModule._dragTo(x, y, button)
    return

tweenfinished = False
starttime = time.time()

while(tweenfinished == False):
    _failSafeCheck()
    elapsedtime = time.time() - starttime

    tweenvalue = min(1, max(0, float(elapsedtime) / float(duration)))

    pointOnLine = tween(tweenvalue) # range 0 / 1
    tweenX, tweenY = getPointOnLine(startx, starty, x, y, pointOnLine)
    tweenX, tweenY = int(tweenX), int(tweenY)

    if moveOrDrag == 'move':
        platformModule._moveTo(tweenX, tweenY)
    else:
        # only OS X needs the drag event specifically
        platformModule._dragTo(tweenX, tweenY, button)
    if (elapsedtime < duration) :
        time.sleep(0.001)
    else :
        tweenfinished = True

# TODO: Test range. Should not be necessary with previous change??        
# Ensure that no matter what the tween function returns, the mouse ends up
# at the final destination.
#if moveOrDrag == 'move':
#    platformModule._moveTo(x, y)
#else:
#    platformModule._dragTo(x, y, button)

This would probably require a second look and more test before such fix could be submited as a pull request but it's working well for what I need (and I'm a little bit pressured by time).

Thanks for the great library!

Eric

@asweigart
Copy link
Owner

Thanks, I'll take a look at it today.

@asweigart
Copy link
Owner

Ah, I think I know what the problem is. Is PyAutoGUI updated to the latest version? 0.9.20

In a previous version, PyAutoGUI was set up so that it only expected ranges between 0.0 and 1.0 from the tweening functions. However, the "elastic" and "back up" tweens overshoot the target (for cosmetic effect), and so I rewrote the PyAutoGUI code.

Reopen if this bug is present in 0.9.20. Also, what tween were you using?

@bleuetnoir
Copy link
Author

Yes, the issue was with 0.9.20 installed with pip, sorry I forgot to add this information in the issue.
It was not even working with linear tween...

@asweigart
Copy link
Owner

Do you have some code snippets that can reproduce the problem? What exactly is happening? Is the mouse not moving at all? Or is it moving instantly?

@asweigart asweigart reopened this Nov 20, 2014
@bleuetnoir
Copy link
Author

I have tested it at home in a Debian VM, I had to disable cursor integration (Virtualbox) and install a few libraries but the results are the same as what I had in Windows (but I have not tested "elastic" and "back up" tweens).

The simplest test case is:

import pyautogui
from pyautogui import tweens

pyautogui.moveTo(500, 500, duration=2, tween=pyautogui.tweens.easeInOutQuad)

This doesn't work as is (no move at all).

@skorokithakis
Copy link

I'm having a similar issue on Ubuntu, pyautogui.moveTo(500, 500, duration=1, tween=pyautogui.easeInOutQuad) just makes the pointer sit there and jump to the target after a second, without any tweening or animation at all. I'm running in a virtualenv.

@neatville
Copy link

I use Ubuntu also, and I get an error when I try it (whether it's python2 or 3).

 pyautogui.moveTo(100, 100, 2, pyautogui.tweens.easeInQuad)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'tweens'

@adamkdean
Copy link

I am also getting this issue, and it's 2016 now.

Traceback (most recent call last):
File "c:\Users\Adam\Projects\Test\test.py", line 8, in
pyautogui.moveTo(500, 500, duration=2, tween=pyautogui.tweens.easeInOutQuad)
AttributeError: module 'pyautogui' has no attribute 'tweens'

Edit, looks like I had to import pyautogui.tweens like so:

import pyautogui
import pyautogui.tweens

# use tweening/easing function to move mouse over 2 seconds.
pyautogui.moveTo(500, 500, 2, pyautogui.tweens.easeInOutQuad)

@asweigart
Copy link
Owner

The update to the documentation in 166b828 corrects this. The tweens module no longer exists, instead you just specify the function directly: pyautogui.easeInOutQuad instead of pyautogui.tweens.easeInOutQuad.

@kimborgen
Copy link

@asweigart Why is this still not fixed in the readme? 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants