
    g
f3G                        d Z dZdZdZdZdZddlZddlZddlZddl	Z	ddl
Z
ddlZ ej                  dd	        ej                  d
d       ddlmZ ddlmZ 	 ddlmZ  e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  ddlm!Z! ddlm"Z" dd lm#Z# dd!l$m%Z%  ejL                         Z'd" Z(d# Z)d$ Z&d%Z*da+d& Z,d7d(Z-d) Z.d8d*Z/d8d+Z0d8d,Z1d8d-Z2d'a3d. Z4d/ Z5d9d0Z6d8d1Z7d8d2Z8da9d3 Z:d4 Z;d5 Z<e=d6k(  r ej|                   e<              yy# e$ r dZY w xY w):z+The main module for the Orca screen reader.z$Id$z
$Revision$z$Date$zqCopyright (c) 2004-2009 Sun Microsystems Inc.Copyright (c) 2010-2011 The Orca TeamCopyright (c) 2012 Igalia, S.L.LGPL    NAtspiz2.0Gdkz3.0)r   )r   )Settingsz#org.gnome.desktop.a11y.applications)	schema_id   )braille)debug)event_manager)focus_manager)logger)messages)mouse_review)orca_modifier_manager)
orca_state)orca_platform)script_manager)settings)settings_manager)speech)sound)AXObjectc                 l    	 | j                  |      }|dk(  r|st                y y y # t        $ r Y y w xY w)Nzscreen-reader-enabled)get_boolean	Exceptionshutdown)gsettingkeyenableds      +/usr/lib/python3/dist-packages/orca/orca.pyonEnabledChangedr!   E   sE    &&s+ %%g
 /6%  s   ' 	33c                  *    t        j                         S N)r   
getManager     r    getSettingsManagerr'   N   s    &&((r&   c                      t         S r#   )_loggerr%   r&   r    	getLoggerr*   Q   s    Nr&   2   c                     |j                         }|t        j                  j                  k(  r$t	        j
                         j                  d       yy)zHandles device-* signals.zKeyboard change detected.N)
get_sourcer   InputSourceKEYBOARDr   r$   refresh_orca_modifiers)deviceManagerdevicesources      r    deviceChangeHandlerr4   Z   sA      F)))((*AAB]^ *r&   Fc                 
   t        j                  t         j                  dd       t        j                         }|j                          t        j
                          t        j
                          t        j                         j                          d}t        rpt        j                         j                  d      d   }	 t        j                         j                  |      at        j                         j                  |       d}nBt        j                         j(                  }	 t        j                         j                  |      a| s"t        j                         j+                         } t        j                         j-                  |        t        j                         j                  d      r`d}t        j                  t         j                  |d       	 t        j.                          |r!|s| j1                  t2        j4                         n'd}t        j                  t         j                  |d       t        j                         j                  d	      rZd
}t        j                  t         j                  |d       	 t        j.                  t7        j                         j8                         n'd}t        j                  t         j                  |d       t        j                         j                  d      r#t=        j>                         jA                          n"t=        j>                         j                          t        j                         j                  d      r|j/                          tC        j                         jE                  d       t7        j                         jA                          t        j                         jA                          t        j                  t         j                  dd       y# t         $ r' t        j"                  t         j                         Y t$        $ r' t        j"                  t         j&                         Y w xY w# t         $ r' t        j"                  t         j                         Y Mt$        $ r' t        j"                  t         j&                         Y {w xY w# t$        $ r' t        j"                  t         j&                         Y w xY w# t$        $ rN t        j"                  t         j:                         d}t        j                  t         j:                  |d       Y sw xY w)zLoads (and reloads) the user settings module, reinitializing
    things such as speech if necessary.

    Returns True to indicate the input event has been consumed.
    zORCA: Loading User SettingsTFactiveProfiler   enableSpeechzORCA: About to enable speechz'ORCA: Speech is not enabled in settingsenableBraillezORCA: About to enable braillez1ORCA: Could not initialize connection to braille.z(ORCA: Braille is not enabled in settingsenableMouseReviewenableSoundzLoading user settings.zORCA: User Settings Loaded)#r
   printMessage
