
    g
f*                         d Z dZdZdZdZdZddl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y)z:Script-customizable support for application spellcheckers.z$Id$z
$Revision$z$Date$zCopyright (c) 2014 Igalia, S.L.LGPL    N)debug)focus_manager)	guilabels)messages)object_properties)settings_manager)AXObject)AXText)AXUtilitiesc                       e Zd ZddZd Zd Zd Zd Zd Zd Z	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 Zd Zd Zd Zd Zd Zd Zd Zy)"
SpellCheckc                     || _         || _        d | _        d | _        d | _        d | _        d| _        d| _        d | _        d | _	        d | _
        y )NF)N)_script_hasChangeToEntry_window_errorWidget_changeToEntry_suggestionsList
_activated_documentPositionspellErrorCheckButtonspellSuggestionCheckButtonpresentContextCheckButton)selfscripthasChangeToEntrys      1/usr/lib/python3/dist-packages/orca/spellcheck.py__init__zSpellCheck.__init__-   sW    !1 " $!)%)"*.')-&    c                    d|g}t        j                  t         j                  |d       | j                  |      s+d|dg}t        j                  t         j                  |d       y| j                  rJ| j                  |      | _        | j                  s(d}t        j                  t         j                  |d       y| j                  |      | _	        | j                  s(d}t        j                  t         j                  |d       y| j                  |      | _        | j                  s(d}t        j                  t         j                  |d       y|| _        d| _        d	}t        j                  t         j                  |d       y)
Nz&SPELL CHECK: Attempting activation forTzSPELL CHECK:zis not spellcheck windowFz&SPELL CHECK: Change-to entry not foundz#SPELL CHECK: Error widget not foundz'SPELL CHECK: Suggestions list not foundz SPELL CHECK: Activation complete)r   printTokens
LEVEL_INFO_isCandidateWindowr   _findChangeToEntryr   printMessage_findErrorWidgetr   _findSuggestionsListr   r   r   )r   windowtokensmsgs       r   activatezSpellCheck.activate;   sE   :FC%**FD9&&v.$f.HIFe..=!!"&"9"9&"AD&&>""5#3#3S$? 11&9  7Cu//d; $ 9 9& A$$;Cu//d;05++S$7r!   c                 $    | j                          y N)_clearStater   s    r   
deactivatezSpellCheck.deactivate\   s    r!   c                     | j                   S r/   r   r1   s    r   getDocumentPositionzSpellCheck.getDocumentPosition_   s    %%%r!   c                     ||f| _         y r/   r4   )r   objoffsets      r   setDocumentPositionzSpellCheck.setDocumentPositionb   s    !$fr!   c                     | j                   S r/   )r   r1   s    r   getErrorWidgetzSpellCheck.getErrorWidgete   s       r!   c                 z    | j                   sy| j                  j                  j                  | j                         S N r   r   	utilitiesdisplayedTextr1   s    r   getMisspelledWordzSpellCheck.getMisspelledWordh   /      ||%%33D4E4EFFr!   c                 z    | j                   sy| j                  j                  j                  | j                         S r=   r?   r1   s    r   getCompletionMessagezSpellCheck.getCompletionMessagen   rC   r!   c                     | j                   S r/   )r   r1   s    r   getChangeToEntryzSpellCheck.getChangeToEntryt   s    """r!   c                     | j                   S r/   )r   r1   s    r   getSuggestionsListzSpellCheck.getSuggestionsListw   s    $$$r!   c                     | j                   S r/   )r   r1   s    r   isActivezSpellCheck.isActivez   s    r!   c                 H    |r|| j                   k(  ry| j                  |      S )NT)r   r-   r   r*   s     r   isCheckWindowzSpellCheck.isCheckWindow}   s"    f,}}V$$r!   c                 B    t        j                  | j                         S r/   )r   is_sensitiver   r1   s    r   
isCompletezSpellCheck.isComplete   s    ++D,?,?@@@r!   c                      yNF )r   events     r   isAutoFocusEventzSpellCheck.isAutoFocusEvent       r!   c                 h    | j                   sy|xr" t        j                  |      | j                   k(  S rS   )r   r
   
get_parent)r   r7   s     r   isSuggestionsItemzSpellCheck.isSuggestionsItem   s/    $$Hx**3/43H3HHHr!   c                    | j                         sy| j                  \  }}|r|dk\  syt        j                  ||      d   }|spt        j                  ||      d   }t        j                  d|      }| j                         |j                        dk(  rt        t        fd|            }|d   }|syt        j                  |z  }| j                  j                  j                  |      }| j                  j!                  ||       y)	NFr   z(?:\.|\!|\?)   c                 &    | j                        S r/   )count)xwords    r   <lambda>z+SpellCheck.presentContext.<locals>.<lambda>   s    aggdm r!   stringvoiceT)rK   r   r   get_sentence_at_offsetget_line_at_offsetresplitrB   r^   listfilterr   MISSPELLED_WORD_CONTEXTr   speechGeneratorre   speakMessage)	r   r7   r8   rc   	sentencesmatchr,   re   r`   s	           @r   presentContextzSpellCheck.presentContext   s    }},,V! ..sF;A>..sF;A>F&9I))+D||D!Q&V$;YGHq..7,,22#2>!!#U!3r!   c                     | j                         r| j                         sy| j                  j                          | j	                         }| j                  j
                  j                  |      }| j                  j                  ||       y)NFrb   rd   T)rK   rQ   r   clearBraillerE   rm   re   presentMessage)r   r,   re   s      r   presentCompletionMessagez#SpellCheck.presentCompletionMessage   sl    DOO$5!!#''),,22#2>##Cu#5r!   c                     | j                         ry| j                  |      rG| j                  |       |s#t        j                         j                  d      r| j                          yy)NFspellcheckPresentContextT)rQ   presentMistakepresentSuggestionr	   
getManager
getSettingrq   )r   detaileds     r   presentErrorDetailszSpellCheck.presentErrorDetails   sX    ??x(""8,+668CCD^_##%r!   c                 x   | j                         sy| j                         }|syt        j                  |z  }| j                  j
                  j                  |      }| j                  j                  ||       |s#t        j                         j                  d      r| j                  j                  |       y)NFrb   rd   spellcheckSpellErrorT)rK   rB   r   MISSPELLED_WORDr   rm   re   rn   r	   rz   r{   spellCurrentItem)r   r|   r`   r,   re   s        r   rx   zSpellCheck.presentMistake   s    }}%%'&&-,,22#2>!!#U!3'224??@VWLL))$/r!   c                 \   | j                   s| j                  |d      S | j                         sy| j                  }|sy| j                  j
                  j                  |      xs t        j                  |      }| j                  j
                  j                  |dd      }| d| }| j                  j                  j                  |      }| j                  j                  ||       |s#t        j                         j                  d	      r| j                  j!                  |       y)
NT)includeLabelFr   r    rb   rd   spellcheckSpellSuggestion)r   presentSuggestionListItemrK   r   r   r@   displayedLabelr
   get_name	substringrm   re   rn   r	   rz   r{   r   )r   r|   entrylabelrc   r,   re   s          r   ry   zSpellCheck.presentSuggestion   s    %%11(1NN}}##&&55e<X@Q@QRW@X''11%B?q!,,22#2>!!#U!3'224??@[\LL))&1r!   c                    | j                         sy| j                  }|sy| j                  j                  j	                  |      }t        |      dk(  sy|r=| j                  j                  j                  |      xs t        j                  |      }nd}t        j                  |d         }| d| }| j                  j                  j                  |      }| j                  j                  |j                         |       |s#t        j                         j                  d      r| j                  j!                  |       t        j                         j                  d	      rp|d   t#        j                         j%                         k(  rH| j'                  |d         \  }	}
t(        j*                  |	|
d
z  }| j                  j                  |       y)NFr\   r>   r   r   rb   rd   r   enablePositionSpeaking)indextotalT)rK   r   r   r@   selectedChildrenlenr   r
   r   rm   re   rn   stripr	   rz   r{   r   r   get_locus_of_focus_getSuggestionIndexAndPositionr   GROUP_INDEX_SPEECH)r   r|   r   suggestionsitemsr   rc   r,   re   r   r   s              r   r   z$SpellCheck.presentSuggestionListItem   s   }}++&&77D5zQLL**99+F 2$$[1  E""58,q!,,22#2>!!#))+U!;'224??@[\LL))&1&&(334LMQx=335HHJJ>>uQxHLE5#665SX9YYCLL%%c*r!   c                 J    d | _         d | _        d | _        d | _        d| _        y rS   )r   r   r   r   r   r1   s    r   r0   zSpellCheck._clearState  s(     " $r!   c                      yrS   rT   rM   s     r   r%   zSpellCheck._isCandidateWindow  rW   r!   c                      y r/   rT   r   roots     r   r&   zSpellCheck._findChangeToEntry      r!   c                      y r/   rT   r   s     r   r(   zSpellCheck._findErrorWidget  r   r!   c                      y r/   rT   r   s     r   r)   zSpellCheck._findSuggestionsList  r   r!   c                      y)N)r   r   rT   )r   
suggestions     r   r   z)SpellCheck._getSuggestionIndexAndPosition  s    r!   c                    ddl m} |j                         }|j                  dt        j
                   d      }|j                  d       |j                  |       |j                  j                  dddd      }|j                  ddd	d       |j                  |       |j                         }|j                  |       t        j                  }t        j                         j!                  d
      }|j"                  j%                  |      | _        | j&                  j)                  |       |j+                  | j&                  dddd       t        j,                  }t        j                         j!                  d      }|j"                  j%                  |      | _        | j.                  j)                  |       |j+                  | j.                  dddd       t        j0                  }t        j                         j!                  d      }|j"                  j%                  |      | _        | j2                  j)                  |       |j+                  | j2                  dddd       |S )Nr   )Gtkz<b>z</b>)r   Tg      ?r\      r   r   rw      )gi.repositoryr   FrameLabelr   SPELL_CHECKset_use_markupset_label_widget	Alignmentnewset_paddingaddGridSPELL_CHECK_SPELL_ERRORr	   rz   r{   CheckButtonnew_with_mnemonicr   
set_activeattachSPELL_CHECK_SPELL_SUGGESTIONr   SPELL_CHECK_PRESENT_CONTEXTr   )r   r   framer   	alignmentgridvalues          r   getAppPreferencesGUIzSpellCheck.getAppPreferencesGUI  s   %				#i&;&;%<D A	BT"u%MM%%c315	aB*		)xxzd11 ++-889OP%(__%F%Fu%M"""--e4D..1a;66 ++-889TU*-//*K*KE*R'''2259D33Q1a@55 ++-889ST),)J)J5)Q&&&11%8D22Aq!Q?r!   c                     | j                   j                         | j                  j                         | j                  j                         dS )z7Returns a dictionary with the app-specific preferences.)r   r   rw   )r   
get_activer   r   r1   s    r   getPreferencesFromGUIz SpellCheck.getPreferencesFromGUI?  sD     %)$>$>$I$I$K)-)H)H)S)S)U(,(F(F(Q(Q(S
 	
r!   N)T)F)FF) __name__
__module____qualname__r    r-   r2   r5   r9   r;   rB   rE   rG   rI   rK   rN   rQ   rV   rZ   rq   ru   r}   rx   ry   r   r0   r%   r&   r(   r)   r   r   r   rT   r!   r   r   r   +   s    .B&-!GG#%%AI4
 *B "H
r!   r   )__doc____id____version____date____copyright____license__rh   orcar   r   r   r   r   r	   orca.ax_objectr
   orca.ax_textr   orca.ax_utilitiesr   r   rT   r!   r   <module>r      sN   , A	1 	     " ! #  )[
 [
r!   