
    Eg                     x    d dl mZmZmZ d dlmZ  G d dej                        Z G d dej                        Z	y)    )GtkGObjectGLib)trackersc                   (     e Zd ZdZ fdZd Z xZS )_fixedViewportz
    This is needed by MarqueeLabel to restrict the size of
    our label, and cause the viewport to actually be functional.
    Otherwise, the text is trimmed, but no scrolling occurs.
    c                 |    t         t        |           | j                  t        j
                  j                         y N)superr   __init__set_shadow_typer   
ShadowTypeNONE)self	__class__s    7/usr/share/cinnamon-screensaver/widgets/marqueeLabel.pyr   z_fixedViewport.__init__   s(    nd,.S^^001    c                      y)N)  r    r   s    r   do_get_preferred_widthz%_fixedViewport.do_get_preferred_width   s    r   )__name__
__module____qualname____doc__r   r   __classcell__r   s   @r   r   r      s    
2
r   r   c                   n     e Zd ZdZg dZ ee      Z fdZd Zd Z	ddZ
d Zd Zdd	Zd
 Zd Z xZS )MarqueeLabela  
    A scrolling label for the PlayerControl - it uses the defined
    pattern as a mapping between elapsed time and the hadjustment
    of the _fixedViewport.  If the label text is wider than the
    widget's actual width, we will scroll according to this map
    over the course of 15 seconds.

    It roughly translates to:
         0.0 -  2.0 seconds: no movement.
         2.0 - 10.0 seconds: gradually scroll to max adjustment of the viewport.
        10.0 - 12.0 seconds: no movement.
        12.0 - 15.0 seconds: scroll back to the starting position.

    This widget also implements a stack (similar to the one in MonitorView) which
    provides for a smooth label crossfade when track info changes.
    ))        r!   )g       @r!   )g      $@      ?)g      (@r"   )g      .@r!   c                 D   t         t        |           | j                  t        j
                  j                         | j                  d       d| _        | j                  |      | _
        | j                  | j                         | j                  | j                         y )Ni,  r   )r   r    r   set_transition_typer   StackTransitionType	CROSSFADEset_transition_durationtick_id_make_labelcurrentaddset_visible_child)r   textr   s     r   r   zMarqueeLabel.__init__.   ss    lD*,  !8!8!B!BC$$S)''-t||,r   c                     t               }t        j                  |      }|j                  t        j                  j
                         |j                  |       |j                          |S r
   )r   r   Label
set_halignAlignSTARTr+   show_all)r   r-   vplabels       r   r)   zMarqueeLabel._make_label;   sF    		$)
u
	r   c                    | j                   j                         j                         |k(  ry | j                          | j	                  |      | _        | j                  | j
                         | j                  | j
                         | j                   }| j
                  | _         d | _        t        j                  |j                         | j                   j                         s:t        j                         j                  | j                   d| j                         y t        j                  | j                          y Nrealize)r*   	get_childget_textcancel_tickr)   queuedr+   r,   r   idle_adddestroyget_realizedr   con_tracker_getconnecton_current_realized_marquee_idle)r   r-   tmps      r   set_textzMarqueeLabel.set_textF   s    <<!!#,,.$6&&t,t{{+ll{{%||((*$$&..t||/8/3/G/GI T//0r   c                     t        j                  | j                         t        j                         j                  |d| j                         y r7   )r   r=   rC   r   r@   
disconnectrB   )r   widgetdatas      r   rB   z MarqueeLabel.on_current_realized^   s<    ++,  "--f.7.2.F.F	Hr   c                 h    | j                   dkD  r#| j                  | j                          d| _         y y )Nr   )r(   remove_tick_callbackr   s    r   r;   zMarqueeLabel.cancel_ticke   s,    <<!%%dll3DL r   c                 6   | j                   j                         | _        | j                  j                         | j                  j	                         k(  | j                         k(  ry| j                         j                         | _        | j                  | j                  | j                  dz
     d   dz  dz  z   | _        | j                  dk(  r | j                  | j                        | _        | j                  | j                         t         j"                  S )NF   r     )r*   get_hadjustmenthadjust	get_upperget_page_sizeget_allocated_widthget_frame_clockget_frame_time
start_timePATTERNLENGTHend_timer(   add_tick_callback_on_marquee_tick_marquee_stepr   SOURCE_REMOVEr   s    r   rC   zMarqueeLabel._marquee_idlej   s    ||335LL""$(B(B(DDIaIaIcc..0??A4<<a+H+Kd+RUY+YZ<<111$2G2GHDL4??+!!!r   c                    |j                         }| j                  |       || j                  k\  rI| j                  | _        | xj                  | j                  | j
                  dz
     d   dz  dz  z  c_        t        j                  S )NrM   r   rN   )rU   r\   rY   rV   rW   rX   r   SOURCE_CONTINUE)r   rH   clockrI   nows        r   r[   zMarqueeLabel._on_marquee_tickz   so    ""$3$--"mmDOMMdll4;;?;A>ELMM###r   c                     || j                   z
  dz  dz  }d}|| j                  k  rU| j                  |   \  }}||kD  r|dz  },||k(  r|S | j                  |dz
     \  }}||z
  }||z
  }	||	z  }
||z
  |
z  }||z   S y )NrN   r   rM   )rV   rX   rW   )r   ra   pointicindexcvalpindexpvaldiffdurationratioadditives               r   interpolate_pointzMarqueeLabel.interpolate_point   s    '4/$6$++o<<?LFDv~Q<<A.LFD$;DH8OE%/H(?"! r   c                 J   || j                   k  r| j                  |      }n| j                  | j                  dz
     d   }| j                  j                         | j                  j                         z
  |z  }| j                  j                  |       | j                          y )NrM   )	rY   rm   rW   rX   rP   rQ   rR   	set_value
queue_draw)r   ra   tnew_positions       r   r\   zMarqueeLabel._marquee_step   s    &&s+AT[[1_-a0A//1DLL4N4N4PPTUU|,r   r
   )r   r   r   r   rW   lenrX   r   r)   rE   rB   r;   rC   r[   rm   r\   r   r   s   @r   r    r       sH     G \F-	10H
" 	$#,	r   r    N)
gi.repositoryr   r   r   utilr   Viewportr   Stackr    r   r   r   <module>rx      s2    - , S\\ O399 Or   