
    ^j}                         d dl mZmZmZmZmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZ d dlmZ d dlmZ erd d	lmZ  G d
 d      Zy)    )TYPE_CHECKINGListOptionalTuplecast)ActionChains)interaction)ActionBuilder)MouseButton)PointerInput)Self)
WebElement)	WebDriverc                       e Zd Zddededee   defdZddededee   defdZ	dd	e
eeef      dee   defd
ZddedededededefdZdededededef
dZy)ActionHelpersN	origin_eldestination_eldurationreturnc                    |d}t        t        j                  d      }t        t	        d|             }t        | |      |_        |j                  j                  j                  |       |j                  j                  j                          t        | ||      |_        |j                  j                  j                  |       |j                  j                  j                          |j                          | S )a  Scrolls from one element to another

        Args:
            origin_el: the element from which to begin scrolling (center of element)
            destination_el: the element to scroll to (center of element)
            duration: defines speed of scroll action when moving from originalEl to destinationEl.
                Default is 600 ms for W3C spec.

        Usage:
            driver.scroll(el1, el2)

        Returns:
            Union['WebDriver', 'ActionHelpers']: Self instance
        iX  touchr   mouser   r   )r   r	   POINTER_TOUCHr   r   r
   w3c_actionspointer_actionmove_topointer_downreleaseperform)selfr   r   r   touch_inputactionss         ^/home/ubuntu/.local/lib/python3.12/site-packages/appium/webdriver/extensions/action_helpers.pyscrollzActionHelpers.scroll    s      H";#<#<gFtK67+DD 	**229=**779+DhW**22>B**224    pausec                    t        t        d|             }|j                  j                  j	                  |       |*|dkD  r%|j                  j                  j                  |       |j                  j                  j                  |       |j                  j                  j                          |j                          | S )a_  Drag the origin element to the destination element

        Args:
            origin_el: the element to drag
            destination_el: the element to drag to
            pause: how long the action pauses before moving after the tap and hold, in float seconds.

        Returns:
            Union['WebDriver', 'ActionHelpers']: Self instance
        r   r   )	r   r   r   r   click_and_holdr(   r   r    r!   )r"   r   r   r(   r$   s        r%   drag_and_dropzActionHelpers.drag_and_dropB   s     tK67**99)D..44U;**22>B**224r'   	positionsc                 0   t        |      dk(  rt        t        d|             }t        | t	        t
        j                  d            |_        |d   d   }|d   d   }|j                  j                  j                  ||       |j                  j                  j                          |r)|j                  j                  j                  |dz         n%|j                  j                  j                  d       |j                  j                  j                          |j                          | S d}t        t        d|             }g |j                  _        |D ]  }|dz  }|d   }|d   }|j                  j                  dd|       }|j!                  ||	       |j#                  t$        j&                  
       |r|j)                  |dz         n|j)                  d       |j+                  t$        j&                          |j                          | S )a  Taps on an particular place with up to five fingers, holding for a
        certain time

        Args:
            positions: an array of tuples representing the x/y coordinates of
                the fingers to tap. Length can be up to five.
            duration: length of time to tap, in ms

        Usage:
            driver.tap([(100, 20), (100, 60), (100, 100)], 500)

        Returns:
            Union['WebDriver', 'ActionHelpers']: Self instance
           r   r   r   r   i  g?finger)xy)button)lenr   r   r
   r   r	   r   r   r   move_to_locationr   r(   r    r!   devicesadd_pointer_inputcreate_pointer_movecreate_pointer_downr   LEFTcreate_pausecreate_pointer_up)	r"   r,   r   r$   r0   r1   r/   position	new_inputs	            r%   tapzActionHelpers.tapW   s    y>Q"4T#:;G"/LIbIbdk<l"mG!QA!QA..??1E..;;=##2288DI##2288=..668OO* ' F"4T#:;G*,G'% >!QKQK $//AA'VTZS[K\]	--Q-7--[5E5E-F**8d?;**3/++K,<,<=> OOr'   start_xstart_yend_xend_yc                     t        t        j                  d      }t        t	        d|             }t        | |      |_        |j                  j                  j                  ||       |j                  j                  j                          |dkD  rt        | ||      |_        |j                  j                  j                  ||       |j                  j                  j                          |j                          | S )a  Swipe from one point to another point, for an optional duration.

        Args:
            start_x: x-coordinate at which to start
            start_y: y-coordinate at which to start
            end_x: x-coordinate at which to stop
            end_y: y-coordinate at which to stop
            duration: defines the swipe speed as time taken to swipe from point a to point b, in ms.

        Usage:
            driver.swipe(100, 100, 100, 400)

        Returns:
            Union['WebDriver', 'ActionHelpers']: Self instance
        r   r   r   r   r   )r   r	   r   r   r   r
   r   r   r4   r   r    r!   )r"   r?   r@   rA   rB   r   r#   r$   s           r%   swipezActionHelpers.swipe   s      #;#<#<gFtK67+DD**;;GWM**779a<"/KRZ"[G**;;E5I**224r'   c                    t        t        d|             }t        | t        t        j
                  d            |_        |j                  j                  j                  ||       |j                  j                  j                          |j                  j                  j                  ||       |j                  j                  j                          |j                          | S )a  Flick from one point to another point.

        Args:
            start_x: x-coordinate at which to start
            start_y: y-coordinate at which to start
            end_x: x-coordinate at which to stop
            end_y: y-coordinate at which to stop

        Usage:
            driver.flick(100, 100, 100, 400)

        Returns:
            Union['WebDriver', 'ActionHelpers']: Self instance
        r   r   r   )r   r   r
   r   r	   r   r   r   r4   r   r    r!   )r"   r?   r@   rA   rB   r$   s         r%   flickzActionHelpers.flick   s     tK67+D[E^E^`g8hi**;;GWM**779**;;E5I**224r'   )N)r   )__name__
__module____qualname__r   r   intr   r&   floatr+   r   r   r>   rD   rF    r'   r%   r   r      s     
  J  RZ[^R_  ko  Dz : V^_dVe qu *0T%S/2 0hsm 0W[ 0dS 3 s 3 RU ^b :S 3 s 3 4 r'   r   N)typingr   r   r   r   r   'selenium.webdriver.common.action_chainsr   !selenium.webdriver.common.actionsr	   0selenium.webdriver.common.actions.action_builderr
   .selenium.webdriver.common.actions.mouse_buttonr   /selenium.webdriver.common.actions.pointer_inputr   typing_extensionsr   appium.webdriver.webelementr   appium.webdriver.webdriverr   r   rL   r'   r%   <module>rV      s4    > = @ 9 J F H " 24] ]r'   