
    g
fy/                         d Z dZdZdZdZd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 ddlmZ ddlmZ  G d d      Z e       Zd Zy)4Provides ability to navigate objects hierarchically.z$Id$z
$Revision$z$Date$z Copyright (c) 2023 The Orca TeamLGPL   )cmdnames)debug)focus_manager)input_event)keybindings)messages)AXEventSynthesizer)AXObject)AXUtilitiesc                       e Zd ZdZd ZddZddZd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd ZddZddZddZddZddZddZy)ObjectNavigatorr   c                     d | _         d | _        d | _        d| _        | j	                  d      | _        t        j                         | _        y )NT)	_navigator_focus_last_navigator_focus_last_locus_of_focus	_simplifyget_handlers	_handlersr	   KeyBindings	_bindings)selfs    7/usr/lib/python3/dist-packages/orca/object_navigator.py__init__zObjectNavigator.__init__+   sC     $%)"$(!**40$002    c                     |rCd}t        j                  t         j                  |d       | j                          | j                  S | j                  j                         r| j                          | j                  S )z)Returns the object-navigator keybindings.z&OBJECT NAVIGATOR: Refreshing bindings.T)r   printMessage
LEVEL_INFO_setup_bindingsr   isEmpty)r   refresh
is_desktopmsgs       r   get_bindingszObjectNavigator.get_bindings3   sd     :Cu//d;  " ~~ ^^##%  "~~r   c                     |r7d}t        j                  t         j                  |d       | j                          | j                  S )z&Returns the object-navigator handlers.z&OBJECT NAVIGATOR: Refreshing handlers.T)r   r   r   _setup_handlersr   )r   r"   r$   s      r   r   zObjectNavigator.get_handlers?   s:     :Cu//d;  "~~r   c           
      L   t        j                         | _        | j                  j                  t        j                  dt         j
                  t         j                  | j                  j                  d                   | j                  j                  t        j                  dt         j
                  t         j                  | j                  j                  d                   | j                  j                  t        j                  dt         j
                  t         j                  | j                  j                  d                   | j                  j                  t        j                  dt         j
                  t         j                  | j                  j                  d                   | j                  j                  t        j                  d	t         j
                  t         j                  | j                  j                  d
                   | j                  j                  t        j                  dt         j
                  t         j                  | j                  j                  d                   d}t        j                  t        j                  |d       y)z*Sets up the object-navigator key bindings.Upobject_navigator_upDownobject_navigator_downRightobject_navigator_nextLeftobject_navigator_previousReturnobject_navigator_perform_actions object_navigator_toggle_simplifyz"OBJECT NAVIGATOR: Bindings set up.TN)r	   r   r   add
KeyBindingdefaultModifierMaskORCA_CTRL_MODIFIER_MASKr   getr   r   r   r   r$   s     r   r    zObjectNavigator._setup_bindingsI   s    %002""//33""#89	;	< 	""//33""#:;	=	> 	""//33""#:;	=	> 	""//33""#>?	A	B 	""//33""#DE	G	H 	""//33""#EF	H	I 35++S$7r   c                 $   i | _         t        j                  | j                  t        j
                        | j                   d<   t        j                  | j                  t        j                        | j                   d<   t        j                  | j                  t        j                        | j                   d<   t        j                  | j                  t        j                        | j                   d<   t        j                  | j                  t        j                        | j                   d<   t        j                  | j                  t        j                        | j                   d<   d}t!        j"                  t         j$                  |d       y	)
z2Sets up the object-navigator input event handlers.r*   r,   r.   r0   r2   r4   z"OBJECT NAVIGATOR: Handlers set up.TN)r   r   InputEventHandlerupr   NAVIGATOR_UPdownNAVIGATOR_DOWNnextNAVIGATOR_NEXTpreviousNAVIGATOR_PREVIOUSperform_actionNAVIGATOR_PERFORM_ACTIONtoggle_simplifyNAVIGATOR_TOGGLE_SIMPLIFIEDr   r   r   r:   s     r   r'   zObjectNavigator._setup_handlers{   sH     ))%%' 	,- ))		'') 	./ ))		'') 	./ ))++- 	23 ))##113 	89 ))$$446 	9:
 35++S$7r   c                 ,    t        j                  |      S )z<Returns True if obj should be included in simple navigation.)r   is_paragraphr   objs     r   _include_in_simple_navigationz-ObjectNavigator._include_in_simple_navigation   s     '',,r   c                 Z   | j                  |      r+d|dg}t        j                  t        j                  |d       y|j                  j                  |      r+d|dg}t        j                  t        j                  |d       yd|g}t        j                  t        j                  |d       y)z>Returns True if obj should be excluded from simple navigation.zOBJECT NAVIGATOR: Not excludingz: explicit inclusionTFzOBJECT NAVIGATOR: Excludingz: is layout only)rM   r   printTokensr   	utilitiesisLayoutOnly)r   scriptrL   tokenss       r   _exclude_from_simple_navigationz/ObjectNavigator._exclude_from_simple_navigation   s     --c27>TUFe..= ((-3S:LMFe..=3S9%**FD9r   c                 (   t        j                  |      sg S t        t        j                  |            }| j                  s|S g }|D ]G  }| j                  ||      r"|j                  | j                  ||             7|j                  |       I |S )zJReturns a list of children for obj, taking simple navigation into account.)	r   get_child_countlistiter_childrenr   rT   extend	_childrenappend)r   rR   rL   childrenfunctional_childrenchilds         r   rZ   zObjectNavigator._children   s     '',I..s34~~O ! 	2E33FEB#**4>>&%+HI#**51		2 #"r   c                     t        j                  |      }| j                  s|S |<| j                  ||      r*t        j                  |      }|| j                  ||      r*|S )zBReturns the parent for obj, taking simple navigation into account.)r   
