
    g
fp                         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 ddlmZ ddlmZ ddlmZ  G d d      Z e       Zd Zy)8Provides Orca-controlled navigation for tabular content.z$Id$z
$Revision$z$Date$zyCopyright (c) 2005-2009 Sun Microsystems Inc.Copyright (c) 2011-2023 Igalia, S.L.Copyright (c) 2023 GNOME Foundation Inc.LGPL   )cmdnames)debug)focus_manager)input_event)keybindings)messages)
orca_state)settings_manager)AXObject)AXTable)AXText)AXUtilitiesc                       e Zd ZdZd ZddZd dZd Zd Zd Z	d Z
d!d	Zd"dZd!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d"dZd"dZd"dZd"dZd"dZd"dZd"dZd"dZd Zy
)#TableNavigatorr   c                     d | _         d | _        d | _        d| _        d| _        | j                  d      | _        t        j                         | _	        y )NTF)
_previous_reported_row_previous_reported_col_last_input_event_enabled
_suspendedget_handlers	_handlersr	   KeyBindings	_bindingsselfs    6/usr/lib/python3/dist-packages/orca/table_navigator.py__init__zTableNavigator.__init__2   sL    &*#&*#!%  **40$002    c                     |rCd}t        j                  t         j                  |d       | j                          | j                  S | j                  j                         r| j                          | j                  S )z(Returns the table-navigator keybindings.z%TABLE NAVIGATOR: Refreshing bindings.T)r   printMessage
LEVEL_INFO_setup_bindingsr   isEmpty)r   refresh
is_desktopmsgs       r   get_bindingszTableNavigator.get_bindings?   sd     9Cu//d;  " ~~ ^^##%  "~~r!   c                     |r7d}t        j                  t         j                  |d       | j                          | j                  S )z%Returns the table-navigator handlers.z%TABLE NAVIGATOR: Refreshing handlers.T)r   r#   r$   _setup_handlersr   )r   r'   r)   s      r   r   zTableNavigator.get_handlersK   s:     9Cu//d;  "~~r!   c                     | j                   S )z4Returns true if table-navigation support is enabled.)r   r   s    r   
is_enabledzTableNavigator.is_enabledU   s     }}r!   c                 b   | j                   duxrH | j                   t        j                  k(  xs) t        j                  j                  | j                         }| j                   | j                   j	                         }nd}d| d| }t        j                  t
        j                  |d       |S )z>Returns true if the last input event was a navigation command.NNonez(TABLE NAVIGATOR: Last navigation event (z) was last key event: T)r   r   lastNonModifierKeyEventisReleaseForasSingleLineStringr   r#   r$   )r   resultstringr)   s       r   'last_input_event_was_navigation_commandz6TableNavigator.last_input_event_was_navigation_commandZ   s     ''t3 \'':+M+MM [55BB4CYCYZ 	 !!-++>>@FF8@VW]V^_5++S$7r!   c                     t        j                         | _        | j                  j                  t        j                  dt         j
                  t         j                  | j                  j                  d      d| j                                | j                  j                  t        j                  dt         j
                  t         j                  | j                  j                  d      d| j                  xr | j                                | j                  j                  t        j                  dt         j
                  t         j                  | j                  j                  d      d| j                  xr | j                                | j                  j                  t        j                  dt         j
                  t         j                  | j                  j                  d	      d| j                  xr | j                                | j                  j                  t        j                  d
t         j
                  t         j                  | j                  j                  d      d| j                  xr | j                                | j                  j                  t        j                  dt         j
                  t         j                  | j                  j                  d      d| j                  xr | j                                | j                  j                  t        j                  dt         j
                  t         j                  | j                  j                  d      d| j                  xr | j                                | j                  j                  t        j                  dt         j
                  t         j                  | j                  j                  d      d| j                  xr | j                                | j                  j                  t        j                  dt         j
                  t         j                  | j                  j                  d      d| j                  xr | j                                | j                  j                  t        j                  dt         j
                  t         j                  | j                  j                  d      d| j                  xr | j                                | j                  j                  t        j                  d
