+
     i-  c                  s   R t ^ RIHt ^ RIt^ RIt^ RIHtHtHtH	t	H
t
HtHtHtHt ^ RIHt  ^ RIHt ^ RIHtHt ^ RIHtHt ^ RIHt ^ R	IHt ]! R
]R7      t ! R R]],          4      t R#   ] d
    ^ RIHt  LIi ; i)zContains and manages mappings.)annotationsN)	TupleDictListOptionalIteratorTypeTypeVarGenericoverload)ecodes)ValidationError)InputCombinationInputConfig)Mapping	UIMapping)	PathUtils)loggerMappingModel)Zboundc                  s   ] tR t^5tRt]R3R R ll4       t]R4R R ll4       tR]3R R lltR	 R
 ltR R lt	R t
R R ltR R ltR R ltR R ltR R ltR R ltR R ltR R ltR R ltR  R! ltR" R# ltR$ R% ltR& R' ltR( R) ltR* R+ lt]R, R- l4       t]P8                  R. R/ l4       t]R0 R1 l4       tR2tR# )5Presetz1Contains and manages mappings of a single preset.Nc                    V ^8  d   QhRRRR/# )   selfzPreset[Mapping]pathOptional[os.PathLike] Zformat   "A/usr/lib/python3.14/site-packages/inputremapper/configs/preset.py__annotate__Preset.__annotate__:   s    PPP.CP    c                	    R # Nr   r   r      &&r   __init__Preset.__init__9   s    MPr   c               r   )r   r   r   mapping_factoryzType[MappingModel]r   r   r   r   r   r   =   s      # ,r   c                	r    r!   r   r   r   r&      &&&r   r$   r%   <   s    
 r   c               r   )r   r   r   returnNoner   r   r   r   r   r   C   s"     D D#D 
	Dr   c                	s:    / V n         / V n        Wn        W n        R # r!   )	_mappings_saved_mappings_path_mapping_factoryr'   r(   r   r$   r%   C   s#    
 @BEG,0
 5Dr   c                   V ^8  d   QhRR/# )r   r)   zIterator[MappingModel]r   r   r   r   r   r   P   s     4 40 4r   c                sd    \        V P                  P                  4       P                  4       4      # )zIterate over Mapping objects.)Ziterr+   copyvaluesr      &r   __iter__ZPreset.__iter__P   s#    DNN'')00233r   c               r/   )r   r)   Zintr   r   r   r   r   r   T   s     # # #r   c                	s,    \        V P                  4      # r!   )lenr+   r2   r3   r   __len__ZPreset.__len__T   s    4>>""r   c                	r    )Tr   r2   r3   r   __bool__ZPreset.__bool__W   s     r   c               r/   r   r)   boolr   r   r   r   r   r   \   s     6 6T 6r   c                s4    V P                   V P                  8g  # )z#Check if there are unsaved changed.)r+   r,   r2   r3   r   has_unsaved_changesZPreset.has_unsaved_changes\   s    ~~!5!555r   c               r   )r   combinationr   r)   r*   r   r   r   r   r   r   `   s      "2 t r   c                s|   \        V\        4      '       g   \        R\        V4       24      hVP	                  4        F%  pW P
                  P                  4       9   g   K#  Tp M	   V P
                  P                  V4      pVP                  4        R#   \         d    \        P                  ! RT4        R# i ; i)zCRemove a mapping from the preset by providing the InputCombination.2combination must by of type InputCombination, got z;unable to remove non-existing mapping with combination = %sN)
isinstancer   	TypeErrortypeget_permutationsr+   keyspop#remove_combination_changed_callbackKeyErrorr   debug)r   r;   permutationmapping   &&  r   removeZPreset.remove`   s     +'788DT+EVDWX  '779Knn1133) :	nn((5G779 	LLM 	s   (+B "B;:B;c               r   )r   rG   r   r)   r*   r   r   r   r   r   r   v   s     
< 
<< 
<D 
<r   c                s    VP                   P                  4        F"  pW P                  9   g   K  \        RV R24      h	  VP	                  V P
                  4       WP                  VP                   &   R# )zAdd a mapping to the preset.z'A mapping with this input_combination: z already existsN)input_combinationr@   r+   rD   Z set_combination_changed_callback_combination_changed_callback)r   rG   rF   s   && r   addZ
Preset.addv   sj    "44EEGKnn,="m?4  H 	001S1ST4;w001r   c               r/   r   r)   r*   r   r   r   r   r   r      s      t r   c                sv    V P                   P                  4        F  pVP                  4        K  	  / V n         R# )ziRemove all mappings and custom configs without saving.
note: self.has_unsaved_changes() will report True
N)r+   r1   rC   r   rG      & r   emptyZPreset.empty   s.     ~~,,.G779 /r   c               r/   rM   r   r   r   r   r   r      s      t r   c                sB    V P                  4        / V n        RV n        R# )z'Remove all mappings and also self.path.N)rP   r,   r   r2   r3   r   clearZPreset.clear   s    