get_parentr   rT   )r   rR   rL   parents       r   _parentzObjectNavigator._parent   sg     $$S)~~M  T%I%I&RX%Y((0F  T%I%I&RX%Y r   c                 4    | j                   | _        || _         y)z8Changes the navigator focus, storing the previous focus.N)r   r   rK   s     r   _set_navigator_focusz$ObjectNavigator._set_navigator_focus   s     &*%:%:" #r   c                     t        j                         j                         \  }}|xs" t        j                         j                         }| j                  |k(  s||t         j
                  k(  ry|| _        || _        y)z9Updates the navigator focus to Orca's object of interest.N)r   
getManager&get_active_mode_and_object_of_interestget_locus_of_focusr   FLAT_REVIEWr   )r   moderegionrL   s       r   updatezObjectNavigator.update   sn     %//1XXZfG002EEG$$+~$-*C*C"C #$'!r   c                 2   d| j                   g}t        j                  t        j                  |d       t	        j
                         j                  | j                   t        j                         |j                  | j                   | j                         y)z1Presents the current navigator focus to the user.zOBJECT NAVIGATOR: PresentingT)rj   )priorObjN)
r   r   rO   r   r   rf   emit_region_changedOBJECT_NAVIGATORpresentObjectr   )r   rR   rS   s      r   presentzObjectNavigator.present   sy     1$2G2GH%**FD9  "66!!(F(F 	7 	HT22T=W=WXr   Nc                     | j                          | j                  || j                        }|#| j                  |       | j	                  |       y|j                  t        j                         y)z=Moves the navigator focus to the parent of the current focus.N)rl   rb   r   rd   rr   presentMessager
   NAVIGATOR_NO_PARENT)r   rR   eventra   s       r   r=   zObjectNavigator.up   sW     	fd&;&;<%%f-LL !!(">">?r   c                     | j                          | j                  || j                        }|s |j                  t        j
                         y| j                  |d          | j                  |       y)zBMoves the navigator focus to the first child of the current focus.N    )rl   rZ   r   rt   r
   NAVIGATOR_NO_CHILDRENrd   rr   )r   rR   rv   r\   s       r   r?   zObjectNavigator.down  s[     	>>&$*?*?@!!("@"@A!!(1+.Vr   c                    | j                          | j                  || j                        }| |j                  t        j
                         y| j                  ||      }| j                  |v ru|j                  | j                        }|t        |      dz
  k  r)| j                  ||dz             | j                  |       y|j                  t        j
                         y| j                  |       | j                  |       y)zCMoves the navigator focus to the next sibling of the current focus.Nr   )rl   rb   r   rt   r
   NAVIGATOR_NO_NEXTrZ   indexlenrd   rr   r   rR   rv   ra   siblingsr|   s         r   rA   zObjectNavigator.next  s     	fd&;&;<>!!("<"<=>>&&1  H,NN4#8#89Es8}q(())(57*;<V$%%h&@&@A%%f-LL r   c                    | j                          | j                  || j                        }| |j                  t        j
                         y| j                  ||      }| j                  |v ri|j                  | j                        }|dkD  r)| j                  ||dz
            | j                  |       y|j                  t        j
                         y| j                  |       | j                  |       y)zGMoves the navigator focus to the previous sibling of the current focus.Nrx   r   )
rl   rb   r   rt   r
   NAVIGATOR_NO_PREVIOUSrZ   r|   rd   rr   r~   s         r   rC   zObjectNavigator.previous&  s     	fd&;&;<>!!("@"@A>>&&1  H,NN4#8#89Eqy))(57*;<V$%%h&D&DE%%f-LL r   c                     | j                    | _         | j                   r |j                  t        j                         y|j                  t        j                         y)zToggles simplified navigation.T)r   rt   r
   NAVIGATOR_SIMPLIFIED_ENABLEDNAVIGATOR_SIMPLIFIED_DISABLEDr   rR   rv   s      r   rG   zObjectNavigator.toggle_simplify;  sK     "^^+>>!!("G"GH  !!("H"HIr   c                     t        j                  | j                        ryt        j                  | j                  d       y)z'Attempts to click on the current focus.Tr   )r   try_all_clickable_actionsr   click_objectr   s      r   rE   zObjectNavigator.perform_actionE  s2    778M8MN''(=(=qAr   )FT)F)N)__name__
__module____qualname____doc__r   r%   r   r    r'   rM   rT   rZ   rb   rd   rl   rr   r=   r?   rA   rC   rG   rE    r   r   r   r   (   sc    >3
08d$8L-
0#($
(Y	@
!*!*r   r   c                      t         S )zReturns the Object Navigator)
_navigatorr   r   r   getNavigatorr   O  s
     r   N)r   __id____version____date____copyright____license__ r   r   r   r   r	   r
   ax_event_synthesizerr   	ax_objectr   ax_utilitiesr   r   r   r   r   r   r   <module>r      sZ   * ;2       4  %c cL	 
r   