
    Eg5'                         d dl Z  e j                  dd       d dlmZmZmZmZ d dlZd dlm	Z	m
Z
 d dlZ G d dej                        Zy)    NCinnamonDesktopz3.0)GtkGdk	GdkPixbufGLib)trackerssettingsc                   t     e Zd ZdZ fdZddZd Zd Zd Zd Z	d Z
d	 Zd
 ZddZd Zd Zd Zd Z xZS )PasswordEntryz
    The GtkEntry where the user types their password.  It also
    implements a clickable imagine showing the currently chosen
    keyboard layout, and allowing switching of the layout.
    c                 0   t         t        |   d       | j                         j	                  d       t        d      }| j                  t        |      dz          | j                  d       | j                  t        j                  j                         | j                  d       | j                  dd       | j                  |       | j!                  d       | j#                  t        j$                  j&                  d	       t)        j*                         j-                  | d
| j.                         || _        d | _        d| _        d| _        t8        j:                  | _        t)        j*                         j-                  | j<                  d| j>                         t)        j*                         j-                  | j<                  d| j@                         | jC                          t)        j*                         j-                  | d| jD                         y )N   )
max_lengthpasswordentryzPlease enter your password...   TFzcaps-lock-warning cinnamon-screensaver-view-revealz
icon-pressr   config-changedlayout-changeddestroy)#superr   __init__get_style_context	add_class_set_width_charslenset_has_frameset_input_purposer   InputPurposePASSWORDset_visibilityset_propertyset_placeholder_textset_can_defaultset_icon_from_icon_nameEntryIconPosition	SECONDARYr   con_tracker_getconnecton_icon_pressedplaceholder_textcurrent_icon_namecurrent_flag_idoriginal_group
singletonsKeyboardLayoutControllerkeyboard_controlleron_config_changedon_layout_changedset_lockscreen_keyboard_layout
on_destroy)selfr*   	__class__s     0/usr/share/cinnamon-screensaver/passwordEntry.pyr   zPasswordEntry.__init__   s   mT+s+; **?;<=S!12Q674 s//889E"-u5!!#34T"$$S%:%:%D%DFhi  "**4t?S?ST 0!% #-#F#F   "**4+C+C+;+/+A+A	C 	  "**4+C+C+;+/+A+A	C 	++-  "**4+4+/??	<    c           	      n   | j                   j                         sy|j                  t        j                  j
                        }|j                  }|j                  dz   }|j                  dz  dz  }|j                  dz
  }d}	t        j                         r/| j                   j                         }
| j                         }|
rd|
z  }	 t        j                  j!                  |d||z        }|j#                         |z  }|j%                         |z  }||dz  z   |dz  z
  }||dz  z   |dz  z
  }|r%t'        j(                  ||| j+                               }|j-                  ||       |j/                          | j                   j1                  |||dz  z   ||dz  z   |dz  |dz  | j                   j3                                d}	|	sRt        j8                         r| j                   j;                         }
n| j                   j=                         }
t        j>                         r|
jA                         }
|jC                         }|jE                          |jG                  t        jH                  jJ                         |jM                  dt        jH                  jJ                        }|jM                  dt        jH                  jJ                        }|jO                  |d	   tP        jR                  tP        jT                         |jW                  |       |jY                  |
      \  }}}}}}|j[                  d	d	d	d
       |j]                  ||dz  z   |dz  z
  dz   ||dz  z   |dz  z   dz          |j_                  |
       |jC                         ja                  t        jH                  jJ                        }t'        jb                  ||       |j]                  ||dz  z   |dz  z
  ||dz  z   |dz  z          |j_                  |
       |je                          y# t4        j6                  $ r Y lw xY w)a@  
        GtkEntry always makes its icons menu-sized, no matter how much actual
        space is available for the image.  So, we use a transparent icon in
        update_layout_icon(), just so GtkEntry thinks there's an icon there,
        that way it allocates space for it, and responds to clicks in the area.
        F      z/usr/share/iso-flag-png/%s.pngTz	font-sizezfont-familyr   g?r   )3r0   get_enabledget_icon_arear   r%   PRIMARYxywidthheightr	   get_show_flagsget_current_icon_nameget_scale_factorr   Pixbufnew_from_file_at_size	get_width