!	r   c               r/   rM   r   r   r   r   r   r      s     % %d %r   c                s   \         P                  ! RV P                  4       V P                  '       d0   \        P                  P	                  V P                  4      '       g   \        RV P                   R24      hV P                  4       V n        V P                  4        V P                  P                  4        F"  pV P                  VP                  4       4       K$  	  R# )zBLoad from the mapping from the disc, clears all existing mappings.zLoading preset from "%s"z#Tried to load non-existing preset "Z"N)r   infor   osexistsZFileNotFoundError_get_mappings_from_discr,   rP   r1   rL   r0   rN   rO   r   loadZPreset.load   s    .		:yyytyy 9 9#&I$))TU$VWW#;;=

++224G HHW\\^$ 5r   c               r   )r   rJ   r   r)   r9   r   r   r   r   r   r      s      ;K PT r   c                s    V  Uu0 uF  q"P                   kK  	  pp\        VP                  4       4      pWC,          p\        V4      ^8  # u upi )z9Check if the event combination maps to multiple mappings.)rJ   Zsetr@   r5   )r   rJ   rG   Zall_input_combinationsZpermutationsZunions   &&    r   _is_mapped_multiple_timesZ Preset._is_mapped_multiple_times   sK    KO!P4";";4!P,==?@55zA~	 "Qs   A
c               r   )r   rG   r   r)   r9   r   r   r   r   r   r      s     1 1I 1$ 1r   c                s    \        VP                  \        4      pVP                  \        P                  ! 4       8H  pT;'       d    V'       * # )z9Check if the mapping has a valid input event combination.)r=   rJ   r   Zempty_combination)r   rG   Zis_a_combinationZis_emptyrH   r   _has_valid_input_combinationZ#Preset._has_valid_input_combination   s@    %g&?&?AQR,,0@0R0R0TT00L0r   c               r/   rM   r   r   r   r   r   r      s     -. -.d -.r   c                s   V P                   '       g   \        P                  ! R4       R# \        P                  ! V P                   4       V P                  4       '       g   \        P                  ! R4       R# \        P                  ! RV P                   4       . p/ pV  F  pVP                  4       '       gk   V P                  V4      '       g   \        P                  ! RV4       KI  V P                  VP                  4      '       d   \        P                  ! RV4       K  VP                  RR7      pVP                  P                  4       VR	&   VP                  pVP                  V4       VP                  4       W%&   W%,          P                  4        K  	  \!        V P                   R
4      ;_uu_ 4       p\"        P$                  ! W^R7       VP'                  R4       RRR4       W n        R#   + '       g   i     L; i)zDump as JSON to self.path.z:unable to save preset without a path set Preset.path firstNzNot saving unchanged presetzSaving preset to %szSkipping invalid mapping %sz4skipping mapping with duplicate event combination %sT)Zexclude_defaultsrJ   Zw)ZindentZ
)r   r   rE   r   Ztouchr:   rR   is_validrX   rW   rJ   dictZ	to_configappendr0   rC   openjsonZdumpZwriter,   )r   preset_listZsaved_mappingsrG   mapping_dictr;   file   &      r   saveZPreset.save   s|    yyyLLUV		"''))LL67)4995G##%%88AA LL!>H11'2K2KLL LLN "<<<>L070I0I0S0S0UL,-!33K|,*1,,.N''KKM/ 2 $))S!!TIIk2JJt "  .	 "!s   9*G33H	c               r/   r8   r   r   r   r   r   r      s     E E$ Er   c                	sP    R V  Uu. uF  qP                  4       NK  	  up9  # u upi )F)rY   rN   rO   r   rY   ZPreset.is_valid   s&    tDtG--/tDDDDs   #c               r   )r   r;   zOptional[InputCombination]r)   zOptional[MappingModel]r   r   r   r   r   r      s      5	r   c                s    V'       g   R# \        V\        4      '       g   \        R\        V4       24      hVP	                  4        F&  pV P
                  P                  V4      pVf   K$  Vu # 	  R# )z;Return the Mapping that is mapped to this InputCombination.Nr<   )r=   r   r>   r?   r@   r+   get)r   r;   rF   ZexistingrH   r   get_mappingZPreset.get_mapping   sn     +'788DT+EVDWX  '779K~~))+6H# : r   c               r/   r8   r   r   r   r   r   r      s     
 