t         j
                  t         j                  | j                  j                  d      d| j                  xr | j                                | j                  j                  t        j                  dt         j
                  t         j                  | j                  d   d| j                  xr | j                                | j                  j                  t        j                  dt         j
                  t         j                  | j                  d   d| j                  xr | j                                | j                  j                  t        j                  dt         j
                  t         j                  | j                  d   d| j                  xr | j                                | j                  j                  t        j                  dt         j
                  t         j                  | j                  d   d| j                  xr | j                                t        j                         j                  | j                  | j                  d      | _        d| j                   }t!        j"                  t         j$                  |d       | j                  g}t!        j&                  t         j$                  |d       y)z*Sets up the table-navigation key bindings.ttable_navigator_toggle_enabledr   Lefttable_cell_leftRighttable_cell_rightUptable_cell_upDowntable_cell_downHometable_cell_firstEndtable_cell_lasttable_cell_beginning_of_rowtable_cell_end_of_rowtable_cell_top_of_columntable_cell_bottom_of_columnrset_dynamic_column_headers_row clear_dynamic_column_headers_row   cset_dynamic_row_headers_column clear_dynamic_row_headers_columnFz-TABLE NAVIGATOR: Bindings set up. Suspended: TN)r	   r   r   add
KeyBindingdefaultModifierMaskORCA_SHIFT_MODIFIER_MASKr   getr   SHIFT_ALT_MODIFIER_MASKr   ORCA_ALT_SHIFT_MODIFIER_MASKr   
getManageroverrideKeyBindingsr   r#   r$   printTokens)r   r)   tokenss      r   r%   zTableNavigator._setup_bindingsj   s    %002""//44""#CDOO#%	& 	""//33""#455doo"57	8 	""//33""#565doo"57	8 	""//33""?35doo"57	8 	""//33""#455doo"57	8 	""//33""#565doo"57	8 	""//33""#455doo"57	8 	""//88""#@A5doo"57	8 	""//88""#:;5doo"57	8 	""//88""#=>5doo"57	8 	""//88""#@A5doo"57	8 	""//44?@5doo"57	8 	""//44AB5doo"57	8 	""//44?@5doo"57	8 	""//44AB5doo"57	8 *446JJNNDNNE3 >doo=NO5++S$7..!%**FD9r!   c                 r
   i | _         t        j                  | j                  t        j
                  | j                         | j                   d<   t        j                  | j                  t        j                  | j                  xr | j                         | j                   d<   t        j                  | j                  t        j                  | j                  xr | j                         | j                   d<   t        j                  | j                  t        j                  | j                  xr | j                         | j                   d<   t        j                  | j                  t        j                  | j                  xr | j                         | j                   d<   t        j                  | j                   t        j"                  | j                  xr | j                         | j                   d<   t        j                  | j$                  t        j&                  | j                  xr | j                         | j                   d<   t        j                  | j(                  t        j*                  | j                  xr | j                         | j                   d	<   t        j                  | j,                  t        j.                  | j                  xr | j                         | j                   d
