
    g
f`                     h   d Z dZdZdZdZdZddlmZ ddlZ ej                  d	d
       ddlm
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 i Zi ZdZdZde
j,                  j.                  z  Zde
j,                  j2                  z  Zdez  Zdez  de
j,                  j.                  z  z  Zdez  de
j,                  j2                  z  z  Zdez  de
j,                  j2                  z  z  de
j,                  j.                  z  z  Zdez  de
j,                  j>                  z  z  Z dez  de
j,                  j.                  z  z  de
j,                  j>                  z  z  Z!de
j,                  j>                  z  Z"de
j,                  j>                  z  de
j,                  j.                  z  z  Z#de
j,                  j2                  z  de
j,                  j.                  z  z  Z$de
j,                  j>                  z  de
j,                  j2                  z  z  de
j,                  j.                  z  z  Z%de
j,                  j.                  z  de
j,                  j2                  z  z  de
j,                  jL                  z  z  de
j,                  jN                  z  z  Z(de
j,                  j>                  z  de
j,                  j.                  z  z  de
j,                  j2                  z  z  de
j,                  jL                  z  z  de
j,                  jN                  z  z  dez  z  Z)e)Z*d Z+d Z,d Z- G d d      Z. G d d      Z/y)zLProvides support for defining keybindings and matching them to input
events.z$Id$z
$Revision$z$Date$z-Copyright (c) 2005-2008 Sun Microsystems Inc.LGPL    )GdkNAtspiz2.0)r      )debug)settings)
orca_state_   c                    | sy| t         vrt        j                  j                         }t        j                  |       }|dk(  rydt         | <   |j                  |      \  }}|D ]Q  }|j                  dk(  r|j                  t         | <    t         |    S t         |    dk(  s<|d   j                  t         | <   S t         |    S )a  Converts an XKeysym string (e.g., 'KP_Enter') to a keycode that
    should match the event.hw_code for key events.

    This whole situation is caused by the fact that Solaris chooses
    to give us different keycodes for the same key, and the keypad
    is the primary place where this happens: if NumLock is not on,
    there is no telling the difference between keypad keys and the
    other navigation keys (e.g., arrows, page up/down, etc.).  One,
    for example, would expect to get KP_End for the '1' key on the
    keypad if NumLock were not on.  Instead, we get 'End' and the
    keycode for it matches the keycode for the other 'End' key.  Odd.
    If NumLock is on, we at least get KP_* keys.

    So...when setting up keybindings, we say we're interested in
    KeySyms, but those keysyms are carefully chosen so as to result
    in a keycode that matches the actual key on the keyboard.  This
    is why we use KP_1 instead of KP_End and so on in our keybindings.

    Arguments:
    - keysym: a string that is a valid representation of an XKeysym.

    Returns an integer representing a key code that should match the
    event.hw_code for key events.
    r   )_keycodeCacher   Keymapget_defaultkeyval_from_nameget_entries_for_keyvalgroupkeycode)keysymkeymapkeyvalsuccessentriesentrys         2/usr/lib/python3/dist-packages/orca/keybindings.py
getKeycoder   S   s    4 ]"'') %%f-Q; !"f!88@ 	;E{{a(-f%    V$)(/
(:(:f%	;       c                    d}| t         z  rEt        j                  t        j                  k(  r|t	        d      dz   z  }nC|t	        d      dz   z  }n1| dt
        j                  j                  z  z  r|t	        d      dz   z  }| dz  r|t	        d      dz   z  }| dt
        j                  j                  z  z  r|t	        d      dz   z  }| dt
        j                  j                  z  z  r|t	        d	      dz   z  }| t        z  r|t	        d
      dz   z  }| t        z  r|t	        d      dz   z  }| t        z  r|t	        d      dz   z  }|S )zYGets the modifier names of a numeric modifier mask as a human
    consumable string.
     Insert+	Caps_Lockr      Alt_RSuperMeta2AltCtrlShift)ORCA_MODIFIER_MASKr   keyboardLayoutGENERAL_KEYBOARD_LAYOUT_DESKTOPr   r   ModifierType	SHIFTLOCKMETA3META2ALT_MODIFIER_MASKCTRL_MODIFIER_MASKSHIFT_MODIFIER_MASK)modstexts     r   getModifierNamesr6      sW   
 D  ""h&N&NN AhK#%%D AkNS((D	e((222	3 	+$$ cz 	'
S  qE&&,,,- 	'
S  qE&&,,,- 	'
S    	%3   	&	C!! 	'
S  Kr   c                 D    | dk(  rt        d      S | dk(  rt        d      S y)zsReturns a human-consumable string representing the number of
    clicks, such as 'double click' and 'triple click'.   zdouble click   ztriple clickr   r
   )counts    r   getClickCountStringr;      s/     z
   z
   r   c                   V    e Zd 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y)
KeyBindingzcA single key binding, consisting of a keycode, a modifier mask,
    and the InputEventHandler.
    c                 t    || _         || _        || _        || _        || _        d| _        || _        g | _        y)a  Creates a new key binding.

        Arguments:
        - keysymstring: the keysymstring - this is typically a string
          from /usr/include/X11/keysymdef.h with the preceding 'XK_'
          removed (e.g., XK_KP_Enter becomes the string 'KP_Enter').
        - modifier_mask: bit mask where a set bit tells us what modifiers
          we care about (see Atspi.ModifierType.*)
        - modifiers: the state the modifiers we care about must be in for
          this key binding to match an input event (see also
          Atspi.ModifierType.*)
        - handler: the InputEventHandler for this key binding
        - enabled: Whether this binding can be bound and used, i.e. based
          on mode, the feature being enabled/active, etc.
        N)keysymstringmodifier_mask	modifiershandlerclick_countr   _enabled	_grab_ids)selfr?   r@   rA   rB   rC   enableds          r   __init__zKeyBinding.__init__   s?    $ )*"&r   c           	         | j                   sd| j                   dS | j                  rd| j                   d}nd| j                   d}| d| j                    d| j                   d| j                   d| j
                   	S )	NzUNBOUND BINDING for ''zENABLED BINDING for 'zDISABLED BINDING for ': z mods=z clicks=z
 grab ids=)r?   rB   rD   rA   rC   rE   )rF   strings     r   __str__zKeyBinding.__str__   s      *4<<.::==,T\\N!<F-dll^1=Fhb**+6$..1A$JZJZI[ \')	
r   c                     | j                   st        | j                        | _         | j                   |k(  r|| j                  z  }|| j                  k(  S y)z_Returns true if this key binding matches the given keycode and
        modifier state.
        F)r   r   r?   r@   rA   )rF   r   rA   results       r   matcheszKeyBinding.matches  sK     ||%d&7&78DL<<7"!3!33FT^^++r   c                     | j                   S )z+Returns True if this KeyBinding is enabled.rD   rF   s    r   
is_enabledzKeyBinding.is_enabled  s     }}r   c                     || _         y)z$Set this KeyBinding's enabled state.NrR   )rF   rG   s     r   set_enabledzKeyBinding.set_enabled  s      r   c                 N    	 | j                   j                  S # t        $ r Y yw xY w)z8Returns the description of this binding's functionality.r   )rB   description	ExceptionrS   s    r   rX   zKeyBinding.description  s)    	<<+++ 		s    	$$c                     t        | j                        }t        | j                        }| j                  }| | d| }|j                         S )zAReturns a more human-consumable string representing this binding. )r6   rA   r;   rC   r?   strip)rF   r4   
clickCountr   rL   s        r   asStringzKeyBinding.asString&  sM      /()9)9:
""6&:,/||~r   c                 (   g }| j                   st        | j                        | _         | j                  t        z  rt
        j                  }||S g }| j                  t         z  }t        j                  D ]G  }t        |      }|dk(  r|dk(  rt        d      }|j                  |      }|j                  ||z         I n| j                  g}|D ]?  }t        j                         }| j                   |_         ||_        |j                  |       A |S )z return a list of Atspi key definitions for the given binding.
            This may return more than one binding if the Orca modifier is bound
            to more than one key.
        r   
Shift_Lockr"   )r   r   r?   rA   r*   r	   devicer   orcaModifierKeysmap_modifierappendr   KeyDefinition)	rF   retra   modList	otherModskeyr   modkds	            r   keyDefszKeyBinding.keyDefs0  s    
 ||%d&7&78DL>>..&&F~
G*<)<<I00 0$S/a<C<$7(5G))'2sY/0 ~~&G 	C$$&BBJBLJJrN		
 
r   c                 ,    t        | j                        S )zIReturns True if there are existing grabs associated with this KeyBinding.)boolrE   rS   s    r   hasGrabszKeyBinding.hasGrabsN  s     DNN##r   c                 H   | j                   r| j                  syt        j                  y| j	                         D ];  }| j
                  j                  t        j                  j                  |d             = d|  }t        j                  t        j                  |d       y)z#Adds key grabs for this KeyBinding.NzGRABS ADDED: T)r?   rD   r	   ra   rl   rE   rd   add_key_grabr   printMessage
LEVEL_INFO)rF   rk   msgs      r   addGrabszKeyBinding.addGrabsS  s     !!dmm$,,. 	LBNN!!*"3"3"@"@T"JK	L dV$5++S$7r   c                 P   | j                   r9t        j                  s)d}t        j                  t        j
                  |dd       y| j                   D ]!  }t        j                  j                  |       # g | _         d|  }t        j                  t        j                  |d       y)z&Removes key grabs for this KeyBinding.z+WARNING: Have grab to remove but no device.TNzGRABS REMOVED: )rE   r	   ra   r   rr   LEVEL_WARNINGremove_key_grabrs   )rF   rt   ids      r   removeGrabszKeyBinding.removeGrabsb  s     >>*"3"3?Cu22CtD.. 	2B--b1	2v&5++S$7r   N)r   T)__name__
__module____qualname____doc__rH   rM   rP   rT   rV   rX   r^   rl   ro   ru   rz    r   r   r=   r=      sC    
 +/6

$
 
<$
88r   r=   c                   ~    e Zd ZdZd Zd ZddZddZd ZddZ	ddZ
d	 Zd
 ZddZddZddZd Zd Zd Zd Zy)KeyBindingsz<Structure that maintains a set of KeyBinding instances.
    c                     g | _         y NkeyBindingsrS   s    r   rH   zKeyBindings.__init__u  s
    r   c                 <    d}| j                   D ]
  }|| dz  } |S )Nr   
r   )rF   rO   
keyBindings      r   rM   zKeyBindings.__str__x  s2    ** 	(JB''F	(r   c                 0   |j                   r\| j                  |d      rJd|j                          d|j                          d}t	        j
                  t        j                  |d       | j                  j                  |       |r|j                          yy)zOAdds KeyBinding instance to this set of keybindings, optionally updating grabs.
keysNoMaskKEYBINDINGS: '' (z) already in keybindingsTN)
r?   hasKeyBindingr^   rX   r   rr   rs   r   rd   ru   )rF   r   includeGrabsrt   s       r   addzKeyBindings.add~  s     ""t'9'9*l'S
 3 3 56 7))+,,DF  u//d;
+! r   c                    || j                   vr|| j                  |j                        }|syd|d|g}t        j                  t        j
                  |d       | j                  |j                        D ]  }| j                  ||        y|j                         r=|r|j                          n*d|dg}t        j                  t        j
                  |d       | j                   j                  |       y)zKRemoves KeyBinding from this set of keybindings, optionally updating grabs.Nz5KEYBINDINGS: Warning: No binding in set to remove forzAlternates:TzKEYBINDINGS: Warning:zwill be removed but has grabs.)	r   getBindingsForHandlerrB   r   printTokensrw   removero   rz   )rF   r   r   
candidatestokens	candidates         r   r   zKeyBindings.remove  s     T---33J4F4FGJ
  Nz#Z1Fe1164@!77
8J8JK 5	I|45 &&( 2:?_`!!%"5"5vtD
+r   c                     | j                    S )zAReturns True if there are no bindings in this set of keybindings.r   rS   s    r   isEmptyzKeyBindings.isEmpty  s     ####r   c                     d}|r|d| z  }t        j                  t         j                  |d       | j                  D ]4  }|j	                         s|j                         r%|j                          6 y)z?Adds grabs for all enabled bindings in this set of keybindings.zKEYBINDINGS: Adding key grabsrK   TN)r   rr   rs   r   rT   ro   ru   rF   reasonrt   bindings       r   addKeyGrabszKeyBindings.addKeyGrabs  sl     .Rx= C5++S$7'' 	#G!!#G,<,<,>  "	#r   c                     d}|r|d| z  }t        j                  t         j                  |d       | j                  D ]#  }|j	                         s|j                          % y)z.Removes all grabs for this set of keybindings.zKEYBINDINGS: Removing key grabsrK   TN)r   rr   rs   r   ro   rz   r   s       r   removeKeyGrabszKeyBindings.removeKeyGrabs  sa     0Rx= C5++S$7'' 	&G!##%	&r   c                 H    | j                   D ]  }|j                  |k(  s y y)z@Returns True if the handler is found in this set of keybindings.TFr   rB   rF   rB   r   s      r   
hasHandlerzKeyBindings.hasHandler  s-     '' 	G')	 r   c                 ~    | j                   D ].  }|j                  |k(  s|j                  j                         s. y y)zOReturns True if the handler is found in this set of keybindings and is enabled.TF)r   rB   rT   r   s      r   hasEnabledHandlerzKeyBindings.hasEnabledHandler  s<     '' 	G')goo.H.H.J	 r   c                    | j                   D ]  }|dk(  r|j                  s|j                  s#|j                  j                  |j                  j                  k(  sQ|j                  |j                  k(  sk|j                  |j                  k(  s|j
                  |j
                  k(  s|j                  |j                  k(  s y|dk(  rK|j                  s|j                  s|j                  j                  |j                  j                  k(  s	 y|dk(  rn|j                  |j                  k(  s+|j                  |j                  k(  sF|j
                  |j
                  k(  sa|j                  |j                  k(  s| y|dk(  s|j                  |j                  k(  s|j
                  |j
                  k(  s|j                  |j                  k(  s y y)a  Return True if keyBinding is already in self.keyBindings.

           The typeOfSearch can be:
              "strict":      matches description, modifiers, key, and click count
              "description": matches only description
              "keys":        matches the modifiers, key, modifier mask, and click count
              "keysNoMask":  matches the modifiers, key, and click count
        strictTrX   keysr   F)r   rB   rX   r?   r@   rA   rC   )rF   newKeyBindingtypeOfSearchr   s       r   r   zKeyBindings.hasKeyBinding  s    ** 	 Jx'%%-*?*?!))559N9N9Z9ZZ!..-2L2LL!//=3N3NN!++}/F/FF!--1J1JJ.%%-*?*?!))559N9N9Z9ZZ'**m.H.HH!//=3N3NN!++}/F/FF!--1J1JJ-**m.H.HH!++}/F/FF!--1J1JJ/	 2 r   c                    | j                   D cg c]  }|j                  s| }}|rR|D cg c]  }|j                  j                   }}t	        |j
                  t        |            D cg c]  }||   	 }}i }|D ]s  }|j                         }|j                  |      }|;d|d|j                         d|g}	t        j                  t        j                  |	d       |j                         ||<   u |S c c}w c c}w c c}w )zReturns the KeyBinding instances which are bound to a keystroke.

        Arguments:
        - uniqueOnly: Should alternative bindings for the same handler be
          filtered out (default: False)
        z
