mò
¯íDc           @   s~   d  Z  d k Z d k Z d k l Z l Z d k l Z l Z d e i f d „  ƒ  YZ	 e	 ƒ  Z
 e i e
 d ƒ e
 i ƒ  d S(	   s~  
threading.py - S.Fourmanoit <syfou@users.sourceforge.net>, 2005

Test script showing how threads can be used with adesklets.
It demonstrates at the same time how the 'delayed event' mechanism
can be superseeded by any other policy, while preserving
desklet responsiveness.

Two threads are created:

- Working thread:  catch events, and feed them to a queue
- Consumer thread: dequeue events in FIFO mode, using a simple
                   timing mechanism to mark too old event as
                   expired, and use the information to build the
                   display, which is here only a simple trace
                   drawing.
N(   s   izips   count(   s   times   sleept	   My_Eventsc           B   s,   t  Z d „  Z d „  Z d „  Z d „  Z RS(   Nc         C   s,   t  i i |  ƒ g  |  _ t i ƒ  |  _ d  S(   N(   t	   adeskletst   Events_handlert   __init__t   selft   queuet   threadt   allocate_lockt   lock(   R   (    (    t-   /home/sylvain/adesklets.git/test/threading.pyR      s    	c         C   sQ   t  i d d ƒ t  i t  i ƒ t  i t ƒ t  i d d d d ƒ t  i ƒ  d  S(   Nid   iÿ   (   R   t   window_resizet   window_resett   WINDOW_MANAGEDt   window_set_transparencyt   Truet   context_set_colort   window_show(   R   (    (    R	   t   ready   s
    c         C   s:   |  i i ƒ  |  i i | | t ƒ  f ƒ |  i i ƒ  d S(   sµ   
        Motion notify reporter
        
        The main execution thread is only used to catch events,
        and queue things in self.queue (this is the working thread)
        N(	   R   R   t   acquireR   t   appendt   xt   yt   timet   release(   R   t   delayedR   R   (    (    R	   t   motion_notify$   s     c         C   s#  d i  d d | d | g ƒ GHxý |  i i ƒ  t ƒ  } d
 } x= t
 t ƒ  |  i ƒ D]& \ } } | | d | j  o PqT qT W| o, | d j	 o | Gd GHn |  i | d 4n |  i i ƒ  | oK d	 t | d  ƒ | | d f GHt i | d d | d d d d ƒ n t | ƒ q" Wd
 S(   s€   
        Routine implementing the display operations, via an
        asynchronous thread (this is the consumer thread).
        s   
s   Display threads   max delay is %f seconds,s+   sleep time between processing is %f secondsi   i   i    s   events droppeds    Motion Notify %s, %f seconds agoN(   t   joint	   max_delayt
   sleep_timeR   R   R   R   t   tt   Nonet   curt   izipt   countR   t   iR   t   strR   t   image_fill_rectanglet   sleep(   R   R   R   R   R"   R   (    (    R	   t   __call__/   s(       	 	!*(   t   __name__t
   __module__R   R   R   R&   (    (    (    R	   R       s   			i   f0.01(   i   f0.01(   t   __doc__R   R   t	   itertoolsR    R!   R   R%   R   R    t	   my_eventst   start_new_threadt   pause(   R!   R   R    R    R+   R%   R   R   (    (    R	   t   ?   s   		B	