³ò
4ä%Ic           @   s   d  Z  d d k Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k l Z d d k	 Z	 d e i
 f d „  ƒ  YZ d „  Z d S(   s0   thumbbar.py - Thumbnail sidebar for main window.iÿÿÿÿN(   t   prefst   ThumbnailSidebarc           B   sŒ   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z RS(   s<   A thumbnail sidebar including scrollbar for the main window.c         C   sA  t  i i |  t d ƒ | |  _ t |  _ d  |  _ d |  _ t  i	 t  i
 i ƒ |  _ t  i |  i ƒ |  _ |  i i t  i
 i d g t  i
 i ƒ t  i d  ƒ |  _ t  i ƒ  } t  i ƒ  |  _ |  i i |  i d d ƒ |  i i t  i ƒ |  i i |  i ƒ |  i i | t ƒ |  i i | d d ƒ|  i i t d d ƒ |  i i  t d d d ƒ |  i i! t ƒ |  i i" ƒ  |  _# d |  i# _$ d |  i# _% t  i& d  ƒ |  _' |  i' i( |  i# ƒ |  i i) ƒ  |  _* |  i |  i ƒ |  i |  i' ƒ |  i i+ d |  i, ƒ |  i i- d	 |  i. ƒ |  i* i- d
 |  i/ ƒ |  i i- d |  i0 ƒ d  S(   Ni    s   text/uri-listt   pixbufs   thumbnail sizei   i   i   t
   drag_begint   drag_data_gett   changedt   scroll_event(   s   text/uri-listi    i    (1   t   gtkt   HBoxt   __init__t   Falset   _windowt   _loadedt   Nonet
   _load_taskt   _heightt	   ListStoret   gdkt   Pixbuft
   _liststoret   TreeViewt	   _treeviewt   enable_model_drag_sourcet   BUTTON1_MASKt   ACTION_COPYt   TreeViewColumnt   _columnt   CellRendererPixbuft   Layoutt   _layoutt   putt
   set_sizingt   TREE_VIEW_COLUMN_FIXEDt   append_columnt
   pack_startt   Truet   set_attributest   set_fixed_widthR    t   set_size_requestt   set_headers_visiblet   get_vadjustmentt   _vadjustt   step_incrementt   page_incrementt
   VScrollbart   _scrollt   set_adjustmentt   get_selectiont
   _selectiont   connect_aftert   _drag_begint   connectt   _drag_data_gett   _selection_eventt   _scroll_event(   t   selft   windowt   cellrenderer(    (    sH   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/thumbbar.pyR	      s@    				c         C   s"   |  i  i ƒ  d |  i i ƒ  d S(   s3   Return the width in pixels of the ThumbnailSidebar.i    (   R   t   size_requestR-   (   R7   (    (    sH   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/thumbbar.pyt	   get_width:   s    c         G   s   |  i  ƒ  d S(   s   Show the ThumbnailSidebar.N(   t   show_all(   R7   t   args(    (    sH   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/thumbbar.pyt   show>   s    c         C   s   |  i  ƒ  d S(   s   Hide the ThumbnailSidebar.N(   t   hide_all(   R7   (    (    sH   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/thumbbar.pyt   hideB   s    c         C   s?   |  i  i ƒ  |  i i d d ƒ d |  _ t |  _ t |  _ d S(   s4   Clear the ThumbnailSidebar of any loaded thumbnails.i    N(	   R   t   clearR   t   set_sizeR   R
   R   R#   t   _stop_update(   R7   (    (    sH   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/thumbbar.pyRA   F   s
    		c         C   sK   |  i  i t d d ƒ |  i i t d d d ƒ |  i ƒ  |  i ƒ  d S(   sU   Reload the thumbnails with the size specified by in the
        preferences.
        s   thumbnail sizei   i    N(   R   R%   R    R   R&   RA   t   load_thumbnails(   R7   (    (    sH   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/thumbbar.pyt   resizeN   s    
c         C   s˜   |  i  p@ |  i i i p/ t d p# t d p |  i i o t d o d Sn t |  _  |  i d j	 o t	 i
 |  i ƒ n t	 i |  i ƒ |  _ d S(   s3   Load the thumbnails, if it is appropriate to do so.s   show thumbnailss   hide alls   hide all in fullscreenN(   R   R   t   file_handlert   file_loadedR    t   is_fullscreenR#   R   R   t   gobjectt   source_removet   idle_addt   _load(   R7   (    (    sH   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/thumbbar.pyRD   W   s    	c         C   s  |  i  p d Sn |  i i |  i i i ƒ  d ƒ |  i i |  i i i ƒ  d |  i ƒ } | i	 |  i
 i ƒ  j  p* | i	 | i |  i
 i ƒ  |  i
 i j od | i	 | i d |  i
 i d } t d | ƒ } t |  i
 i |  i
 i | ƒ } |  i
 i | ƒ n d S(   s–   Select the thumbnail for the currently viewed page and make sure
        that the thumbbar is scrolled so that the selected thumb is in view.
        Ni   i   i    (   R   R0   t   select_pathR   RF   t   get_current_pageR   t   get_background_areaR   t   yR)   t	   get_valuet   heightt	   page_sizet   maxt   mint   uppert	   set_value(   R7   t   rectt   value(    (    sH   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/thumbbar.pyt   update_selectc   s    
		&"c         C   sM  |  i  i i d  j	 o
 t } n t d } t |  _ x t d |  i  i i ƒ  d ƒ D]ß } |  i  i i	 | t d t d | ƒ } t d o t
 | | ƒ n t i | d ƒ } |  i i | g ƒ x t i ƒ  o t i t ƒ qÃ W|  i o d  Sn |  i |  i i | d |  i ƒ i 7_ |  i i d |  i ƒ qS Wt |  _ |  i ƒ  d  S(   Ns   create thumbnailsi   s   thumbnail sizes   show page numbers on thumbnailsi    (   R   RF   t   archive_typeR   R
   R    RC   t   xranget   get_number_of_pagest   get_thumbnailt   _add_page_numbert   imaget
   add_borderR   t   appendR   t   events_pendingt   main_iterationR   R   RO   R   RR   R   RB   R#   RZ   (   R7   t   createt   iR   (    (    sH   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/thumbbar.pyRL   t   s,    

	   
	c         C   s;   y |  i  i ƒ  d d d SWn t j
 o d Sn Xd S(   s/   Return the index of the currently selected row.i   i    N(   R0   t   get_selected_rowst	   ExceptionR   (   R7   (    (    sH   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/thumbbar.pyt   _get_selected_row‹   s    c         C   s8   y |  i  i |  i ƒ  d ƒ Wn t j
 o n Xd S(   s1   Handle events due to changed thumbnail selection.i   N(   R   t   set_pageRi   Rh   (   R7   t   tree_selection(    (    sH   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/thumbbar.pyR5   ’   s    c         C   s‘   | i  t i i j o! |  i i |  i i ƒ  d ƒ nW | i  t i i j o@ |  i i |  i i	 } |  i i t
 |  i i ƒ  d | ƒ ƒ n d S(   s.   Handle scroll events on the thumbnail sidebar.i<   N(   t	   directionR   R   t	   SCROLL_UPR)   RW   RQ   t   SCROLL_DOWNRV   RS   RU   (   R7   t   widgett   eventRV   (    (    sH   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/thumbbar.pyR6   ™   s
    !c         G   sf   yL |  i  ƒ  } |  i i i | d ƒ } d t i | ƒ } | i | g ƒ Wn t j
 o n Xd S(   s‚   Put the URI of the selected file into the SelectionData, so that
        the file can be copied (e.g. to a file manager).
        i   s   file://localhostN(   Ri   R   RF   t   get_path_to_paget   urllibt   pathname2urlt   set_urisRh   (   R7   t   treeviewt   contextt	   selectionR=   t   selectedt   patht   uri(    (    sH   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/thumbbar.pyR4   ¡   s    c         C   sŠ   | i  ƒ  d } | i | ƒ } t i i t i i t d | i ƒ  Œ } | i | | i	 ƒ  d d d d | i ƒ  Œ } | i
 | d d ƒ d S(   sÆ   We hook up on drag_begin events so that we can set the hotspot
        for the cursor at the top left corner of the thumbnail (so that we
        might actually see where we are dropping!).
        i    i   iûÿÿÿN(   t
   get_cursort   create_row_drag_iconR   R   R   t   COLORSPACE_RGBR#   t   get_sizet   get_from_drawablet   get_colormapt   set_icon_pixbuf(   R7   Ru   Rv   Ry   t   pixmapt   pointer(    (    sH   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/thumbbar.pyR2   ­   s    (   t   __name__t
   __module__t   __doc__R	   R;   R>   R@   RA   RE   RD   RZ   RL   Ri   R5   R6   R4   R2   (    (    (    sH   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/thumbbar.pyR      s   	'													c         C   s¶   t  | ƒ } t d t | ƒ d |  i ƒ  ƒ } t d |  i ƒ  ƒ } t i d | | f d ƒ } t i | ƒ } | i	 d | d d ƒt
 i | ƒ } | i d d | | |  d d ƒ d
 S(   s  Add page number <page> in a black rectangle in the top left corner of
    <pixbuf>. This is highly dependent on the dimensions of the built-in
    font in PIL (bad). If the PIL font was changed, this function would
    likely produce badly positioned numbers on the pixbuf.
    i   i   i
   t   RGBi    i   iÿÿÿÿt   filliÿ   N(   i    i    i    (   i   iÿÿÿÿ(   iÿ   iÿ   iÿ   (   t   strRU   t   lenR;   t
   get_heightt   Imaget   newt	   ImageDrawt   Drawt   textR`   t   pil_to_pixbuft	   copy_area(   R   t   pageR   t   widthRR   t   imt   drawt
   num_pixbuf(    (    sH   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/thumbbar.pyR_   ½   s    #(   R†   Rr   R   RI   RŒ   RŽ   R`   t   preferencesR    t	   thumbnailR   R   R_   (    (    (    sH   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/thumbbar.pys   <module>   s   ®