WARNING: 'r   z) also matches:T)r   r?   rB   rX   mapindexsetr^   getr   r   rs   )
rF   
uniqueOnlykbboundhandlersibindingsrL   matchr   s
             r   getBoundBindingszKeyBindings.getBoundBindings  s     #..B"//BB9>?2

..?H?'*8>>3x='IJ!U1XJEJ 	0B[[]FLL(E &r~~7GIZ\ab!!%"2"2FDA!~~/HV	0  C?Js   C7C7C<-Dc                 f   |r)| j                   D cg c]  }|j                  s| }}d}n| j                   }d}|D cg c]  }|j                         s| }}dt        |       d| dt        | j                          d}t	        j
                  t        j                  |d       |S c c}w c c}w )z>Returns the KeyBindings instances which can be bound and used.zbound bindingsr   zKEY BINDINGS: r[   z found out of .T)r   r?   rT   lenr   rr   rs   )rF   	boundOnlyr   r   boundStringrG   rt   s          r   getEnabledBindingszKeyBindings.getEnabledBindings  s     %)%5%5IrIHI*K''H$K (<"BMMO2<<s7|nAk].TM]M]I^H__`a5++S$7 J =s   B)B)B.B.c                 `    | j                   D cg c]  }|j                  |k(  s| c}S c c}w )z9Returns the KeyBinding instances associated with handler.r   )rF   rB   r   s      r   r   z!KeyBindings.getBindingsForHandler&  s)     "--Grw1FGGGs   ++c           	      l   t         j                  t         j                  kD  ry t        |      dk  ry t        t	        t        d |                  t        |      k(  ry d }d|j                          ddj                  t        ||             }t        j                  t         j                  |d       y )Nr   c                     | j                   S r   rC   xs    r   <lambda>z4KeyBindings._checkMatchingBindings.<locals>.<lambda>4  s
     r   c                 :    | j                    d| j                   dS )Nz (zx))rB   rC   r   s    r   toStringz4KeyBindings._checkMatchingBindings.<locals>.toString7  s    ii[1==/44r   r   z' matches multiple handlers: z, T)	r   
debugLevelrs   r   r   r   asSingleLineStringjoinrr   )rF   keyboardEventrO   r   rt   s        r   _checkMatchingBindingsz"KeyBindings._checkMatchingBindings+  s    e... v;! s3.789S[H	5 ]==?@ A**.))C&4I*J)KM 	 	5++S$7r   c                 V   g }g }|j                         }| j                  D ]  }|j                  |j                  |j                        s*|j
                  |j                  k(  r |j                  |k(  r|j                  |       |j                  sp|j                  |        d|j                          d|g}t        j                  t        j                  |d       | j                  ||       |r|d   j                  S |j                         ryd|j                          d|g}t        j                  t        j                  |d       |j!                  t#        j$                  d              | j                  ||       |D ]  }|j                  |k  s|j                  c S  y)	zReturns the input handler of the key binding that matches the
        given keycode and modifiers, or None if no match exists.
        zKEYBINDINGS: z matchesTr   Nz fallback candidatesc                 4    |j                   | j                   z
  S r   r   )r   ys     r   r   z-KeyBindings.getInputHandler.<locals>.<lambda>e  s    ammamm>[ r   )ri   )getClickCountr   rP   hw_coderA   r@   rC   rd   r?   r   r   r   rs   r   rB   isKeyPadKeyWithNumlockOnsort	functools