get_heightr    cairo_surface_create_from_pixbuf
get_windowset_source_surfacepaintrender_cairo_subscriptget_current_flag_idr   Errorget_use_layout_variant_namesget_current_variant_labelget_current_short_group_labelget_show_upper_case_layoutupperr   save	set_state
StateFlagsBACKDROPget_propertyselect_font_facecairoFONT_WEIGHT_NORMALFONT_SLANT_NORMALset_font_sizetext_extentsset_source_rgbamove_to	show_text	get_colorcairo_set_source_rgbarestore)r5   widgetcrdata	icon_rectr@   rA   rB   rC   handlednameui_scalefilenamepixbuflogical_widthlogical_heightrender_xrender_ysurfacectx	font_sizefamilyxbybwhxaya
text_colors                                r7   on_drawzPasswordEntry.on_draw7   s    ''335(()>)>)F)FG	KKKK!OA%*!!A%""$++AACD,,.H;dB&--CCHbRX[cRcdF$*$4$4$6$AM%+%6%6%88%CN !UQY=13D EH !VaZ 0NQ4F GH"%"F"FvGOGKGX#Z ))'*2*24 HHJ,,CCBDLP]`aPaDbDLP^abPbDcDQTUDUDRUVDVDHD\D\DpDpDrt #G 446//IIK//MMO224zz|**,CHHJMM#..112((cnn6M6MNI%%mS^^5L5LMFq	5+C+CUE\E\]Y'%'__T%:"RQ2r q!Q,JJUQY1q51Q6VaZ(AE2Q69 LL  113==cnn>U>UVJ%%b*5JJUQY1q51VaZ(AE25 LLKKMU zz s   C<P P43P4c                     | j                  d       t        j                         j                  dd| j                         y )Ng?auth-progressd   )set_progress_pulse_stepr   timer_tracker_getstartpulser5   s    r7   start_progresszPasswordEntry.start_progress   s3    $$S)""$**?+.+/::	7r8   c                 l    t        j                         j                  d       | j                  d       y )Nr   g        )r   r   cancelset_progress_fractionr   s    r7   stop_progresszPasswordEntry.stop_progress   s'    ""$++O<""3'r8   c                 $    | j                          y)z9
        Periodic callback for the progress bar.
        T)progress_pulser   s    r7   r   zPasswordEntry.pulse   s     	r8   c                 D    | j                          | j                          y N)
grab_focusupdate_layout_icon)r5   
controllerlayouts      r7   r2   zPasswordEntry.on_layout_changed   s    !r8   c                 $    | j                          y r   )r3   )r5   r   s     r7   r1   zPasswordEntry.on_config_changed   s    ++-r8   c                    |t         j                  j                  k(  r| j                  j	                          y |t         j                  j
                  k(  r| j                         t         j                  j                  k(  re| j                  d       | j                  t         j                  j                         | j                  t         j                  j
                  d       nd| j                  d       | j                  t         j                  j                         | j                  t         j                  j
                  d       | j                          y y )NFr   Tz!cinnamon-screensaver-view-conceal)r   r%   r?   r0   
next_groupr&   get_input_purposer   	FREE_FORMr    r   r   r$   
queue_draw)r5   entryicon_posevents       r7   r)   zPasswordEntry.on_icon_pressed   s    s,,444$$//1..888%%'3+;+;+E+EE##E*&&s'7'7'@'@A,,S-B-B-L-LNpq##D)&&s'7'7'A'AB,,S-B-B-L-LNqrOO 9r8   c                 .   | j                  t        j                  j                  d       | j	                  t        j                  j                  | j
                  j                                | j                  | j
                  j                                y)a  
        Set an empty icon here so the widget responds to clicks and allocates space for it.
        We'll do the actual flag or whatever in the 'draw' callback.  Setting the icon here
        also ensures a redraw at the correct time to update the flag image.
        zscreensaver-blankN)	r$   r   r%   r?   set_icon_tooltip_textr0   get_current_nameupdate_saved_groupget_current_groupr   s    r7   r   z PasswordEntry.update_layout_icon   si     	$$S%:%:%B%BDWX""3#8#8#@#@$BZBZBkBkBmn 8 8 J J LMr8   c                 (   | j                          t        j                         j                  | j                  d| j
                         t        j                         j                  | j                  d| j                         | j                          y )Nr   r   )r   r   r'   
disconnectr0   r1   r2   restore_original_layout)r5   rh   rj   s      r7   r4   zPasswordEntry.on_destroy   sv      "--d.F.F.>.2.D.D	F 	  "--d.F.F.>.2.D.D	F 	$$&r8   c                    | j                   j                         sy t        j                         }| j                   j	                         | _        d}|dk(  r| j
                  }n|}| j                   j                  |       | j                  |       | j                          t        j                         j                  | d| j                         y )Nr   r<   draw)r0   r=   r	   get_kb_groupr   r-   set_current_groupr   r   r   r'   r(   r   )r5   saved_group	new_groups      r7   r3   z,PasswordEntry.set_lockscreen_keyboard_layout   s    ''335 ++-"66HHJ	"++I#I  229=	*!  "**4+1+/<<	9r8   c                 .    t        j                  |       y r   )r	   set_kb_group)r5   groups     r7   r   z PasswordEntry.update_saved_group   s    e$r8   c                     | j                   j                         sy| j                   j                  | j                         y)z
        Called when the unlock dialog is destroyed, restores
        the group that was active before the screensaver was activated.
        N)r0   r=   r   r-   r   s    r7   r   z%PasswordEntry.restore_original_layout   s3    
 ''335  2243F3FGr8   c                     t         j                  j                  |        | j                         j	                         }| j                  |d       y )Nr<   )r   Widgetr   
get_buffer
get_lengthselect_region)r5   lengths     r7   r   zPasswordEntry.grab_focus   s9    

d#"--/62&r8   r   )__name__
__module____qualname____doc__r   r   r   r   r   r2   r1   r)   r   r4   r3   r   r   r   __classcell__)r6   s   @r7   r   r      sS    
"<H`D7(".	N'96%H'r8   r   )girequire_versiongi.repositoryr   r   r   r   r]   utilr   r	   r.   Entryr    r8   r7   <module>r      s>    
   $e , 3 3  # v'CII v'r8   