³ò
B3IHc           @   s¦   d  Z  d d k Z d Z d d d „  ƒ  YZ d d d „  ƒ  YZ d e f d	 „  ƒ  YZ d
 e e i f d „  ƒ  YZ d e f d „  ƒ  YZ d e e i f d „  ƒ  YZ d S(   sf  realtime.py | GPL - license | (c)2005 www.stani.be

This module provides two classes which enable to update only selectively parts
of a wx.TreeCtrl or a wx.ListCtrl. This makes fast/realtime updating possible
of only changed items instead of the whole tree or list.

These classes are used in SPE's sidebar:
- TreeCtrl for Explore
- ListCtrl for Todo & IndexiÿÿÿÿNs5   Warning: %s: please contact spe.stani.be at gmail.comt   Itemc           B   s   e  Z d  „  Z d „  Z RS(   c         C   s1   d |  _  d  |  _ t |  _ d |  _ d  |  _ d  S(   Niÿ   i    (   iÿ   iÿ   iÿ   (   i    i    i    (   t   backgroundColourt   Nonet   datat   Falset   deletedt
   textColourt   wx(   t   self(    (    s   C:\py\_spe\sm\wxp\realtime.pyt   init   s
    				c         C   s   g  |  _  g  |  _ d  S(   N(   t   _updatet
   _updateAll(   R   (    (    s   C:\py\_spe\sm\wxp\realtime.pyt   reset   s    	(   t   __name__t
   __module__R	   R   (    (    (    s   C:\py\_spe\sm\wxp\realtime.pyR       s   	t   Ctrlc           B   s€   e  Z d Z d  „  Z g  d d „ Z e d „ Z d „  Z d „  Z	 d „  Z
 d „  Z e d „ Z d d „ Z d	 „  Z d
 „  Z RS(   c         C   s   h  |  _  d  S(   N(   t   items(   R   (    (    s   C:\py\_spe\sm\wxp\realtime.pyt   __init__   s    c   
      C   s¾   | o4 y  d t  | ƒ i d d ƒ } WqA d } qA Xn d } d | i d d ƒ | f i d d ƒ } d } g  } | D] } | | i qz ~ }	 x  | | |	 j o | d	 7} q– W| | S(
   s#   Create unique id with data & index.t   |t   %s   %%t    s   %s%s|%%dt   asciit   replacei    i   (   t   reprR   t   encodet   id(
   R   t   baset   othersR   t   dataIdR   t   nrt   _[1]t   othert   othersId(    (    s   C:\py\_spe\sm\wxp\realtime.pyt   _createUniqueId"   s     ($ c         C   s{   | i  d j o+ | i o  |  i |  | i  ƒ d | _  n | o5 | i ƒ  |  i i | i ƒ o |  i | i =qw n d S(   s,   Delete safely (not wx) item from self._itemsN(   R   R   R   t   _wxDeleteItemt   _deleteR   t   has_keyR   (   R   t   itemt	   fromItems(    (    s   C:\py\_spe\sm\wxp\realtime.pyt   _deleteItem2   s    
c         C   s#   |  i  | d t ƒ| i | _ d S(   sf   DeleteWx component and refresh update.
        This is used for an item which previously came earlier.R&   N(   R'   R   R   R
   (   R   R%   (    (    s   C:\py\_spe\sm\wxp\realtime.pyt
   _renewItem<   s    c         C   s   d S(   s5   Indepedent delete wx item method (to be overwritten).N(    (   R   R%   (    (    s   C:\py\_spe\sm\wxp\realtime.pyt   _DeleteItemB   s    c         C   s   d S(   sU   Inserts an item after a given one, used by self._update()
        (to be overwritten)N(    (   R   t   parentt   childrent   indext   text(    (    s   C:\py\_spe\sm\wxp\realtime.pyt   _insertItemE   s    c         C   s   d S(   sU   Inserts an item as the first one, used by self._update().
        (to be overwritten)N(    (   R   R*   R-   (    (    s   C:\py\_spe\sm\wxp\realtime.pyt   _prependItemI   s    c      	   C   sŸ  | i  } | i } xUt | ƒ D]F\ } } | | j oq | i | ƒ } | |  } | i ƒ  x9 | D]1 }	 |	 | j o |  i |	 ƒ qc |  i |	 ƒ qc W| | d } n’ | oC | d | j o2 | d }
 |  i | |
 ƒ } | | <| d } nH | d j o" |  i | | | | i	 ƒ | _
 n |  i | | i	 ƒ | _
 |  i | | ƒ | o |  i | t ƒ q  q  W| i ƒ  x | D] }	 |  i |	 ƒ q{W| | _ d S(   sA   Update (recursively) all children (Item) of parent(Item or List).i   i    N(   R+   t   previousChildrent	   enumerateR,   t   reverseR(   R)   t   _copyItemToR.   R-   R   R/   t   _updateItemR
   t   True(   R   R*   t   recursivelyR+   R0   R,   t   childt	   prevIndext
   abandonedst	   abandonedt
   empty_slot(    (    s   C:\py\_spe\sm\wxp\realtime.pyR
   M   s:    		 

 
"
 c         C   sF   x? | i  D]4 } |  | i g } | i | d ƒ | d | Œ  q
 Wd S(   s*   Execute pending update actions of TreeItemi   i    N(   R
   R   t   extend(   R   R%   R,   t   actiont	   arguments(    (    s   C:\py\_spe\sm\wxp\realtime.pyR4   t   s
    
 c         C   sY   | i  | j o) | | _  | i i |  i i | f ƒ n | i i |  i i | f ƒ d S(   s"   Sets the text colour of a TreeItemN(   R   R
   t   appendt   _baset   SetItemTextColourR   (   R   R%   t   color(    (    s   C:\py\_spe\sm\wxp\realtime.pyRA   {   s    	 c         C   sY   | i  | j o) | | _  | i i |  i i | f ƒ n | i i |  i i | f ƒ d S(   s(   Sets the background colour of a TreeItemN(   R   R
   R?   R@   t   SetItemBackgroundColourR   (   R   R%   RB   (    (    s   C:\py\_spe\sm\wxp\realtime.pyRC   ‚   s    	 N(   R   R   R   R@   R   R!   R5   R'   R(   R)   R.   R/   R   R
   R4   RA   RC   (    (    (    s   C:\py\_spe\sm\wxp\realtime.pyR      s   	
				'	t   TreeItemc           B   s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   s1   All the wx actions are handled by the Tree class.c         C   s<   | |  _  | |  _ g  |  _ h  |  _ |  i ƒ  |  i ƒ  d S(   s!   self.wx holds the wx.TreeItemDataN(   R   R-   R0   t   imageR	   R   (   R   R-   R   (    (    s   C:\py\_spe\sm\wxp\realtime.pyR   Œ   s    				
c         C   sB   x2 |  i  D]' } | i  o | i ƒ  n t | _ q
 Wt |  _ d S(   sB   When an item is removed its children are also removed recursively.N(   R+   R#   R5   R   (   R   R7   (    (    s   C:\py\_spe\sm\wxp\realtime.pyR#   –   s    
 
c         C   s   t  i |  ƒ t |  _ d  S(   N(   R    R	   R   t   bold(   R   (    (    s   C:\py\_spe\sm\wxp\realtime.pyR	   ž   s    c         C   s   t  i |  ƒ g  |  _ d  S(   N(   R    R   R+   (   R   (    (    s   C:\py\_spe\sm\wxp\realtime.pyR   ¢   s    (   R   R   t   __doc__R   R#   R	   R   (    (    (    s   C:\py\_spe\sm\wxp\realtime.pyRD   ‰   s
   	
		t   TreeCtrlc           B   s¤   e  Z e i Z d  „  Z d „  Z d „  Z d „  Z d „  Z	 d d „ Z d „  Z d „  Z d „  Z d	 „  Z d
 „  Z e d „ Z e i d „ Z d „  Z d „  Z RS(   c         O   sb   t  i |  ƒ t i i |  | | Ž |  i |  _ t i i |  _ | d |  _ |  i t i @|  _	 d  S(   Nt   style(
   R   R   R   RH   t   DeleteR)   R"   t   _stylet   TR_HIDE_ROOTt	   _hideRoot(   R   t   argst   kwargs(    (    s   C:\py\_spe\sm\wxp\realtime.pyR   ª   s    c         C   sÆ   | i  | _  | i | i j o# | i i t  i i | i f ƒ n | i i t  i i | i f ƒ | i | _ | i | i j o# | i i t  i i	 | i f ƒ n | i i t  i i	 | i f ƒ | S(   sT   Copy/steal wx control from an abandoned TreeItem to avoid creating a new wx control.(
   R   R   R
   R?   RH   t	   SetPyDataR   R0   R-   t   SetItemText(   R   t   frmt   to(    (    s   C:\py\_spe\sm\wxp\realtime.pyR3   ²   s    ##c         C   s'   t  i i |  | i  | | d i  | ƒ S(   s"   Inserts an item after a given one.i   (   R   RH   t
   InsertItem(   R   R*   R+   R,   R-   (    (    s   C:\py\_spe\sm\wxp\realtime.pyR.   ¾   s    c         C   s   t  i i |  | i  | ƒ S(   s!   Inserts an item as the first one.(   R   RH   t   PrependItem(   R   R*   R-   (    (    s   C:\py\_spe\sm\wxp\realtime.pyR/   Â   s    c         C   st   t  d | d | ƒ |  _ |  i |  i | <t i i |  | ƒ |  i _ |  i p  |  i i i t i i	 f ƒ n |  i S(   NR-   R   (
   RD   t   rootR   R   RH   t   AddRootRM   R
   R?   t   Expand(   R   R-   (    (    s   C:\py\_spe\sm\wxp\realtime.pyRW   Æ   s    
 c         C   sÔ   t  | d ƒ o | i ƒ  } n | i } |  i d d | i | f d | d | ƒ } |  i i | ƒ o |  i | } | i ƒ  n! t d | d | ƒ } |  i | <| i	 | ƒ | d j o |  i | | ƒ n | S(	   s>  Add data immediately, if the label is not unique. Be aware that that
        is a devation from wx.ListCtrl, if data is not wxTreeItemData.
        
        There are two possibilities that an item is appended to its parent
        - if already present, pick it up and update the text
        - if not, create one itemt   GetDataR   s   %s|%sR   R   R-   R   N(   t   hasattrRY   R+   R!   R   R   R$   R   RD   R?   R   RP   (   R   R*   R-   R   t	   pChildrenR   R%   (    (    s   C:\py\_spe\sm\wxp\realtime.pyt
   AppendItemÎ   s     			 c         C   s   |  i  | ƒ d S(   s/   Delete item and all its children from the tree.N(   R'   (   R   R%   (    (    s   C:\py\_spe\sm\wxp\realtime.pyRJ   è   s    c         C   s*   |  i  |  i d t ƒ|  i |  i ƒ d S(   s›   Update only differences between current and previous state.
        This method MUST be called in the end otherwise there will be no visual
        change.R6   N(   R
   RV   R5   R4   (   R   (    (    s   C:\py\_spe\sm\wxp\realtime.pyt   Updateì   s    c         C   s7   t  i i |  | i  ƒ o t  i i |  | i  ƒ n d S(   s   Collapse a TreeItem.N(   R   RH   t
   IsExpandedt   Collapse(   R   R%   (    (    s   C:\py\_spe\sm\wxp\realtime.pyR_   ó   s    c         C   s   g  | _  d S(   s9   Remove children of a TreeItem, mostly used for self.root.N(   R+   (   R   R%   (    (    s   C:\py\_spe\sm\wxp\realtime.pyt   CollapseAndResetø   s    c         C   sQ   |  i  o | |  i j p t i i |  | i ƒ p t i i |  | i ƒ n d S(   s   Expands a TreeItem.N(   RM   RV   R   RH   R^   RX   (   R   R%   (    (    s   C:\py\_spe\sm\wxp\realtime.pyRX   ü   s    3c         C   sY   | i  | j o) | | _  | i i t i i | f ƒ n | i i t i i | f ƒ d S(   s(   Sets the background colour of a TreeItemN(   RF   R
   R?   R   RH   t   SetItemBoldR   (   R   R%   RF   (    (    s   C:\py\_spe\sm\wxp\realtime.pyRa     s    	 c         C   s{   | i  i | ƒ p | i  | | j o0 | | i  | <| i i t i i | | f ƒ n | i i t i i | | f ƒ d S(   s8   Sets the image for a certain state (which) of a TreeItemN(   RE   R$   R
   R?   R   RH   t   SetItemImageR   (   R   R%   RE   t   which(    (    s   C:\py\_spe\sm\wxp\realtime.pyRb     s    (#c         C   sY   | i  | j o) | | _  | i i t i i | f ƒ n | i i t i i | f ƒ d S(   s   Sets the text of a TreeItemN(   R-   R
   R?   R   RH   RQ   R   (   R   R%   R-   (    (    s   C:\py\_spe\sm\wxp\realtime.pyRQ     s    	 c         C   sY   | i  | j o) | | _  | i i t i i | f ƒ n | i i t i i | f ƒ d S(   s   Sets the py data of a TreeItem.N(   R   R
   R?   R   RH   RP   R   (   R   R%   R   (    (    s   C:\py\_spe\sm\wxp\realtime.pyRP     s    	 N(   R   R   R   RH   R@   R   R3   R.   R/   RW   R   R\   RJ   R]   R_   R`   RX   R5   Ra   t   TreeItemIcon_NormalRb   RQ   RP   (    (    (    s   C:\py\_spe\sm\wxp\realtime.pyRH   §   s    												t   ListItemc           B   s#   e  Z d  „  Z d „  Z d „  Z RS(   c         C   s<   | |  _  | |  _ | |  _ d  |  _ |  i ƒ  |  i ƒ  d  S(   N(   R,   R-   R   R   RE   R	   R   (   R   R,   R-   R   (    (    s   C:\py\_spe\sm\wxp\realtime.pyR     s    				
c         C   s   t  i |  ƒ d |  _ d  S(   Ni    (   R    R	   R   (   R   (    (    s   C:\py\_spe\sm\wxp\realtime.pyR	   '  s    c         C   s   t  |  _ d S(   s   Flag as deleted.N(   R5   R   (   R   (    (    s   C:\py\_spe\sm\wxp\realtime.pyR#   +  s    (   R   R   R   R	   R#   (    (    (    s   C:\py\_spe\sm\wxp\realtime.pyRe     s   			t   ListCtrlc           B   s’   e  Z e i 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 d „  Z d „  Z RS(   c         O   sT   t  i |  ƒ t i i |  | | Ž |  i |  _ t i i |  _ g  |  _ g  |  _ d  S(   N(	   R   R   R   Rf   t
   DeleteItemR)   R"   R+   R0   (   R   RN   t   kwds(    (    s   C:\py\_spe\sm\wxp\realtime.pyR   3  s    	c         C   sñ   | i  | _  | i | i j o# | i i t  i i | i f ƒ n | i i t  i i | i f ƒ | i } x€ | i i ƒ  D]o \ } } | i	 | ƒ o4 | | | j o# | i i t  i i
 | | f ƒ n | i i t  i i
 | | f ƒ qz W| S(   sT   Copy/steal wx control from an abandoned TreeItem to avoid creating a new wx control.(   R   R   R
   R?   Rf   t   SetItemDataR   R-   R   R$   t   SetStringItem(   R   RR   RS   t   toTextt   columnt   label(    (    s   C:\py\_spe\sm\wxp\realtime.pyR3   ;  s    #	 !##c         C   s   t  i i |  | | d ƒ S(   s"   Inserts an item after a given one.i    (   R   Rf   t   InsertStringItem(   R   R*   R+   R,   R-   (    (    s   C:\py\_spe\sm\wxp\realtime.pyR.   H  s    c         C   s   t  i i |  d | d ƒ S(   s!   Inserts an item as the first one.i    (   R   Rf   Rn   (   R   R*   R-   (    (    s   C:\py\_spe\sm\wxp\realtime.pyR/   L  s    c         C   s    | | _  t i |  | | ƒ d S(   s$   Same as Ctrl, but update also index.N(   R   R   R4   (   R   R%   R,   (    (    s   C:\py\_spe\sm\wxp\realtime.pyR4   P  s    	c         C   s   g  |  _  d  S(   N(   R+   (   R   (    (    s   C:\py\_spe\sm\wxp\realtime.pyt   DeleteAllItemsU  s    c         C   s5   | |  i  j o |  i  i | ƒ n |  i | ƒ d S(   s   Delete item safely.N(   R+   t   removeR'   (   R   R%   (    (    s   C:\py\_spe\sm\wxp\realtime.pyRg   X  s    c         C   s³   |  i  d | d |  i d | ƒ } |  i i | ƒ o |  i | } | i ƒ  n0 t d | d h  | d <d | ƒ } |  i | <|  i i | ƒ | d j o |  i | | ƒ n | S(	   s  Add data immediately, if the label is not unique. Be aware that that
        is a devation from wx.ListCtrl
        
        There are two possibilities that an item is appended to its parent
        - if already present, pick it up and update the text
        - if not, create one itemR   R   R   R,   R-   i    R   N(	   R!   R+   R   R$   R   Re   R?   R   Ri   (   R   R,   Rm   R   R   R%   (    (    s   C:\py\_spe\sm\wxp\realtime.pyRn   ^  s    			/c         C   s&   |  i  | | ƒ } |  i | | ƒ | S(   N(   Rn   Rb   (   R   R,   Rm   t
   imageIndexR%   (    (    s   C:\py\_spe\sm\wxp\realtime.pyt   InsertImageStringItemv  s    c         C   sY   | i  | j o) | | _  | i i t i i | f ƒ n | i i t i i | f ƒ d  S(   N(   RE   R
   R?   R   Rf   Rb   R   (   R   R%   Rq   (    (    s   C:\py\_spe\sm\wxp\realtime.pyRb   {  s    	 c         C   sY   | i  | j o) | | _  | i i t i i | f ƒ n | i i t i i | f ƒ d  S(   N(   R   R
   R?   R   Rf   Ri   R   (   R   R%   R   (    (    s   C:\py\_spe\sm\wxp\realtime.pyRi     s    	 c         C   sY   | i  | j o) | | _  | i i t i i | f ƒ n | i i t i i | f ƒ d S(   s   Sets the text of a TreeItemN(   R-   R
   R?   R   RH   RQ   R   (   R   R%   R-   (    (    s   C:\py\_spe\sm\wxp\realtime.pyRQ   ‡  s    	 c         C   s{   | i  } | i | ƒ p | | | j o- | | | <| i i t i i | | f ƒ n | i i t i i | | f ƒ d  S(   N(   R-   R$   R
   R?   R   Rf   Rj   R   (   R   R%   Rl   Rm   R-   (    (    s   C:\py\_spe\sm\wxp\realtime.pyRj   Ž  s
    	"
#c         C   s   |  i  |  d t ƒd S(   s›   Update only differences between current and previous state.
        This method MUST be called in the end otherwise there will be no visual
        change.R6   N(   R
   R   (   R   (    (    s   C:\py\_spe\sm\wxp\realtime.pyR]   •  s    N(   R   R   R   Rf   R@   R   R3   R.   R/   R4   Ro   Rg   R   Rn   Rr   Rb   Ri   RQ   Rj   R]   (    (    (    s   C:\py\_spe\sm\wxp\realtime.pyRf   /  s   													(    (    (	   RG   R   t   WARNINGR    R   RD   RH   Re   Rf   (    (    (    s   C:\py\_spe\sm\wxp\realtime.pys   <module>	   s   lv