cmp_to_key)rF   r   rP   r   r]   r   r   r   s           r   getInputHandlerzKeyBindings.getInputHandler@  s   
 
"002
** 		2J!!-"7"79P9PQ++}/F/FF))Z7NN:. **%%j1		2 "-"B"B"D!EXNPWX%**FD9##M7;1:%%%113!-"B"B"D!EEYZ%**FD9 	I001[\]##M:># 	)I$$
2 (((	) r   c           
         |D ]l  }|d   }|d   }|d   }|d   }	 |d   }||v r"| j                  t        |||||   |             Cd|dg}	t        j                  t        j
                  |	d       n y	# t         $ r d}Y `w xY w)
a4   Takes the keymappings and tries to find a matching named
           function in handlers.
           keymap is a list of lists, each list contains 5 elements
           If addUnbound is set to true, then at the end of loading all the
           keybindings, any remaining functions will be unbound.
        r   r   r8   r9      zKEYBINDINGS: Could not findzhandler for keybinding.TN)rY   r   r=   r   r   rs   )
rF   r   r   r   r?   modifierMaskrA   rB   r]   r   s
             r   loadzKeyBindings.loadm  s      	BAQ4LQ4L!IdGqT
 (" ,	8G;LjZ [ 8B[\!!%"2"2FDA	B  
s   A33B BN)F)r   )r   )r{   r|   r}   r~   rH   rM   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   q  s[    ",>$

#
&#J0H
8*+ZBr   r   )0r~   __id____version____date____copyright____license__gi.repositoryr   girequire_versionr   r   r   r   r   r	   	orca_i18nr   _keysymsCacher   MODIFIER_ORCANO_MODIFIER_MASKr-   ALTr1   CONTROLr2   r*   ORCA_ALT_MODIFIER_MASKORCA_CTRL_MODIFIER_MASKORCA_CTRL_ALT_MODIFIER_MASKSHIFTORCA_SHIFT_MODIFIER_MASKORCA_ALT_SHIFT_MODIFIER_MASKr3   SHIFT_ALT_MODIFIER_MASKCTRL_ALT_MODIFIER_MASKSHIFT_ALT_CTRL_MODIFIER_MASKr0   r/   COMMAND_MODIFIER_MASKNON_LOCKING_MODIFIER_MASKdefaultModifierMaskr   r6   r;   r=   r   r   r   r   <module>r      sv  ( ?  	   7E "      !" !"e&8&8&<&<!< !"e&8&8&@&@!@ !"m!3 !"m!3!"e&8&8&<&<!<"= !"m!3!"e&8&8&@&@!@"A !"m!3!"e&8&8&@&@!@"A!"e&8&8&<&<!<"=  "#m!3!"e&8&8&>&>!>"? !"m!3!"e&8&8&<&<!<"=!"e&8&8&>&>!>"?  "#e&8&8&>&>!> !"e&8&8&>&>!>!"e&8&8&<&<!<"= !"e&8&8&@&@!@!"e&8&8&<&<!<"= !"e&8&8&>&>!>!"e&8&8&@&@!@"A!"e&8&8&<&<!<"=  "#e&8&8&<&<!<!"e&8&8&@&@!@"A!"e&8&8&>&>!>"? "#e&8&8&>&>!>"?  "#e&8&8&>&>!>!"e&8&8&<&<!<"=!"e&8&8&@&@!@"A "#e&8&8&>&>!>"? "#e&8&8&>&>!>	"?
 "#m!3"4  0 7!r6p$Y8 Y8vVB VBr   