T 
r   c                s   \         P                  \         P                  3V  Uu. uF  qP                  ^ ,          P                  NK!  	  up9  d   R# . pV  F[  pVP
                  f   K  VP                  VP
                  P                  4       4       VP                  VP                  4       4       K]  	  RV9  ;'       g#    \        P                  ! 4       P                  V9  # u upi )z.Return True if this mapping disables BTN_Left.Fbtn_left)r
   ZEV_KEYZBTN_LEFTrJ   Ztype_and_codeZoutput_symbolr[   ZlowerZget_output_type_coder   re   )r   Zmr1   rG   s   &   r   dangerously_mapped_btn_leftZ"Preset.dangerously_mapped_btn_left   s    MM6??+:>4
:>Q"00$4
 
 57G$$,MM'//5578MM'6689	  f$ B B##%336A	
4
s   %C$c               s$    V ^8  d   QhRRRRRR/# )r   newr   oldr)   r*   r   r   r   r   r   r     s$     6 6#6*:6	6r   c                	s    VP                  4        F4  pW0P                  P                  4       9   g   K#  W28w  g   K+  \        R 4      h	  V P                  P	                  V4      V P                  V&   R# )z(combination already exists in the presetN)r@   r+   rA   rD   rB   )r   rg   rh   rF   s   &&& r   rK   Z$Preset._combination_changed_callback  sZ     //1Knn11338JIJJ 2 #nn005sr   c               r/   rM   r   r   r   r   r   r     s     > > >r   c                	s    V P                   f   R # \        P                   P                  V P                   4      '       g
   / V n        R # V P	                  4       V n        R # r!   )r   rS   rT   r,   rU   r2   r3   r   _update_saved_mappingsZPreset._update_saved_mappings  sB    99ww~~dii((#%D #;;=r   c               r/   )r   r)   z$Dict[InputCombination, MappingModel]r   r   r   r   r   r     s     % %)M %r   c                	sf   / pV P                   '       g   \        P                  ! R 4       V# \        P                  ! V P                   4      P
                  ^ 8X  d   \        P                  ! R4       V# \        V P                   R4      ;_uu_ 4       p \        P                  ! V4      p RRR4       X F]  p\        T\        4      '       g$   \        P                  ! R\        T4      T4       K<   T P                  ! R/ TB pYQTP"                  &   K_  	  T#   \        P                   d1    \        P                  ! RT P                   4       Tu uuRRR4       # i ; i  + '       g   i     L; i  \         d3   p\        P                  ! RTP!                  R4      T4        Rp?K  Rp?ii ; i)	z:unable to read preset without a path set Preset.path firstzgot empty fileZrzunable to decode json file: %sNz$Expected mapping to be a dict: %s %sz%failed to Validate mapping for %s: %srJ   r   )r   r   rE   rS   ZstatZst_sizer\   r]   rV   ZJSONDecodeErrorerrorr=   rZ   r?   r.   Z	Exceptionrc   rJ   )r   Zmappingsr`   r^   r_   rG   rj   ra   r   rU   ZPreset._get_mappings_from_disc  sW   9;yyyLLUVO77499%%*LL)*O$))S!!T "iio " (LlD11:& 
 //?,? 3:W../' (( 1 ''  =tyyI "!  "!$  ; $$%89
 sB   E D2E38EE EE  E0	3F0>'F++F0c               r/   )r   r)   r   r   r   r   r   r   r   <  s      + r   c                	s    V P                   # r!   )r-   r2   r3   r   r   Preset.path;  s    zzr   c               r/   )r   r   r   r   r   r   r   r   r   @  s     * *. *r   c                	sV    WP                   8w  d   Wn        V P                  4        R # R # r!   )r   r-   ri   r"   r#   r   r   rk   ?  s"    99J'') r   c               r/   )r   r)   zOptional[str]r   r   r   r   r   r   F  s      m r   c                s    V P                   '       d@   \        P                   P                  V P                   4      P                  R4      ^ ,          # R# )zThe name of the preset.Z.N)r   rS   ZbasenameZsplitr2   r3   r   nameZPreset.nameE  s9     99977##DII.44S9!<<r   )r.   r+   r-   r,   r   r!   )N.)Z__name__Z
__module__Z__qualname__Z__firstlineno____doc__r	   r$   r   r4   r6   r7   r:   rI   rL   rP   rQ   rV   rW   rX   rb   rY   rd   rf   rK   ri   rU   Zpropertyr   Zsetterrl   Z__static_attributes__r   r   r   r   r   5   s    ; P P  '+D4#
6,
<%1-.^E$
&6>%N   
[[* *
  r   r   )!rm   Z
__future__r    r]   rS   Ztypingr   r   r   r   r   r   r   r   r	   Zevdevr
   Zpydantic.v1r   ZImportErrorZpydanticZ"inputremapper.configs.input_configr   r   Zinputremapper.configs.mappingr   r   Zinputremapper.configs.pathsr   Zinputremapper.logging.loggerr   r   r   r   r   r   <module>rn      sq   ( % "  	
 
 
 )+ M < 1 /~Y7UW\" U  )()s   A. .A>=A>