<   t        j                  | j0                  t        j2                  | j                  xr | j                         | j                   d<   t        j                  | j4                  t        j6                  | j                  xr | j                         | j                   d<   t        j                  | j8                  t        j:                  | j                  xr | j                         | j                   d<   t        j                  | j<                  t        j>                  | j                  xr | j                         | j                   d<   t        j                  | j@                  t        jB                  | j                  xr | j                         | j                   d<   t        j                  | jD                  t        jF                  | j                  xr | j                         | j                   d<   d| j                   }tI        jJ                  tH        jL                  |d       y)z1Sets up the table-navigator input event handlers.)enabledr9   r;   r=   r?   rA   rC   rE   rF   rG   rH   rI   rK   rL   rO   rP   z-TABLE NAVIGATOR: Handlers set up. Suspended: TN)'r   r   InputEventHandler_toggle_enabledr   TABLE_NAVIGATION_TOGGLEr   _table_cell_leftTABLE_CELL_LEFTr   _table_cell_rightTABLE_CELL_RIGHT_table_cell_upTABLE_CELL_UP_table_cell_downTABLE_CELL_DOWN_table_cell_firstTABLE_CELL_FIRST_table_cell_lastTABLE_CELL_LAST_table_cell_beginning_of_rowTABLE_CELL_BEGINNING_OF_ROW_table_cell_end_of_rowTABLE_CELL_END_OF_ROW_table_cell_top_of_columnTABLE_CELL_TOP_OF_COLUMN_table_cell_bottom_of_columnTABLE_CELL_BOTTOM_OF_COLUMN_set_dynamic_column_headers_rowDYNAMIC_COLUMN_HEADER_SET!_clear_dynamic_column_headers_rowDYNAMIC_COLUMN_HEADER_CLEAR_set_dynamic_row_headers_columnDYNAMIC_ROW_HEADER_SET!_clear_dynamic_row_headers_columnDYNAMIC_ROW_HEADER_CLEARr   r#   r$   )r   r)   s     r   r,   zTableNavigator._setup_handlers   s6     ))$$00"oo-/ 	78 ))%%((--?,?A 	() ))&&))--?,?A 	)* ))##&&--?,?A 	' ))%%((--?,?A 	() ))&&))--?,?A 	)* ))%%((--?,?A 	() ))1144--?,?A 	45 ))++..--?,?A 	./ ))..11--?,?A 	12 ))1144--?,?A 	45 ))4422--?,?A 	78 ))6644--?,?A 	9: ))44//--?,?A 	78 ))6611--?,?A 	9: >doo=NO5++S$7r!   c                    d}|r|d| z  }t        j                  t         j                  |d       | j                  j                  D ]  }|j                  j                  |d       ! | j                  d      | _        | j                  d      | _        | j                  j                  D ]*  }|j                  j                  || j                          , y)z9Refreshes table navigation bindings and grabs for script.z.TABLE NAVIGATOR: Refreshing bindings and grabs: T)includeGrabsN)r   r#   r$   r   keyBindingsremover   r   r*   rQ   r   )r   scriptreasonr)   bindings        r   refresh_bindings_and_grabsz)TableNavigator.refresh_bindings_and_grabsb  s     ?Rx= C5++S$7~~11 	BG%%gD%A	B **40**40~~11 	NG""7T__9L"M	Nr!   Nc                     | j                    | _         | j                   r |j                  t        j                         n|j                  t        j                         d| _        | j                  |d       y)zToggles table navigation.Nztoggling table navigationT)r   presentMessager
   TABLE_NAVIGATION_ENABLEDTABLE_NAVIGATION_DISABLEDr   r   )r   r   events      r   r_   zTableNavigator._toggle_enableds  s]     !MM)==!!("C"CD!!("D"DE!%''0KLr!   c                     || j                   k(  ryd| }|r|d| z  }t        j                  t        j                  |d       || _         | j	                  |d|        y)z=Suspends table navigation independent of the enabled setting.NzTABLE NAVIGATOR: Suspended: r~   TzSuspended changed to )r   r   r#   r$   r   )r   r   	suspendedr   r)   s        r   suspend_commandszTableNavigator.suspend_commands  si     ',YK8Rx= C5++S$7#''2G	{0STr!   c                    t        j                  |      r+d|dg}t        j                  t        j                  |d       yt        j                  |      r+d|dg}t        j                  t        j                  |d       yt        j                  |      rZt        j                  |      D ]A  }| j                  |      rd|d|dg}t        j                  t        j                  |d        y yt        j                  |      s+d|dg}t        j                  t        j                  |d       yd	|d
