³ò
’\jIc           @   s‚  d  Z  d d k Z d d k Z d d k Z d d k l 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 Z d d k Z d d k Z d d k Z d d k l Z d d k Z e a d Z e d ƒ \ Z Z Z d e i f d „  ƒ  YZ d e i f d	 „  ƒ  YZ d
 e i f d „  ƒ  YZ d e i  f d „  ƒ  YZ! d e i" f d „  ƒ  YZ# d „  Z$ d „  Z% d S(   s    library.py - Comic book library.iÿÿÿÿN(   t   escape(   t   prefsi   t   _LibraryDialogc           B   s>   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d d „ Z RS(   sl   The library window. Automatically creates and uses a new
    librarybackend.LibraryBackend when opened.
    c      	   C   s­  t  i i |  t  i ƒ |  i t d t d ƒ |  i t d ƒ ƒ |  i d |  i	 ƒ d  |  _ | |  _ t  i ƒ  |  _ |  i i t ƒ t i ƒ  |  _ t |  ƒ |  _ t |  ƒ |  _ t |  ƒ |  _ t  i d d t ƒ } | i |  i d d d d t  i t  i t  i Bƒ | i |  i d d d d t  i t  i Bt  i t  i Bƒ | i |  i d d d d t  i t  i Bt  i ƒ | i |  i d d d d t  i t  i ƒ |  i | ƒ |  i  ƒ  d  S(	   Ns   lib window widths   lib window heightt   Libraryt   delete_eventi   i    i   i   (!   t   gtkt   Windowt   __init__t   WINDOW_TOPLEVELt   resizeR   t	   set_titlet   _t   connectt   closet   Nonet   filter_stringt   _file_handlert	   Statusbart
   _statusbart   set_has_resize_gript   Truet   librarybackendt   LibraryBackendt   backendt	   _BookAreat	   book_areat   _ControlAreat   control_areat   _CollectionAreat   collection_areat   Tablet   Falset   attacht   FILLt   EXPANDt   addt   show_all(   t   selft   file_handlert   table(    (    sG   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/library.pyR   #   s,    		%%
(c         C   sE   |  i  i | ƒ } | d j o d Sn |  i ƒ  |  i i | ƒ d S(   s   Open the book with ID <book>.N(   R   t   get_book_pathR   R   R   t	   open_file(   R%   t   bookt   path(    (    sG   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/library.pyt	   open_book=   s
    
c         C   s4   |  i  i d ƒ |  i  i d d t i | ƒ ƒ d S(   s_   Set a specific message on the statusbar, replacing whatever was
        there earlier.
        i    s    %sN(   R   t   popt   pusht   encodingt
   to_unicode(   R%   t   message(    (    sG   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/library.pyt   set_status_messageE   s    c         G   sV   |  i  ƒ  \ t d <t d <|  i i ƒ  |  i i ƒ  |  i i ƒ  t i ƒ  t ƒ  d S(   s0   Close the library and do required cleanup tasks.s   lib window widths   lib window heightN(	   t   get_sizeR   R   t   stop_updateR   R   t   filechoosert    close_library_filechooser_dialogt   _close_dialog(   R%   t   args(    (    sG   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/library.pyR   L   s    
c         C   s˜   | d j o
 d } nF |  i i | ƒ } | d j o& |  i i | ƒ |  i i | ƒ } n t |  | | ƒ | d j	 o | t d <n |  i i ƒ  d S(   s°   Add the books at <paths> to the library. If <collection_name>
        is not None, it is the name of a (new or existing) collection the
        books should be put in.
        s   last library collectionN(   R   R   t   get_collection_by_namet   add_collectiont   _AddBooksProgressDialogR   R   t   display_collections(   R%   t   pathst   collection_namet
   collection(    (    sG   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/library.pyt	   add_booksU   s    
	N(	   t   __name__t
   __module__t   __doc__R   R,   R2   R   R   R@   (    (    (    sG   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/library.pyR      s   					R   c           B   s˜   e  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 d „  Z d „  Z d „  Z RS(   st   The _CollectionArea is the sidebar area in the library where
    different collections are displayed in a tree.
    c      	   C   sW  t  i i |  ƒ | |  _ |  i t  i t  i ƒ t  i t t	 ƒ |  _
 t  i |  i
 ƒ |  _ |  i i d |  i ƒ |  i i d |  i ƒ |  i i d |  i ƒ |  i i d |  i ƒ |  i i d |  i ƒ |  i i d |  i ƒ |  i i d |  i ƒ |  i i t ƒ |  i i t ƒ |  i t ƒ |  i i t  i i d t  i t f g t  i i  ƒ t  i! ƒ  } t  i" d  | d	 d
 ƒ} |  i i$ | ƒ |  i% |  i ƒ t  i& ƒ  |  _' d } |  i' i( | ƒ t  i) d ƒ } | i* d d  t+ d ƒ d  d  |  i, f d t  i- t+ d ƒ d  d  |  i. f d t  i/ t+ d ƒ d  d  |  i0 f g ƒ |  i' i1 | d
 ƒ |  i2 ƒ  d  S(   Nt   cursor_changedt   drag_data_receivedt   drag_motiont
   drag_begint   button_press_eventt   key_press_eventt   row_activatedR?   t   markupi    s  
        <ui>
            <popup name="Popup">
                <menuitem action="rename" />
                <menuitem action="duplicate" />
                <separator />
                <menuitem action="remove" />
            </popup>
        </ui>
        s   comix-library-collection-areat   renames	   Rename...t	   duplicates   Duplicate collectiont   removes   Remove collection...(3   R   t   ScrolledWindowR   t   _libraryt
   set_policyt   POLICY_NEVERt   POLICY_AUTOMATICt	   TreeStoret   strt   intt
   _treestoret   TreeViewt	   _treeviewR   t   _collection_selectedt   _drag_data_receivedt   _drag_motiont   connect_aftert   _drag_begint   _button_presst
   _key_presst   _expand_or_collapse_rowt   set_headers_visibleR   t   set_rules_hintR   t   _set_acceptable_dropt   enable_model_drag_sourcet   gdkt   BUTTON1_MASKt   TARGET_SAME_WIDGETt   _DRAG_COLLECTION_IDt   ACTION_MOVEt   CellRendererTextt   TreeViewColumnR   t   append_columnR#   t	   UIManagert   _ui_managert   add_ui_from_stringt   ActionGroupt   add_actionsR   t   _rename_collectiont
   STOCK_COPYt   _duplicate_collectiont   STOCK_REMOVEt   _remove_collectiont   insert_action_groupR<   (   R%   t   libraryt   cellrenderert   columnt   ui_descriptiont   actiongroup(    (    sG   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/library.pyR   o   sF    	
		c         C   s5   |  i  i ƒ  } | d j o d Sn |  i | d ƒ S(   sv   Return the collection ID for the currently selected collection,
        or None if no collection is selected.
        Ni    (   RY   t
   get_cursorR   t   _get_collection_at_path(   R%   t   cursor(    (    sG   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/library.pyt   get_current_collection    s    c      	      s£   ‡ ‡ f d †  ‰ ‡  ‡ f d †  } ‡ ‡  f d †  } g  ‰  ˆ i  i | ƒ ˆ i i ƒ  ˆ i i d d t t d ƒ ƒ t g ƒ ˆ d d ƒ ˆ i i	 | ƒ d S(   sT  Display the library collections by redrawing them from the
        backend data. Should be called on startup or when the collections
        hierarchy has been changed (e.g. after moving, adding, renaming).
        Any row that was expanded before the call will have it's
        corresponding new row also expanded after the call.
        c            sg   x` ˆ  i  i i | ƒ D]I } ˆ  i  i i | ƒ } ˆ  i i |  t | ƒ | g ƒ } ˆ | | ƒ q Wd  S(   N(   RP   R   t   get_collections_in_collectiont   get_collection_nameRW   t   appendt	   xmlescape(   t   parent_itert	   supercollt   collt   namet
   child_iter(   R%   t   _recursive_add(    sG   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/library.pyR‹   ±   s     c            sv   |  i  | d ƒ } | t d j o. d  t d <ˆ i i | ƒ ˆ i i | ƒ n" | ˆ  j o ˆ i i | ƒ n d  S(   Ni   s   last library collection(   t	   get_valueR   R   RY   t   expand_to_patht
   set_cursor(   t	   treestoreR+   t   iteratorR?   (   t   expanded_collectionsR%   (    sG   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/library.pyt   _expand_and_select¹   s    
c            s    ˆ  i  | ƒ } ˆ i | ƒ d  S(   N(   R   R„   (   t   treeviewR+   R?   (   R%   R‘   (    sG   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/library.pyt   _expanded_rows_accumulatorÃ   s    s	   <b>%s</b>s	   All booksN(
   RY   t   map_expanded_rowsRW   t   clearR„   R   R…   R   t   _COLLECTION_ALLt   foreach(   R%   R’   R”   (    (   R‘   R%   R‹   sG   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/library.pyR<   ©   s    

c         C   s%   |  i  i | ƒ } |  i  i | d ƒ S(   sU   Return the collection ID of the collection at the (TreeView)
        <path>.
        i   (   RW   t   get_iterRŒ   (   R%   R+   R   (    (    sG   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/library.pyR   Ï   s    c         C   sY   |  i  ƒ  } | d j p | t d j o d Sn | t d <t i |  i i i | ƒ d S(   s†   Change the viewed collection (in the _BookArea) to the
        currently selected one in the sidebar, if it has been changed.
        s   last library collectionN(   R   R   R   t   gobjectt   idle_addRP   R   t   display_covers(   R%   R“   R?   (    (    sG   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/library.pyRZ   Ö   s    
c         C   sž   t  i |  i d t  i t  i t d ƒ ƒ } | i t d ƒ ƒ | i ƒ  } | i ƒ  | t  i	 j o7 |  i
 ƒ  } |  i i i | ƒ t t d <|  i ƒ  n d S(   sr   Remove the currently selected collection from the library, if the
        user answers 'Yes' in a dialog.
        i    s#   Remove collection from the library?s–   The selected collection will be removed from the library (but the books and subcollections in it will remain). Are you sure that you want to continue?s   last library collectionN(   R   t   MessageDialogRP   t   MESSAGE_QUESTIONt   BUTTONS_YES_NOR   t   format_secondary_textt   runt   destroyt   RESPONSE_YESR   R   t   remove_collectionR—   R   R<   (   R%   t   actiont   choice_dialogt   responseR?   (    (    sG   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/library.pyRw   á   s    

c   
   
   C   s¬  |  i  ƒ  } y |  i i i | ƒ } Wn t j
 o d Sn Xt i |  i d t i t i t	 d ƒ ƒ } | i
 t	 d ƒ ƒ | i t i ƒ t i ƒ  } | i i | ƒ t i ƒ  } | i | ƒ | i t ƒ | i | t t d ƒ | i ƒ  | i ƒ  } | i ƒ  } | i ƒ  | t i j oˆ | o |  i i i | | ƒ o |  i ƒ  q¨t	 d ƒ | }	 |  i i i | ƒ d j	 o d |	 t	 d ƒ f }	 n |  i i |	 ƒ n d S(	   s9   Rename the currently selected collection, using a dialog.Ni    s   Rename collection?s4   Please enter a new name for the selected collection.i   s"   Could not change the name to '%s'.s   %s %ss)   A collection by that name already exists.(   R   RP   R   Rƒ   t	   ExceptionR   R   Rž   t   BUTTONS_OK_CANCELR   R    t   set_default_responset   RESPONSE_OKt   HBoxt   vboxt
   pack_startt   Entryt   set_textt   set_activates_defaultR   R$   R¡   t   get_textR¢   t   rename_collectionR<   R9   R   R2   (
   R%   R¥   R?   t   old_namet   rename_dialogt   boxt   entryR§   t   new_nameR1   (    (    sG   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/library.pyRs   ò   s<    	


c         C   sJ   |  i  ƒ  } |  i i i | ƒ o |  i ƒ  n |  i i t d ƒ ƒ d S(   s,   Duplicate the currently selected collection.s   Could not duplicate collection.N(   R   RP   R   t   duplicate_collectionR<   R2   R   (   R%   R¥   R?   (    (    sG   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/library.pyRu     s
    	c         C   s÷   | i  t | i ƒ t | i ƒ ƒ } | d j o d Sn | d } | i d j o  |  i | ƒ t j o
 t } n t	 } |  i
 i d ƒ i | ƒ |  i
 i d ƒ i | ƒ |  i
 i d ƒ i | ƒ |  i
 i d ƒ i d d d | i | i ƒ n d S(   s3   Handle mouse button presses on the _CollectionArea.Ni    i   s   /Popup/renames   /Popup/duplicates   /Popup/removes   /Popup(   t   get_path_at_posRV   t   xt   yR   t   buttonR   R—   R   R   Ro   t
   get_actiont   set_sensitivet
   get_widgett   popupt   time(   R%   R“   t   eventt   rowR+   t   sens(    (    sG   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/library.pyR_     s    $

c         C   s(   | i  t i i j o |  i ƒ  n d S(   s*   Handle key presses on the _CollectionArea.N(   t   keyvalR   t   keysymst   DeleteRw   (   R%   R“   RÃ   (    (    sG   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/library.pyR`   0  s    c         C   s2   | i  | ƒ o | i | ƒ n | i | ƒ d S(   s%   Expand or collapse the activated row.N(   t   row_expandedt   collapse_rowR   (   R%   R“   R+   R{   (    (    sG   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/library.pyRa   5  s    c         C   sƒ  |  i  i d ƒ | i | | ƒ } | d j o$ t |  i ƒ d f t i }	 }
 n | \ }	 }
 |  i ƒ  } |  i	 |	 ƒ } | t
 j oV |
 t i t i f j o |  i  i i | ƒ } n |  i  i i | | ƒ |  i ƒ  n£ | t j o• x’ | i ƒ  i d ƒ D]w } |  i  i i t | ƒ ƒ } |  i  i i | | ƒ | t j o3 |  i  i i | | ƒ |  i  i i t | ƒ ƒ q q Wn d S(   s   Move books dragged from the _BookArea to the target collection,
        or move some collection into another collection.
        t    i   t   ,N(   RP   R2   t   get_dest_row_at_posR   t   lenRW   R   t   TREE_VIEW_DROP_AFTERR   R   Ri   t   TREE_VIEW_DROP_BEFORER   t   get_supercollectiont   add_collection_to_collectionR<   t   _DRAG_BOOK_IDR²   t   splitR   t   get_book_at_pathRV   t   add_book_to_collectionR—   t   remove_book_from_collectiont   remove_book_at_path(   R%   R“   t   contextR»   R¼   t	   selectiont   drag_idt	   eventtimet   drop_rowt	   dest_patht   post   src_collectiont   dest_collectiont   path_strR*   (    (    sG   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/library.pyR[   <  s2    
 c         G   s  | i  | | ƒ } |  i ƒ  } | i ƒ  |  i j oŒ| i ƒ  i ƒ  \ } }	 | d j o! t | ƒ d f t i	 }
 } n | \ }
 } | i
 |
 ƒ } | i |	 | ƒ o% |  i t ƒ |  i i d ƒ d Sn |  i |
 ƒ } | t i t i	 f j o |  i i i | ƒ } n t | | f j p | | j o% |  i t ƒ |  i i d ƒ d Sn |  i i i | ƒ } | d j o t d ƒ } n |  i i i | ƒ } t d ƒ h  | d <| d <} n8| d j o% |  i t ƒ |  i i d ƒ d Sn | \ }
 } | t i t i	 f j o% |  i t ƒ |  i i d ƒ d Sn |  i |
 ƒ } | | j p | t j o% |  i t ƒ |  i i d ƒ d Sn |  i i i | ƒ } | t j o t d ƒ | } n8 |  i i i | ƒ } t d	 ƒ h  | d
 <| d <} |  i t ƒ |  i i | ƒ d S(   s†  Set the library statusbar text when hovering a drag-n-drop over
        a collection (either books or from the collection area itself).
        Also set the TreeView to accept drops only when we are hovering over
        a valid drop position for the current drop type.

        This isn't pretty, but the details of treeviews and drag-n-drops
        are not pretty to begin with.
        i   RË   Nt   RootsO   Put the collection '%(subcollection)s' in the collection '%(supercollection)s'.t   subcollectiont   supercollections   Add books to '%s'.sH   Move books from '%(source collection)s' to '%(destination collection)s'.s   source collections   destination collection(   RÍ   R   t   get_source_widgetRY   t   get_selectiont   get_selectedR   RÎ   R   RÏ   R™   t   is_ancestorRd   R   RP   R2   R   RÐ   R   RÑ   R—   Rƒ   R   R   (   R%   R“   RÙ   R»   R¼   R8   RÝ   Rà   t   modelt   src_iterRÞ   Rß   t	   dest_iterRá   t   src_namet	   dest_nameR1   (    (    sG   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/library.pyR\   [  sn    	!						c         C   s_   | o; |  i  i d t i t f d t i t f g t i i ƒ n |  i  i g  t i i ƒ d S(   s9   Set the TreeView to accept drops if <acceptable> is True.R*   R?   N(	   RY   t   enable_model_drag_destR   t   TARGET_SAME_APPRÓ   Rh   Ri   Rf   Rj   (   R%   t
   acceptable(    (    sG   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/library.pyRd   ¡  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  Create a cursor image for drag-n-drop of collections. We use the
        default one (i.e. the row with text), but put the hotspot in the
        top left corner so that one can actually see where one is dropping,
        which unfortunately isn't the default case.
        i    i   iûÿÿÿN(   R~   t   create_row_drag_iconR   Rf   t   Pixbuft   COLORSPACE_RGBR   R3   t   get_from_drawablet   get_colormapt   set_icon_pixbuf(   R%   R“   RÙ   R+   t   pixmapt   pointer(    (    sG   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/library.pyR^   «  s    N(   RA   RB   RC   R   R   R<   R   RZ   R   Rw   Rs   Ru   R_   R`   Ra   R[   R\   Rd   R^   (    (    (    sG   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/library.pyR   i   s    	1			&			$							F	
R   c           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 d „  Z d „  Z d „  Z RS(   s^   The _BookArea is the central area in the library where the book
    covers are displayed.
    c      	   C   so  t  i i |  ƒ | |  _ t |  _ |  i t  i t  i ƒ t  i t  i	 i
 t ƒ |  _ t  i |  i ƒ |  _ |  i i d ƒ |  i i d |  i ƒ |  i i d |  i ƒ |  i i d |  i ƒ |  i i d |  i ƒ |  i i d |  i ƒ |  i i d |  i ƒ |  i i d |  i ƒ |  i i t  i t  i	 i ƒ  ƒ |  i i d d	 t  i t f g t  i	 i ƒ |  i i  t  i! d
 d t" f g t  i	 i# t  i	 i Bƒ |  i i$ t  i% ƒ |  i& |  i ƒ t  i' ƒ  |  _( d } |  i( i) | ƒ t  i* d ƒ } | i+ d t  i, t- d ƒ d  d  |  i/ f d t  i0 t- d ƒ d  d  |  i1 f d t  i2 t- d ƒ d  d  |  i3 f g ƒ |  i( i4 | d ƒ d  S(   Ni    t   item_activatedt   selection_changedRG   t   drag_data_getRE   RH   RI   R*   s   text/uri-lists  
        <ui>
            <popup name="Popup">
                <menuitem action="open" />
                <separator />
                <menuitem action="remove from collection" />
                <menuitem action="remove from library" />
            </popup>
        </ui>
        s   comix-library-book-areat   opent   Opens   remove from collections   Remove from this collections   remove from librarys   Remove from the library...(5   R   RO   R   RP   R   t   _stop_updateRQ   RS   t	   ListStoreRf   Ró   RV   t
   _liststoret   IconViewt	   _iconviewt   set_pixbuf_columnR   t   _book_activatedt   _selection_changedR]   R^   t   _drag_data_getR[   R_   R`   t   modify_baset   STATE_NORMALt   ColorRe   Rð   RÓ   Rj   t   drag_dest_sett   DEST_DEFAULT_ALLt   _DRAG_EXTERNAL_IDt   ACTION_COPYt   set_selection_modet   SELECTION_MULTIPLER#   Rn   Ro   Rp   Rq   Rr   t
   STOCK_OPENR   R   t   open_selected_bookRv   t   _remove_books_from_collectiont   STOCK_DELETEt   _remove_books_from_libraryRx   (   R%   Ry   R|   R}   (    (    sG   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/library.pyR   Â  sJ    		
				c         C   s   |  i  i ƒ  |  i i ƒ  d S(   s6   Run clean-up tasks for the _BookArea prior to closing.N(   R  t   unselect_allR  R–   (   R%   (    (    sG   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/library.pyR   ô  s    c         C   sÅ   t  |  _ |  i i ƒ  | t j o
 d } n xˆ t |  i i i	 | |  i i
 ƒ ƒ D]b \ } } |  i | ƒ | d d j o8 x t i ƒ  o t i t  ƒ q W|  i o d Sq´ qR qR Wt |  _ d S(   s2   Display the books in <collection> in the IconView.i   i    N(   R   Rÿ   R  R–   R—   R   t	   enumerateRP   R   t   get_books_in_collectionR   t	   _add_bookR   t   events_pendingt   main_iterationR   (   R%   R?   t   iR*   (    (    sG   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/library.pyRœ   þ  s    	
  
c         C   s   t  |  _ d S(   s4   Signal that the updating of book covers should stop.N(   R   Rÿ   (   R%   (    (    sG   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/library.pyR4     s    c         C   s&   |  i  i | ƒ } |  i  i | ƒ d S(   s\   Remove the book at <path> from the ListStore (and thus from
        the _BookArea).
        N(   R  R™   RN   (   R%   R+   R   (    (    sG   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/library.pyRØ     s    c         C   s%   |  i  i | ƒ } |  i  i | d ƒ S(   s8   Return the book ID corresponding to the IconView <path>.i   (   R  R™   RŒ   (   R%   R+   R   (    (    sG   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/library.pyRÕ     s    c         G   s?   |  i  i ƒ  } | p d Sn | d } |  i |  i  | ƒ d S(   s!   Open the currently selected book.Ni    (   R  t   get_selected_itemsR  (   R%   R8   t   selectedR+   (    (    sG   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/library.pyR    s
    
c         C   s—   |  i  i i | ƒ } | d j o |  i  i t i t i ƒ } n t i	 | t
 d t d ƒ t d ƒ } t i | d d ƒ } |  i i | | g ƒ d S(   s<   Add the <book> to the ListStore (and thus to the _BookArea).gq=
×£på?s   library cover sizei   l   ÿÿ N(   RP   R   t   get_book_coverR   t   render_iconR   t   STOCK_MISSING_IMAGEt   ICON_SIZE_DIALOGt   imaget   fit_in_rectangleRV   R   t
   add_borderR  R„   (   R%   R*   t   pixbuf(    (    sG   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/library.pyR  &  s    	c         C   s#   |  i  | ƒ } |  i i | ƒ d S(   s(   Open the book at the (liststore) <path>.N(   RÕ   RP   R,   (   R%   t   iconviewR+   R*   (    (    sG   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/library.pyR  3  s    c         C   s#   | i  ƒ  } |  i i i | ƒ d S(   s[   Update the displayed info in the _ControlArea when a new book
        is selected.
        N(   R  RP   R   t   update_info(   R%   R'  R  (    (    sG   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/library.pyR  8  s    c         G   sÄ   |  i  i i ƒ  } | t j o d Sn |  i i ƒ  } x@ | D]8 } |  i | ƒ } |  i  i i | | ƒ |  i	 | ƒ q= W|  i  i i
 | ƒ } |  i  i t d ƒ h  t | ƒ d <| d <ƒ d S(   su   Remove the currently selected book(s) from the current collection,
        and thus also from the _BookArea.
        Ns.   Removed %(num)d book(s) from '%(collection)s'.t   numR?   (   RP   R   R   R—   R  R  RÕ   R   R×   RØ   Rƒ   R2   R   RÎ   (   R%   R8   R?   R  R+   R*   t	   coll_name(    (    sG   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/library.pyR  ?  s     		c         G   sÚ   t  i |  i d t  i t  i t d ƒ ƒ } | i t d ƒ ƒ | i ƒ  } | i ƒ  | t  i	 j os |  i
 i ƒ  } x= | D]5 } |  i | ƒ } |  i i i | ƒ |  i | ƒ qy W|  i i t d ƒ t | ƒ ƒ n d S(   s   Remove the currently selected book(s) from the library, and thus
        also from the _BookArea, if the user clicks 'Yes' in a dialog.
        i    s   Remove books from the library?s‡   The selected books will be removed from the library (but the original files will be untouched). Are you sure that you want to continue?s$   Removed %d book(s) from the library.N(   R   R   RP   Rž   RŸ   R   R    R¡   R¢   R£   R  R  RÕ   R   t   remove_bookRØ   R2   RÎ   (   R%   R8   R¦   R§   R  R+   R*   (    (    sG   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/library.pyR  P  s     
 	c         C   so  | i  t | i ƒ t | i ƒ ƒ } | d j o d Sn | i t i i j o |  i	 | | ƒ n | i
 d j oø | i | ƒ p | i ƒ  | i | ƒ n t | i ƒ  ƒ d j o |  i i d ƒ i t ƒ n |  i i d ƒ i t ƒ |  i i i ƒ  t j o |  i i d ƒ i t ƒ n |  i i d ƒ i t ƒ |  i i d ƒ i d d d | i
 | i ƒ n d S(   s-   Handle mouse button presses on the _BookArea.Ni   i   s   /Popup/opens   /Popup/remove from collections   /Popup(   Rº   RV   R»   R¼   R   t   typeR   Rf   t   _2BUTTON_PRESSR  R½   t   path_is_selectedR  t   select_pathRÎ   R  Ro   R¾   R¿   R   R   RP   R   R   R—   RÀ   RÁ   RÂ   (   R%   R'  RÃ   R+   (    (    sG   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/library.pyR_   d  s(    $

		c         C   s(   | i  t i i j o |  i ƒ  n d S(   s$   Handle key presses on the _BookArea.N(   RÆ   R   RÇ   RÈ   R  (   R%   R'  RÃ   (    (    sG   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/library.pyR`     s    c         C   s   | i  ƒ  d } t | i ƒ  ƒ } |  i | ƒ } |  i i i | ƒ } | d j o |  i i t	 i
 t	 i ƒ } n | i t d | i ƒ  d ƒ t d | i ƒ  d ƒ t	 i i ƒ } t i | d d ƒ } t i | d ƒ } | d j oœ| i ƒ  } | i ƒ  } t	 i i t	 i i t d t d | d ƒ t d | d ƒ ƒ }	 |	 i d ƒ | i |	 d d | | d d d d t	 i i d	 ƒ t i d
 d d ƒ }
 t i |
 ƒ } | i d d d d d ƒ| i d d d d d ƒt | ƒ } | i d d t | ƒ d d f | d d ƒt i  |
 ƒ } | i |	 t d | d ƒ t d | d ƒ d d t d | d ƒ t d | d ƒ d d t	 i i d	 ƒ n | }	 | i! |	 d d ƒ d S(   s'  Create a cursor image for drag-n-drop from the library.

        This method relies on implementation details regarding PIL's 
        drawing functions and default font to produce good looking results.
        If those are changed in a future release of PIL, this method might
        produce bad looking output (e.g. non-centered text).
        
        It's also used with connect_after() to overwrite the cursor
        automatically created when using enable_model_drag_source(), so in
        essence it's a hack, but at least it works.
        i    i   i   l   ÿÿ i   i   i   i
   iÿ   t   RGBAi   i   t   fillt   outlinei   i€   i   i	   iûÿÿÿN(   i   i   (   i   i    i   i    i   i   i   i   i   i   i   i   i    i   i    i   (   i    i    i    (   i    i    i    (   i   i   i   i   i   i   i   i   i   i   i   i   i   i   i   i   (   i€   i    i    (   iÿ   iÿ   iÿ   (   iÿ   iÿ   iÿ   ("   R~   RÎ   R  RÕ   RP   R   R  R   R   R   R!  R"  t   scale_simplet   maxt	   get_widtht
   get_heightRf   t   INTERP_TILESR#  R%  Ró   Rô   R   R1  t	   compositet   Imaget   newt	   ImageDrawt   Drawt   polygonRU   t   textt   pil_to_pixbufR÷   (   R%   R'  RÙ   t	   icon_patht	   num_booksR*   t   covert   cover_widtht   cover_heightRù   t   imt   drawR>  t   circle(    (    sG   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/library.pyR^   „  sH    %&'&*c   	      G   sW   | i  ƒ  } d i g  } | D] } | t | d ƒ q ~ ƒ } | i d d | ƒ d S(   sŽ   Fill the SelectionData with (iconview) paths for the dragged books
        formatted as a string with each path separated by a comma.
        RÌ   i    s
   text/plaini   N(   R  t   joinRU   t   set(	   R%   R'  RÙ   RÚ   R8   R=   t   _[1]R+   R>  (    (    sG   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/library.pyR  ¹  s    4c         G   sæ   | i  ƒ  } | p d Sn g  } x„ | D]| }	 |	 i d ƒ o |	 d }	 n= |	 i d ƒ o |	 d }	 n |	 i d ƒ o |	 d }	 n t i |	 ƒ }
 | i |
 ƒ q( W|  i i i ƒ  } |  i i i	 | ƒ } |  i i
 | | ƒ d S(   ss   Handle drag-n-drop events ending on the book area (i.e. from
        external apps like the file manager).
        Ns   file://localhost/i   s   file:///i   s   file:/i   (   t   get_urist
   startswitht   urllibt   url2pathnameR„   RP   R   R   R   Rƒ   R@   (   R%   t   widgetRÙ   R»   R¼   t   dataR8   t   urisR=   t   uriR+   R?   R>   (    (    sG   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/library.pyR[   Á  s"     (   RA   RB   RC   R   R   Rœ   R4   RØ   RÕ   R  R  R  R  R  R  R_   R`   R^   R  R[   (    (    (    sG   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/library.pyR   ¼  s$   	2	
													5	R   c           B   sD   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s‡   The _ControlArea is the bottom area of the library window where
    information is displayed and controls such as buttons resides.
    c         C   s  | |  _  t i i |  t d ƒ |  i d ƒ t i ƒ  } | i t i t i	 i
 d ƒ ƒ | i d d ƒ t i ƒ  } | i d ƒ | i t i t i	 i
 d ƒ ƒ t i t d ƒ } | i d ƒ |  i | t t ƒ | i | ƒ | i | ƒ t i ƒ  |  _ |  i i t i ƒ |  i i d	 d
 ƒ | i |  i t t ƒ t i ƒ  |  _ |  i i t i ƒ |  i i d	 d
 ƒ | i |  i t t ƒ t i ƒ  |  _ |  i i t i ƒ |  i i d	 d
 ƒ | i |  i t t ƒ t i ƒ  |  _ |  i i t i ƒ |  i i d	 d
 ƒ | i |  i t t ƒ t i t d ƒ } |  i | t t ƒ t i t ƒ } | i | t t ƒ t i d t d ƒ ƒ } | i | t t ƒ t i ƒ  } | i d |  i ƒ | i t d ƒ ƒ | i | t t d ƒ t i d t d ƒ ƒ } | i | t t d ƒ t i  t! d d d d d d	 ƒ }	 t i" |	 ƒ }
 |
 i d d ƒ |
 i# t ƒ |
 i d |  i$ ƒ | i |
 t t ƒ | i t i ƒ  t t ƒ t i t d ƒ } | i | t t ƒ t i% t d ƒ ƒ } | i& t i' t i( t i) ƒ ƒ | i d |  i* ƒ | i t d ƒ ƒ | i | t t ƒ t i% t d ƒ ƒ } | i d |  i+ ƒ | i& t i' t i( t i) ƒ ƒ | i t d ƒ ƒ | i | t t ƒ | i t i ƒ  t t ƒ t i% d  t i- ƒ |  _. |  i. i d |  i  i/ i0 ƒ |  i. i t d ƒ ƒ |  i. i1 t ƒ | i |  i. t t ƒ d  S(   Ni   i
   s   #333i^  iÿÿÿÿi   s   #ddbi   i    g      à?s   %s:t   Searcht   activatesr   Display only those books that have the specified text string in their full path. The search is not case sensitive.i   s
   Cover sizes   library cover sizei2   i€   i–   t   value_changeds	   Add bookst   clickeds   Add more books to the library.s   Add collections   Add a new empty collection.s   Open the selected book.(2   RP   R   R¬   R   R   t   set_border_widtht   EventBoxt	   modify_bgR	  Rf   t   color_parset   set_size_requestt   VBoxR®   R#   t   labelst	   BoldLabelt
   _namelabelt   set_ellipsizet   pangot   ELLIPSIZE_MIDDLEt   set_alignmentt   Labelt   _pageslabelt
   _filelabelt	   _dirlabelR   R   R¯   R   t   _filter_bookst   set_tooltip_textt
   AdjustmentR   t   HScalet   set_draw_valuet   _change_cover_sizet   Buttont	   set_imaget   image_new_from_stockt	   STOCK_ADDt   ICON_SIZE_BUTTONt
   _add_bookst   _add_collectionR   R  t   _open_buttonR   R  R¿   (   R%   Ry   t	   borderboxt	   insideboxt   infoboxR­   t   hboxt   labelt   search_entryt
   adjustmentt   cover_size_scalet   add_book_buttont   add_collection_button(    (    sG   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/library.pyR   Ý  s’    	c         C   sò  |  i  i t ƒ | o’ |  i i i | d ƒ } |  i i i | ƒ } t i	 i
 |  i i i | ƒ ƒ } |  i i i | ƒ } |  i i i | ƒ } |  i i i | ƒ } n d } } } } } t | ƒ d j o |  i  i t ƒ n | d j	 o |  i i t i | ƒ ƒ n |  i i d ƒ | d j	 o |  i i t d ƒ | ƒ n |  i i d ƒ | d j	 o< | d j	 o/ |  i i d t i | ƒ d | d f ƒ n |  i i d ƒ | d j	 o |  i i t i | ƒ ƒ n |  i i d ƒ d S(	   s]   Update the info box using the currently <selected> books from
        the _BookArea.
        i    i   RË   s   %d pagess   %s, %ss   %.1f MiBg      0AN(   Ru  R¿   R   RP   R   RÕ   R   t   get_book_namet   osR+   t   dirnameR(   t   get_book_formatt   get_book_pagest   get_book_sizeR   RÎ   R   R_  R°   R/   R0   Re  R   Rf  t   archivet   get_nameRg  (   R%   R  R*   R‰   t   dir_patht   formatt   pagest   size(    (    sG   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/library.pyR(  +  s2    	c         G   s   t  i |  i ƒ d S(   s[   Open up a filechooser dialog from which books can be added to
        the library.
        N(   R5   t   open_library_filechooser_dialogRP   (   R%   R8   (    (    sG   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/library.pyRs  N  s    c   	      G   s’  t  i d
 d t  i t  i t d ƒ ƒ } | i t d ƒ ƒ | i t  i ƒ t  i	 ƒ  } | i
 i | ƒ t  i ƒ  } | i t d ƒ ƒ | i t ƒ | i | t t d ƒ | i ƒ  | i ƒ  } | i ƒ  } | i ƒ  | t  i j oª | o£ |  i i i | ƒ o3 |  i i i | ƒ } | t d <|  i i i ƒ  qŽt d ƒ | } |  i i i | ƒ d
 j	 o d | t d	 ƒ f } n |  i i | ƒ n d
 S(   s6   Add a new collection to the library, through a dialog.i    s   Add new collection?s+   Please enter a name for the new collection.s   New collectioni   s   last library collections+   Could not add a new collection called '%s'.s   %s %ss)   A collection by that name already exists.N(   R   R   R   Rž   R©   R   R    Rª   R«   R¬   R­   R®   R¯   R°   R±   R   R$   R¡   R²   R¢   RP   R   R:   R9   R   R   R<   R2   (	   R%   R8   t
   add_dialogR¶   R·   R§   R‰   R?   R1   (    (    sG   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/library.pyRt  T  s6    


	
c         G   s^   | i  ƒ  |  i _ |  i i p d |  i _ n |  i i i ƒ  } t i |  i i i	 | ƒ d S(   sœ   Display only the books in the current collection whose paths
        contain the string in the gtk.Entry. The string is not
        case-sensitive.
        N(
   R²   RP   R   R   R   R   Rš   R›   R   Rœ   (   R%   R·   R8   R?   (    (    sG   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/library.pyRh  u  s
    c         C   sE   t  | i ƒ  ƒ t d <|  i i i ƒ  } t i |  i i i	 | ƒ d S(   s/   Change the size of the covers in the _BookArea.s   library cover sizeN(
   RV   RŒ   R   RP   R   R   Rš   R›   R   Rœ   (   R%   t   scaleR?   (    (    sG   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/library.pyRm  €  s    (	   RA   RB   RC   R   R(  Rs  Rt  Rh  Rm  (    (    (    sG   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/library.pyR   ×  s   	N	#		!	R;   c           B   s    e  Z d  Z d „  Z d „  Z RS(   s9   Dialog with a ProgressBar that adds books to the library.c         C   sò  t  i i |  t d ƒ | t  i t  i t  i f ƒ t |  _ |  i	 d d ƒ |  i
 t ƒ |  i t ƒ |  i d ƒ |  i d |  i ƒ |  i t  i ƒ t  i t d ƒ } | i d ƒ |  i i | t t ƒ t  i t d ƒ } | i | t t d ƒ t  i t d ƒ } t  i t d ƒ } | i | t t ƒ | i | t t ƒ t i d	 t d
 ƒ ƒ } | i d d ƒ | i | t t ƒ t  i d ƒ }	 |	 i d d ƒ | i |	 t t ƒ t  i ƒ  }
 | i |
 t t ƒ t i ƒ  } | i d d ƒ | i t i ƒ | i | t t ƒ |  i ƒ  t t  | ƒ ƒ } d } x¸ t! | ƒ D]ª \ } } | i" i# | | ƒ o | d 7} |	 i$ d | ƒ n | i$ t d ƒ t% i& | ƒ ƒ |
 i' | d | ƒ x t  i( ƒ  o t  i) t ƒ q¯W|  i o d Sq6q6W|  i ƒ  d S(   sk   Adds the books at <paths> to the library, and also to the
        <collection>, unless it is None.
        s   Adding booksi  iÿÿÿÿi   R§   i   i   i
   s   %s:s   Added booksg      ð?t   0i    g      à?i   s   %ds   Adding '%s'...N(*   R   t   DialogR   R   t   DIALOG_MODALt
   STOCK_STOPt   RESPONSE_CLOSER   t   _destroyR[  t   set_has_separatort   set_resizableRW  R   t	   _responseRª   R\  R­   R®   R¬   R   R]  R^  Rc  Rd  t   ProgressBart   ItalicLabelR`  Ra  Rb  R$   t   floatRÎ   R  R   t   add_bookR°   R/   R0   t   set_fractionR  R  (   R%   Ry   R=   R?   t   main_boxRy  t   left_boxt	   right_boxRz  t   number_labelt   bart   added_labelt   total_pathst   total_addedR  R+   (    (    sG   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/library.pyR   ‹  s^    	
 
 
c         G   s   t  |  _ |  i ƒ  d  S(   N(   R   R”  R¢   (   R%   R8   (    (    sG   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/library.pyR—  Â  s    	(   RA   RB   RC   R   R—  (    (    (    sG   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/library.pyR;   ‡  s   	7c         C   sD   t  d  j o) t i d  j o	 d GHq@ t | ƒ a  n t  i ƒ  d  S(   Ns0   ! You need an sqlite wrapper to use the library.(   t   _dialogR   R   t   dbapi2R   t   present(   R¥   t   window(    (    sG   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/library.pyt   open_dialogÇ  s
    	c          G   s/   t  d  j	 o t  i ƒ  d  a  t i ƒ  n d  S(   N(   R¥  R   R¢   t   gct   collect(   R8   (    (    sG   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/library.pyR7   Ò  s    
(&   RC   R  Rª  RM  t   xml.sax.saxutilsR    R…   R   Rš   Ra  R9  R;  R†  R/   R5   R]  R   t   preferencesR   R#  R   R¥  R—   t   rangeR  RÓ   Ri   R   R   RO   R   R   R¬   R   R  R;   R©  R7   (    (    (    sG   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/library.pys   <module>   s8   Lÿ Tÿ °@	