
    g
f                         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  G d de	j                         Zy)z1Customized support for spellcheck in LibreOffice.z$Id$z
$Revision$z$Date$zCopyright (c) 2015 Igalia, S.L.LGPL    )debug)messages)
spellcheck)AXObject)AXText)AXUtilitiesc                   H     e Zd Z fdZd Zd Zd Zd Zd Zd Z	d Z
 xZS )	
SpellCheckc                 6    t         |   |d       i | _        y )NF)hasChangeToEntry)super__init___windows)selfscript	__class__s     F/usr/lib/python3/dist-packages/orca/scripts/apps/soffice/spellcheck.pyr   zSpellCheck.__init__'   s    %8    c                     |y t        j                  |      r|S | j                  t        j                  |d            S )Nr   )r	   	is_dialog_findChildDialogr   	get_child)r   roots     r   r   zSpellCheck._findChildDialog+   s;    <  &K$$X%7%7a%@AAr   c                    t        j                  |      r+d|dg}t        j                  t        j                  |d       y| j
                  j                  t        |            }|-d|d|g}t        j                  t        j                  |d       |S | j                  |      }|sCd| j
                  t        |      <   d|dg}t        j                  t        j                  |d       yt        j                  |t        j                        [d| j
                  t        |      <   d| j
                  t        |      <   d|dg}t        j                  t        j                  |d       yt        j                  |t        j                        d u}d|d|g}t        j                  t        j                  |d       || j
                  t        |      <   |S )	NzSOFFICE:z+is not spellcheck window because it's dead.TFzis spellcheck window:z:is not spellcheck window because the dialog was not found.z;is not spellcheck dialog because a page tab list was found.z2is spellcheck dialog based on combobox descendant:)r   is_deadr   printTokens
LEVEL_INFOr   gethashr   find_descendantr	   is_page_tab_listis_combo_box)r   windowtokensrvdialogs        r   _isCandidateWindowzSpellCheck._isCandidateWindow4   s   F# &*WXFe..=]]tF|,> &*A2FFe..=I&&v.*/DMM$v,' &RTFe..=##FK,H,HIU*/DMM$v,'*/DMM$v,' &SUFe..=%%fk.F.FGtSf&Z\^_%**FD9&(d6l#	r   c                     d }t        j                  ||      }d|d|g}t        j                  t        j                  |d       |S )Nc                     t        j                  |       syt        j                  |       xr t        j                  |       S NF)r   supports_editable_textr	   is_focusableis_multi_linexs    r   isErrorz,SpellCheck._findErrorWidget.<locals>.isErrorW   s4    2215++A.O;3L3LQ3OOr   zSOFFICE: Error widget for:is:Tr   r!   r   r   r   )r   r   r1   r&   r%   s        r   _findErrorWidgetzSpellCheck._findErrorWidgetV   sG    	P
 %%dG4.eR@%**FD9	r   c                     d }t        j                  ||      }d|d|g}t        j                  t        j                  |d       |S )Nc                     t        j                  |       syt        j                  |       xs, t        j                  |       xs t        j
                  |       S r+   )r   supports_selectionr	   is_listis_list_boxis_tree_tabler/   s    r   isSelectableListz9SpellCheck._findSuggestionsList.<locals>.isSelectableListb   sL    ..q1&&q) 0**1-0,,Q/0r   zSOFFICE: Suggestions list for:r2   Tr3   )r   r   r;   r&   r%   s        r   _findSuggestionsListzSpellCheck._findSuggestionsLista   sG    	0 %%d,<=2D%D%**FD9	r   c                 `    | j                   j                  j                  |      \  }}|dz   |fS )N   )_script	utilitiesgetPositionAndSetSize)r   
suggestionindextotals       r   _getSuggestionIndexAndPositionz)SpellCheck._getSuggestionIndexAndPositionn   s/    ||--CCJOuqy%r   c                 |   t        j                  | j                        }d\  }}d|cxk  r|k  rn |S t        j                  | j                  |      \  }}}|j	                  dd      j                  dd      dk(  r!t        j                  | j                  ||      S t        ||dz         }d|cxk  r|k  r|S  |S )N)r    r   zfg-colorrG    z255,0,0r>   )r   get_character_count_errorWidgetget_text_attributes_at_offsetr   replaceget_substringmax)r   lengthoffsetstringattrsstartends          r   getMisspelledWordzSpellCheck.getMisspelledWordr   s    ++D,=,=>6"F"  !' D DTEVEVX^ _E5#yyR(00b9YF++D,=,=ucJJfqj)F	 6"F"  # r   c                    | j                         syt        j                  | j                        }|syt        j
                  |z  }| j                  j                  j                  |      }| j                  j                  ||       y)NF)rQ   )voiceT)
isActiver   get_all_textrJ   r   MISSPELLED_WORD_CONTEXTr?   speechGeneratorrW   speakMessage)r   rQ   msgrW   s       r   presentContextzSpellCheck.presentContext}   sq    }}$$T%6%67..7,,22#2>!!#U!3r   )__name__
__module____qualname__r   r   r(   r4   r<   rE   rU   r^   __classcell__)r   s   @r   r   r   %   s-    B D	 	r   r   N)__doc____id____version____date____copyright____license__orcar   r   r   orca.ax_objectr   orca.ax_textr   orca.ax_utilitiesr	   r    r   r   <module>rn      sI   , 8	1    #  )c&& cr   