g}t        j                  t        j                  |d       y)z<Returns True if obj is empty or consists of only whitespace.zTABLE NAVIGATOR:zis not blank: it is focusableTFzis not blank: it has a namezis not blank:zis not blankzis not blank: it has textzTABLE NAVIGATOR: Treatingzas blank)r   is_focusabler   rZ   r$   r   get_nameget_child_countiter_children	_is_blankr   is_whitespace_or_empty)r   objr[   childs       r   r   zTableNavigator._is_blank  s1    ##C((#/NOFe..=S!(#/LMFe..=##C(!//4 !~~e,0#~^F%%e&6&6E 	!
 ,,S1(#/JKFe..=-sJ?%**FD9r!   c                 f   t        j                         j                         }t        j                  |      }t        j                  |      r|}t        j                  |      s$t        j                  |t
        j                        }d|g}t        j                  t        j                  |d       |S )zReturns the current cell.z TABLE NAVIGATOR: Current cell isT)r   rX   get_locus_of_focusr   
get_parentr   is_table_cell_or_headerfind_ancestorr   rZ   r$   )r   cellparentr[   s       r   _get_current_cellz TableNavigator._get_current_cell  s     '')<<> $$T*..v6D 2248))$0S0STD4d;%**FD9r!   c                 ,   t        j                  |d      \  }}| j                  | j                  ||fS t        j                  t        j                  |      | j                  | j
                        }||k(  r| j                  | j
                  fS ||fS )zGReturns the coordinates of cell, possibly adjusted for linear movement.F)prefer_attribute)r   get_cell_coordinatesr   get_cell_at	get_tabler   )r   r   rowcol	last_cells        r   _get_cell_coordinatesz$TableNavigator._get_cell_coordinates  s     //uMS&&.$2M2M2U8O ''d#T%@%@$B]B]_	..0K0KKKCxr!   c                 t   || _         | j                         }| |j                  t        j                         yt        j                  |      r |j                  t        j                         y| j                  |      \  }}t        j                  |      }t        j                         j                  d      rf|rd| j                  |      rSt        j                  |      s>t        j                  |      }|r'| j                  |      rt        j                  |      s>| j                  ||||dz
  |       y)zMoves to the cell on the left.TskipBlankCellsr   )r   r   r   r
   TABLE_NOT_IN_Ar   is_start_of_rowTABLE_ROW_BEGINNINGr   get_cell_on_leftr   rX   
