
    g
fO                         d Z dZdZdZdZdZddlZddlZddlZ ej                  dd	       dd
l
mZ ddlmZ ddlmZ ddlmZ  G d d      Zej'                          y)a  
Utilities for obtaining value-related information about accessible objects.
These utilities are app-type- and toolkit-agnostic. Utilities that might have
different implementations or results depending on the type of app (e.g. terminal,
chat, web) or toolkit (e.g. Qt, Gtk) should be in script_utilities.py file(s).

N.B. There are currently utilities that should never have custom implementations
that live in script_utilities.py files. These will be moved over time.
z$Id$z
$Revision$z$Date$zGCopyright (c) 2024 Igalia, S.L.Copyright (c) 2024 GNOME Foundation Inc.LGPL    NAtspiz2.0)r      )debug)AXObject)AXUtilitiesc                       e Zd ZdZi Z ej                         Zed        Z	ed        Z
ed        Zed        Zed        Zed        Zed        Zed	        Zed
        Zy)AXValuezKUtilities for obtaining value-related information about accessible objects.c                      	 t        j                  d       d} t        j                  t        j                  | d       t
        j                  j                          [)z*Clears any data we have cached for objectsT<   zAXValue: Clearing local cache.)timesleepr   printMessage
LEVEL_INFOr
   LAST_KNOWN_VALUEclear)msgs    //usr/lib/python3/dist-packages/orca/ax_value.py_clear_stored_datazAXValue._clear_stored_data8   sF     JJrN2Cu//d;$$**,	     c                  z    t        j                  t        j                        } d| _        | j                          y)z3Starts thread to periodically clear cached details.)targetTN)	threadingThreadr
   r   daemonstart)threads    r   start_cache_clearing_threadz#AXValue.start_cache_clearing_threadB   s*     !!)C)CDr   c                    t        j                  |       syt        j                  j	                  t        |             }|t        j                  |       k7  }|r-d| d| g}t        j                  t        j                  |d       |S )z*Returns True if the current value changed.FzAXValue: Previous value ofzwas T)
r   supports_valuer
   r   gethash_get_current_valuer   printTokensr   )obj	old_valueresulttokenss       r   did_value_changezAXValue.did_value_changeJ   sw     &&s+,,00c;	g88==2C4	{9KLFe..=r   c                 L   t        j                  |       sy	 t        j                  j	                  |       }d| d| g}t        j                  t        j                  |d       |S # t
        $ r4}d| }t        j                  t        j                  |d       Y d}~yd}~ww xY w)!Returns the current value of obj.r   z*AXValue: Exception in _get_current_value: TNAXValue: Current value ofis )
r   r    r   Valueget_current_value	Exceptionr   r   r   r$   r%   valueerrorr   r(   s        r   r#   zAXValue._get_current_valueY   s     &&s+	KK11#6E .sc%MB%**FD9  	>ugFCu//d;	   A& &	B#/*BB#c                     t        j                  |       syt        j                  |       }|t        j                  t        |       <   |S )r+   r   )r   r    r
   r#   r   r"   )r%   r2   s     r   r/   zAXValue.get_current_valuek   s>     &&s+**3/.3  c+r   c                    t        j                  | dd      xs d}|r0d| d| dg}t        j                  t        j                  |d       |S t        j
                  |       sy	 t        j                  j                  |       }d
| d| dg}t        j                  t        j                  |d       |r|S t        j                  |       }t        |      dk  r.|dk7  r)t        |      }t        |j!                  d      d         }nd}|d| dS # t        $ r6}d| }t        j                  t        j                  |d       d}Y d	}~d	}~ww xY w)zGReturns the app-provided text-alternative for the current value of obj.	valuetextF z AXValue: valuetext attribute forzis ''Tz.AXValue: Exception in get_current_value_text: NzAXValue: Value text ofr   r   .f)r   get_attributer   r$   r   r    r   r.   get_textr0   r   r
   r#   absstrlensplit)	r%   textr(   r2   r3   r   currentstr_currentdecimal_placess	            r   get_current_value_textzAXValue.get_current_value_textv   sK    %%c;>D"8#dV1~NFe..=K&&s+	KK((-E +C4waA%**FD9L,,S1w<!1g,K !2!23!7!:;NN!N+1,-.#  	B5'JCu//d;E	s   %D 	E,EEc                    t        j                  |       syt        j                  |       }t	        j
                  |       r0|dk  r+d| dg}t        j                  t        j                  |d       yt        j                  |       }t        j                  |       }||k(  ryt        |||z
  z  dz        }d| d| g}t        j                  t        j                  |d       |S )	zJReturns the current value as a percent, or None if that is not applicable.Nr   zAXValue:zhas state indeterminateTd   r,   zas percent is is )r   r    r
   r#   r   is_indeterminater   r$   r   get_minimum_valueget_maximum_valueint)r%   r2   r(   minimummaximumr'   s         r   get_value_as_percentzAXValue.get_value_as_percent   s     &&s+**3/'',! #'@AFe..=++C0++C0gew01S89-s6Gx4PQ%**FD9r   c                 L   t        j                  |       sy	 t        j                  j	                  |       }d| d| g}t        j                  t        j                  |d       |S # t
        $ r4}d| }t        j                  t        j                  |d       Y d}~yd}~ww xY w)z!Returns the minimum value of obj.r   z)AXValue: Exception in get_minimum_value: TNzAXValue: Minimum value ofr-   )
r   r    r   r.   rJ   r0   r   r   r   r$   r1   s        r   rJ   zAXValue.get_minimum_value        &&s+	KK11#6E .sc%MB%**FD9  	=eWECu//d;	r4   c                 L   t        j                  |       sy	 t        j                  j	                  |       }d| d| g}t        j                  t        j                  |d       |S # t
        $ r4}d| }t        j                  t        j                  |d       Y d}~yd}~ww xY w)z!Returns the maximum value of obj.r   z)AXValue: Exception in get_maximum_value: TNzAXValue: Maximum value ofr-   )
r   r    r   r.   rK   r0   r   r   r   r$   r1   s        r   rK   zAXValue.get_maximum_value   rQ   r4   N)__name__
__module____qualname____doc__r   r   Lock_lockstaticmethodr   r   r)   r#   r/   rF   rO   rJ   rK    r   r   r
   r
   2   s    UINNE- -      "   / /B  ,  "  r   r
   )rV   __id____version____date____copyright____license__r   r   girequire_versiongi.repositoryr   r8   r   	ax_objectr   ax_utilitiesr   r
   r   rZ   r   r   <module>re      si   , ;   	   7E "    %_ _B  # # %r   