LEVEL_INFOr   	getPlayerr   r   r	   r   r$   
deactivate_userSettingsr   
getSettinggetGeneralSettings
setProfileImportErrorprintExceptionr   LEVEL_SEVEREprofilegetDefaultScriptloadAppSettingsinitspeakMessager   SETTINGS_RELOADEDr   process_braille_eventLEVEL_WARNINGr   getRevieweractivater   r0   )script
inputEventskipReloadMessageplayerreloaded_profilemsgs          r    loadUserSettingsrW   a   s    
u'')FM __F
OO
OO**,H#..0;;OLQO	5,779LLXVM'')44X>H $..088	5,779LLXVM **,==?!11&9""$//?,5++S$7	5KKM 1##H$>$>? 85++S$7""$//@-5++S$7	?LL113IIJ 95++S$7 ""$//0CD  "++-  "--/""$//> $$&==>VW'')((*	u'')EtL{  	3  !1!12 	5  !3!34	5  	3  !1!12 	5  !3!34	5  	5  !3!34	5  	?  !4!45ECu22C>	?sV   AP +#Q,  7S 
1T  ,Q):+Q)(Q),,S
+S
	S
,S=<S= AUUc                 "   t         j                  rt         j                  j                          y 	 t        j                  dd      }t        j                  j                  t        j                  t        j                  dd      }|j                  |d|      t         _        t         j                  j!                  |        t         j                  j                          y # t
        $ r& t        j                  t        j                         Y y w xY w)Nz.orca_gui_prefsorcauizorca-setup.uiorcaSetupWindow)r   orcaOSshowGUI	importlibimport_moduler   r
   rD   rE   ospathjoinr   datadirpackageOrcaSetupGUIrI   )rP   prefsmoduleuiFiles       r    _showPreferencesUIri      s    !!#(():FC
 WW\\-//'//)+F
 ++F4EuMJ6"  U//0s   C ,DDc                     i }t         j                  D ](  }t        j                         j	                  |      ||<   * | "t        j                         j                         } t        | |       y)zDisplays the user interface to configure the settings for a
    specific applications within Orca and set up those app-specific
    user preferences using a GUI.

    Returns True to indicate the input event has been consumed.
    T)r   userCustomizableSettingsr   r$   r@   r   getActiveScriptri   )rP   rQ   rf   r   s       r    showAppPreferencesGUIrm      sh     E00 C%002==cBc
C ~**,<<>vu%r&   c                     t        j                         j                  t        j                         j                        }t	        j                         j                         } t        | |       y)zDisplays the user interface to configure Orca and set up
    user preferences using a GUI.

    Returns True to indicate the input event has been consumed.
    T)r   r$   rA   rF   r   rG   ri   )rP   rQ   rf   s      r    showPreferencesGUIro      sQ     '')<<=M=X=X=Z=b=bcE&&(99;Fvu%r&   c                     t                y)zQuit Orca. Check if the user wants to confirm this action.
    If so, show the confirmation GUI otherwise just shutdown.

    Returns True to indicate the input event has been consumed.
    T)r   )rP   rQ   s     r    quitOrcarq      s     Jr&   c                     	 t        j                  dd      }|j                          y# t        $ r& t	        j
                  t        j                         Y yw xY w)zzDisplays the user interface to perform an Orca Find.

    Returns True to indicate the input event has been consumed.
    z.orca_gui_findrY   N)r^   r_   
showFindUIr   r
   rD   rE   )rP   rQ   rg   s      r    showFindGUIrt      sI    1(()96B 1U//01s   &) ,AAc                     t        j                  t         j                  dd       t        rHt	        j
                         j                         r&t        j                  t         j                  dd       yt        j                  rht        j                  dkD  rUt        j                  t        j                  t        j                         t        j                  t        j                         t                t        j                  r(t        j                  dkD  rt        j                  d       dat        rt        j                  dt                t        j                  t         j                  dd       y)aB  Initialize the orca module, which initializes the speech and braille
    modules.  Also builds up the application list, registers for AT-SPI events,
    and creates scripts for all known applications.

    Returns True if the initialization procedure has run, or False if this
    module has already been initialized.
    zORCA: InitializingTzORCA: Already initializedFr   changedzORCA: Initialized)r
   r;   r<   _initializedr   r$   isScreenReaderServiceEnabledr   timeoutCallbacktimeoutTimesignalSIGALRMalarmrW   a11yAppSettingsconnectr!   r%   r&   r    rI   rI   	  s     