getSettingr   _present_cellr   r   r   currentr   r   r   s          r   ra   zTableNavigator._table_cell_left  s     "'((*?!!("9"9:""7+!!(">">?--g6S''0&&(334DE4>>$/8O8OPT8U//5 4>>$/8O8OPT8U 	64cAgw?r!   c                 t   || _         | j                         }| |j                  t        j                         yt        j                  |      r |j                  t        j                         y| j                  |      \  }}t        j                  |      }t        j                         j                  d      rf|rd| j                  |      rSt        j                  |      s>t        j                  |      }|r'| j                  |      rt        j                  |      s>| j                  ||||dz   |       y)zMoves to the cell on the right.Tr   r   )r   r   r   r
   r   r   is_end_of_rowTABLE_ROW_ENDr   get_cell_on_rightr   rX   r   r   r   r   s          r   rc   z TableNavigator._table_cell_right  s     "'((*?!!("9"9:  )!!("8"89--g6S((1&&(334DE4>>$/8M8Md8S006 4>>$/8M8Md8S 	64cAgw?r!   c                 t   || _         | j                         }| |j                  t        j                         yt        j                  |      r |j                  t        j                         y| j                  |      \  }}t        j                  |      }t        j                         j                  d      rf|rd| j                  |      rSt        j                  |      s>t        j                  |      }|r'| j                  |      rt        j                  |      s>| j                  |||dz
  ||       y)zMoves to the cell above.Tr   r   )r   r   r   r
   r   r   is_top_of_columnTABLE_COLUMN_TOPr   get_cell_abover   rX   r   r   r   r   s          r   re   zTableNavigator._table_cell_up  s     "'((*?!!("9"9:##G,!!(";";<--g6S%%g.&&(334DE4>>$/8P8PQU8V--d3 4>>$/8P8PQU8V 	64q#w?r!   c                 t   || _         | j                         }| |j                  t        j                         yt        j                  |      r |j                  t        j                         y| j                  |      \  }}t        j                  |      }t        j                         j                  d      rf|rd| j                  |      rSt        j                  |      s>t        j                  |      }|r'| j                  |      rt        j                  |      s>| j                  |||dz   ||       y)zMoves to the cell below.Tr   r   )r   r   r   r
   r   r   is_bottom_of_columnTABLE_COLUMN_BOTTOMr   get_cell_belowr   rX   r   r   r   r   s          r   rg   zTableNavigator._table_cell_down  s     "'((*?!!("9"9:&&w/!!(">">?--g6S%%g.&&(334DE4>>$/8S8STX8Y--d3 4>>$/8S8STX8Y 	64q#w?r!   c                     || _         | j                         }| |j                  t        j                         yt        j                  |      }t        j                  |      }| j                  ||dd|       y)zMoves to the first cell.T    )	r   r   r   r
   r   r   r   get_first_cellr   r   r   r   r   tabler   s         r   ri   z TableNavigator._table_cell_first0  so     "'((*?!!("9"9:!!'*%%e,64Aw7r!   c                 @   || _         | j                         }| |j                  t        j                         yt        j                  |      }t        j                  |      }| j                  ||t        j                  |      t        j                  |      |       y)zMoves to the last cell.T)r   r   r   r
   r   r   r   get_last_cellr   get_row_countget_column_countr   s         r   rk   zTableNavigator._table_cell_last>  s     "'((*?!!("9"9:!!'*$$U+D'//68P8PQV8WY`	br!   c                 \   || _         | j                         }| |j                  t        j                         yt        j                  |      r |j                  t        j                         yt        j                  |      }| j                  |      \  }}| j                  |||||       y)z"Moves to the beginning of the row.T)r   r   r   r
   r   r   r   r   get_start_of_rowr   r   r   r   r   r   r   r   r   s          r   rm   z+TableNavigator._table_cell_beginning_of_rowM  s     "'((*?!!("9"9:""7+!!(">">?''0--d3S64c7;r!   c                 \   || _         | j                         }| |j                  t        j                         yt        j                  |      r |j                  t        j                         yt        j                  |      }| j                  |      \  }}| j                  |||||       y)zMoves to the end of the row.T)r   r   r   r
   r   r   r   r   get_end_of_rowr   r   r   s          r   ro   z%TableNavigator._table_cell_end_of_row_  s     "'((*?!!("9"9:  )!!("8"89%%g.--d3S64c7;r!   c                    || _         | j                         }| |j                  t        j                         yt        j                  |      r |j                  t        j                         y| j                  |      d   }t        j                  |      }| j                  |      d   }| j                  |||||       y)zMoves to the top of the column.Tr   r   )r   r   r   r
   r   r   r   r   r   get_top_of_columnr   r   r   r   r   r   r   r   s          r   rq   z(TableNavigator._table_cell_top_of_columnq  s     "'((*?!!("9"9:##G,!!(";";<((1!4((1((.q164c7;r!   c                    || _         | j                         }| |j                  t        j                         yt        j                  |      r |j                  t        j                         y| j                  |      d   }t        j                  |      }| j                  |      d   }| j                  |||||       y)z"Moves to the bottom of the column.Tr   r   )r   r   r   r
   r   r   r   r   r   get_bottom_of_columnr   r   s          r   rs   z+TableNavigator._table_cell_bottom_of_column  s     "'((*?!!("9"9:&&w/!!(">">?((1!4++G4((.q164c7;r!   c                 J   || _         | j                         }| |j                  t        j                         yt        j                  |      }|rSt        j                  |      d   }t        j                  ||       |j                  t        j                  |dz   z         y)z,Sets the row for the dynamic header columns.Tr   r   )
r   r   r   r
   r   r   r   r   rK   rv   )r   r   r   r   r   r   s         r   ru   z.TableNavigator._set_dynamic_column_headers_row  s     "'((*?!!("9"9:!!'*..w7:C225#>!!("D"Da"PQr!   c                 l   || _         | j                         }| |j                  t        j                         yt        j                  t        j                         j                               }|rD|j                          t        j                  |       |j                  t        j                         y)z.Clears the row for the dynamic column headers.T)r   r   r   r
   r   r   r   r   rX   r   presentationInterruptrL   DYNAMIC_COLUMN_HEADER_CLEAREDr   r   r   r   r   s        r   rw   z0TableNavigator._clear_dynamic_column_headers_row  s     "'((*?!!("9"9:!!-":":"<"O"O"QR((*44U;!!("H"HIr!   c                 |   || _         | j                         }| |j                  t        j                         yt        j                  |      }|rlt        j                  |      d   }t        j                  ||       |j                  t        j                  |j                  j                  |dz         z         y)z,Sets the column for the dynamic row headers.Tr   )r   r   r   r
   r   r   r   r   rO   rz   	utilitiescolumnConvert)r   r   r   r   r   columns         r   ry   z.TableNavigator._set_dynamic_row_headers_column  s     "'((*?!!("9"9:!!'*11':1=F225&A!!//&2B2B2P2PQWZ[Q[2\\^ r!   c                 l   || _         | j                         }| |j                  t        j                         yt        j                  t        j                         j                               }|rD|j                          t        j                  |       |j                  t        j                         y)z.Clears the column for the dynamic row headers.T)r   r   r   r
   r   r   r   r   rX   r   r   rP   DYNAMIC_ROW_HEADER_CLEAREDr   s        r   r{   z0TableNavigator._clear_dynamic_row_headers_column  s     "'((*?!!("9"9:!!-":":"<"O"O"QR((*44U;!!("E"EFr!   c                    t        j                  |      s2d|d| d| dg}t        j                  t        j                  |d       y|| _        || _        |j                  j                  |      rt        j                  |       |j                  j                  |      \  }}t        j                         j                  d|d       t        j                  |      r7|j                  j!                  |      s|j                  j#                  ||       |j%                  |||d       t'        j                         j)                  d	      r+|j+                  t,        j.                  |d
z   |d
z   dz         t'        j                         j)                  d      rIt1        j2                  |      \  }	}
|	d
kD  s|
d
kD  r&|j+                  t-        j4                  |	|
             yyy)zPresents cell to the user.zTABLE NAVIGATOR: z(row z	, column z) is not cell or headerTNF)offsetpriorObj	interruptspeakCellCoordinatesr   )r   r   speakCellSpan)r   r   r   rZ   r$   r   r   r   grabFocusWhenSettingCaretr   
grab_focusgetFirstCaretPositionr   rX   set_locus_of_focussupports_text	isGUICellsetCaretPositionpresentObjectr   r   r   r
   TABLE_CELL_COORDINATESr   get_cell_spanscellSpan)r   r   r   r   r   previous_cellr[   r   r   rowspancolspans              r   r   zTableNavigator._present_cell  s    2248)45YseKb1cdFe..=&)#&)#55d;%&&<<TBV  "55dCG!!#&v/?/?/I/I$/O--c6:T&=TXY &&(334JK!!//37sUVw2WWY &&(33OD&55d;GW{gk%%h&7&7&IJ * Er!   )FT)F) )N) __name__
__module____qualname____doc__r    r*   r   r.   r6   r%   r,   r   r_   r   r   r   r   ra   rc   re   rg   ri   rk   rm   ro   rq   rs   ru   rw   ry   r{   r    r!   r   r   r   /   s    B3

 T:l`8DN"U<,$....$$&&""$"Kr!   r   c                      t         S )zReturns the Table Navigator)
_navigatorr   r!   r   getNavigatorr     s
     r!   N)r   __id____version____date____copyright____license__r   r   r   r   r   r	   r
   r   r   	ax_objectr   ax_tabler   ax_textr   ax_utilitiesr   r   r   r   r   r!   r   <module>r     si   . ?;             %KK KKZ 
r!   