u'')=tD (335RRT5++-H$O X%9%9A%=fnnh&>&>?X))*X%9%9A%=QL 	+;<	u'')<dCr&   c                  j   t        j                  t         j                  dd       t        s
t	                t
        j                  rht
        j                  dkD  rUt        j                  t        j                  t
        j                         t        j                  t
        j                         t
        j                  r(t
        j                  dkD  rt        j                  d       t        j                  j                         } | j                         }|j                  dt                |j                  dt                t        j"                          d}t        j                  t         j                  |d       t        j                  t         j                  dd       t%        j&                          y)	zStarts Orca.zORCA: StartingTr   zdevice-addedzdevice-removedz(ORCA: Startup complete notification madez$ORCA: Starting Atspi main event loopN)r
   r;   r<   rw   rI   r   ry   rz   r{   r|   r}   r   Displayget_defaultget_device_managerr   r4   notify_startup_completer   
event_main)display
devmanagerrV   s      r    startr   0  s    
u'')94@ X%9%9A%=fnnh&>&>?X))*X%9%9A%=Q kk%%'G))+J~':;')<=!
4C	u''d3	u'')OQUV	r&   c                    t        j                         }| t        k(  r%t        j                  |t        j
                         y t                t        j                  |        | dkD  r%t        j                  |t        j                         y y )Nr   )
r`   getpidEXIT_CODE_HANGkillr{   SIGKILLr   sysexitSIGTERM)exitCodepids     r    dier   N  sY    
))+C>!
V^^$JHHX!|
V^^$ r&   c                     d}t        j                  t         j                  |d       t        j                  t         j                         t        j                  d       t        t               y )Nz&TIMEOUT: something has hung. Aborting.T)force)r
   r;   rE   
printStackexamineProcessesr   r   )signumframerV   s      r    timeoutr   Z  sI    
2C	u))35	U''(	&r&   c                 6   t        j                  t         j                  dd       t        syt        j
                  rht        j                  dkD  rUt        j                  t        j                  t        j
                         t        j                  t        j                         t        j                         j                         } | 1| j                          | j                  t        j                   d       t#        j                         j%                  ddd       t        j                         j'                          t#        j                         j'                          t        j(                  rt+        j,                          t        j.                  rt1        j,                          t        j2                  r$t5        j6                         }|j-                          t        j
                  r(t        j                  dkD  rt        j                  d       dat9        j                         j;                  d       t        j                  t         j                  dd       t=        j>                          t        j                  t         j                  dd       y)	zExits Orca.  Unregisters any event listeners and cleans up.

    Returns True if the shutdown procedure ran or False if this module
    was never initialized.
    zORCA: Shutting downTFr   resetStyleszShutting down.z$ORCA: Quitting Atspi main event loopzORCA: Shutdown complete) r
   r;   r<   rw   r   ry   rz   r{   r|   r}   r   r$   rl   presentationInterruptpresentMessager   	STOP_ORCAr   pauseQueuingr>   r7   r   r   r8   r	   r:   r   r=   r   unset_orca_modifiersr   
event_quit)rP   rQ   rS   s      r    r   r   a  s    
u'')>E  X%9%9A%=fnnh&>&>?X))*&&(88:F$$&h00eD ++D$8HI**,))+ "X%9%9A%=QL$$&;;<LM	u'')OQUV		u'')BDIr&   c                    dt        j                  |        d}d|  d| }t        j                  t        j                  |d       t
        rt        |        n	t
        dz  at        j                  rht        j                  dkD  rUt        j                   t         j                  t        j                         t        j                  t        j                         	 t        rt                nt        j                          t                d}t        j                  r(t        j                  dkD  rt        j                  d       |st        t                y y # t        $ r d}Y Xw xY w)	N().ORCA: Shutting down and exiting due to signal= Tr   r   F)r{   	strsignalr
   r;   r<   	exitCountr   r   ry   rz   r|   r}   rw   r   r   r   r   )r   r   signalStringrV   	cleanExits        r    shutdownOnSignalr     s    v''/02L:6(!L>
RC	u''d3
 FQ	 X%9%9A%=fnnh&>&>?X))*J
 OOJ	 X%9%9A%=QN   	s   1E E%$E%c                    dt        j                  |        d}d|  d| }t        j                  t        j                  |d       t        j
                  t        j                         t        j                         j                  d| d       t        j                         j                         }|1|j                          |j                  t        j                  d	       t        j                   d
       y )Nr   r   r   r   TzShutting down: .Fr   r   )r{   r   r
   r;   rE   r   r   r$   r   r   rl   r   r   r   r   r   r   )r   r   r   rV   rP   s        r    crashOnSignalr     s    v''/02L:6(!L>
RC	u))35	U''($$&;;ol^[\<]^&&(88:F$$&h00eDHHQKr&   c                  
   dt         j                   } t         j                  r| dt         j                   dz  } t        j                         }| d|d    d|d    d|d    z  } t
        j                  j                  d	      xs d
}t
        j                  j                  d      xs d
}dj                         ||fz  }|r| d| z  } t        j                  t        j                  | d       t        j                  r]t
        j                  j                  t        j                  j                        r&t!        j"                  t        j                  d       nt!        j"                  d       t$        t&        _        t+        j*                  t*        j,                  t.               t+        j*                  t*        j0                  t.               t+        j*                  t*        j2                  t.               t+        j*                  t*        j4                  t.               t+        j*                  t*        j6                  t8               t        j                  t        j                  dd       t;        j<                         j?                         s#t;        j<                         jA                  d       t        j                  t        j                  dd       tC                t        j                  t        j                  dd       	 tE        j<                         jG                         }|jI                  tJ        jL                         tU        j<                         jW                         }|rJtU        j<                         jY                         s't[        j\                  |      }tE        j<                         j_                  ||      }tE        j<                         ja                  |d       tU        j<                         jc                  ||dd       tU        j<                         je                         }|rtU        j<                         jg                  d|       tE        j<                         j_                  t[        j\                  |      |      }tE        j<                         ja                  |d       	 d} t        j                  t        j                  | d       ti                y# tN        $ r' t        jP                  t        jR                         Y w xY w# tN        $ r9 d} t        j                  t        jR                  | d       tk        tl               Y yw xY w)a1  The main entry point for Orca.  The exit codes for Orca will
    loosely be based on signals, where the exit code will be the
    signal used to terminate Orca (if a signal was used).  Otherwise,
    an exit code of 0 means normal completion and an exit code of 50
    means Orca exited because of a hang.zORCA: Launching version z (rev r   z AT-SPI2 version: r   r   r      XDG_SESSION_TYPE XDG_SESSION_DESKTOPz%s %sz
 Session: T)fileall_threadsF)r   z)ORCA: Enabling accessibility (if needed).zORCA: Initializing.zORCA: Initialized.z
Launching.)set_window_as_focusnotify_scriptNzFound focused object.zORCA: Starting ATSPI registry.z(ORCA: Exception starting ATSPI registry.)7r   versionrevisionr   get_versionr`   environgetstripr
   r;   r<   	debugFilera   existsnamefaulthandlerenabler   r   ry   r{   SIGHUPr   SIGINTr   SIGQUITSIGSEGVr   r   r$   isAccessibilityEnabledsetAccessibilityrI   r   rG   r   r   
START_ORCAr   rD   rE   r   find_active_windowget_locus_of_focusr   get_application	getScriptsetActiveScriptset_active_windowfind_focused_objectset_locus_of_focusr   r   r   )	rV   atspiVersionsessionTypesessionDesktopsessionrP   windowappfocusedObjects	            r    mainr     s    %]%:%:$;
<C../q11$$&LQ0,q/1B!LQROCTUUC**..!34:KZZ^^$9:@bNmmon ==GG9%%	u''d3277>>%//*>*>?dC.  'H MM&--!12
MM&--!12
MM&.."23
MM&.."23
MM&..-0	u'')TVZ[&&(??A##%66t<	u'')>EF	u'')=tD1**,==?h112 %%'::<Fm..0CCE&&v.  **,66sFC!!#33FLI  "44CT 	5 	G &002FFH$$&99$N#..0::((7HF%%'77@WX.5++S$7
 ;  1U//012  85--sD9N	s%   	AS, :1T ,,TT?U! U!__main__)NNF)NN)r   )?__doc____id____version____date____copyright____license__r   gir^   r`   r{   r   require_versiongi.repositoryr   r   gi.repository.Gior   r~   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   	ax_objectr   r*   r)   r!   r'   r   r?   r4   rW   ri   rm   ro   rq   rt   rw   rI   r   r   r   r   r   r   r   r   __name__r   r%   r&   r    <module>r      sl  , 22   	  	  
   7E "   5%    *)NOO        #        
&


)  _Xt ($	
1 %N<
%5n 	&PM^ zCHHTV _  Os   D< <EE