³ò
Pt¡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 e i i e i d ƒ Z	 d e i
 f d „  ƒ  YZ d e i f d „  ƒ  YZ d d d	 „  ƒ  YZ d
 e i f d „  ƒ  YZ d S(   s<   bookmark.py - Bookmarks handler (including menu and dialog).iÿÿÿÿNs   bookmarks.picklet   BookmarksMenuc           B   sV   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(	   sÎ   BookmarksMenu extends gtk.Menu with convenience methods relating to
    bookmarks. It contains fixed items for adding bookmarks etc. as well
    as dynamic items corresponding to the current bookmarks.
    c      	   C   s¢  t  i i |  ƒ | |  _ t  i d ƒ |  _ |  i i d d t d ƒ d d  |  i	 f d d  t d ƒ d d  |  i
 f d	 t  i t d
 ƒ d  d  |  i f g ƒ t  i ƒ  |  _ |  i i d ƒ } | i | i ƒ  ƒ |  i | i ƒ  ƒ |  i i d ƒ } | i | i ƒ  ƒ |  i | i ƒ  ƒ |  i |  i ƒ |  i t  i ƒ  ƒ |  i i d	 ƒ } | i | i ƒ  ƒ |  i | i ƒ  ƒ |  i ƒ  |  i i ƒ  t |  | i ƒ |  _ d  S(   Ns   comix-bookmarkst   add_bookmarks   comix-add-bookmarks   _Add bookmarks
   <Control>dt   edit_bookmarkss   _Edit bookmarks...s
   <Control>bt   clear_bookmarkss   _Clear bookmarks...(   t   gtkt   Menut   __init__t   _windowt   ActionGroupt   _actiongroupt   add_actionst   _t   Nonet   _add_current_to_bookmarkst   _edit_bookmarkst   STOCK_CLEARt   _clear_bookmarkst   SeparatorMenuItemt
   _separatort
   get_actiont   set_accel_groupt   get_accel_groupt   appendt   create_menu_itemt   show_allt   hidet   _BookmarksStoret   file_handlert   _bookmarks_store(   t   selft   uit   windowt   action(    (    sH   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/bookmark.pyR      s2    		
c         C   s+   |  i  | d ƒ | i ƒ  |  i i ƒ  d S(   s   Add <bookmark> to the menu.i   N(   t   insertt   showR   (   R   t   bookmark(    (    sH   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/bookmark.pyR   4   s    
c         C   s2   |  i  | ƒ |  i i ƒ  o |  i i ƒ  n d S(   s    Remove <bookmark> from the menu.N(   t   removeR   t   is_emptyR   R   (   R   R#   (    (    sH   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/bookmark.pyt   remove_bookmark:   s    c         G   s   |  i  i ƒ  d S(   s/   Add the currently viewed file to the bookmarks.N(   R   t   add_current_to_bookmarks(   R   t   args(    (    sH   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/bookmark.pyR   @   s    c         G   s   t  |  i |  i ƒ d S(   s   Open the bookmarks dialog.N(   t   _BookmarksDialogR   R   (   R   R(   (    (    sH   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/bookmark.pyR   D   s    c         G   sx   t  i |  i d t  i t  i t d ƒ ƒ } | i t d ƒ ƒ | i ƒ  } | i ƒ  | t  i	 j o |  i
 i ƒ  n d S(   sZ   Remove all bookmarks, if the user presses 'Yes' in a confirmation
        dialog.
        i    s   Clear all bookmarks?sM   All stored bookmarks will be removed. Are you sure that you want to continue?N(   R   t   MessageDialogR   t   MESSAGE_QUESTIONt   BUTTONS_YES_NOR   t   format_secondary_textt   runt   destroyt   RESPONSE_YESR   R   (   R   R(   t   choice_dialogt   response(    (    sH   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/bookmark.pyR   H   s    
c         C   s   |  i  i d ƒ i | ƒ d S(   s¡   Set the sensitivities of menu items as appropriate if <loaded>
        represents whether a file is currently loaded in the main program
        or not.
        R   N(   R	   R   t   set_sensitive(   R   t   loaded(    (    sH   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/bookmark.pyR3   V   s    c         C   s   |  i  i ƒ  d S(   s4   Store relevant bookmark info in the comix directory.N(   R   t   write_bookmarks_file(   R   (    (    sH   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/bookmark.pyR5   ]   s    (   t   __name__t
   __module__t   __doc__R   R   R&   R   R   R   R3   R5   (    (    (    sH   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/bookmark.pyR       s   							t	   _Bookmarkc           B   sD   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s|   _Bookmark represents one bookmark. It extends the gtk.ImageMenuItem
    and is thus put directly in the bookmarks menu.
    c         C   s´   | |  _  | |  _ | |  _ | |  _ | |  _ | |  _ t i i |  t	 |  ƒ t
 ƒ |  i d  j	 o t i d t i ƒ } n t i d t i ƒ } |  i | ƒ |  i d |  i ƒ d  S(   Ns   comix-archives   comix-imaget   activate(   t   _namet   _patht   _paget	   _numpagest   _archive_typet   _file_handlerR   t   MenuItemR   t   strt   FalseR   t   image_new_from_stockt   ICON_SIZE_MENUt	   set_imaget   connectt   _load(   R   R   t   namet   patht   paget   numpagest   archive_typet   im(    (    sH   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/bookmark.pyR   h   s    						c         C   s   d |  i  |  i |  i f S(   Ns   %s, (%d / %d)(   R;   R=   R>   (   R   (    (    sH   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/bookmark.pyt   __str__x   s    c         G   s   |  i  i |  i |  i ƒ d S(   s/   Open the file and page the bookmark represents.N(   R@   t	   open_fileR<   R=   (   R   R(   (    (    sH   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/bookmark.pyRH   {   s    c         C   s   | |  i  j S(   s3   Return True if the bookmark is for the file <path>.(   R<   (   R   RJ   (    (    sH   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/bookmark.pyt	   same_path   s    c         C   sJ   |  i  ƒ  i ƒ  } |  i | Œ  } d |  i |  i f } | |  i | |  f S(   s\   Return a tuple corresponding to one row in the _BookmarkDialog's
        ListStore.
        s   %d / %d(   t	   get_imaget	   get_stockt   render_iconR=   R>   R;   (   R   t   stockt   pixbufRK   (    (    sH   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/bookmark.pyt   to_rowƒ   s    c         C   s"   |  i  |  i |  i |  i |  i f S(   sz   Return a tuple suitable for pickling. The bookmark can be fully
        re-created using the values in the tuple.
        (   R;   R<   R=   R>   R?   (   R   (    (    sH   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/bookmark.pyt   packŒ   s    (	   R6   R7   R8   R   RO   RH   RQ   RW   RX   (    (    (    sH   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/bookmark.pyR9   b   s   						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 RS(
   s…   The _BookmarksStore is a backend for both the bookmarks menu and dialog.
    Changes in the _BookmarksStore is mirrored in both.
    c         C   sÊ   | |  _  | |  _ g  |  _ t i i t ƒ o˜ yY t t d ƒ } t i	 | ƒ } t i	 | ƒ } x | D] } |  i
 | Œ  qe W| i ƒ  WqÆ t j
 o, d Gt GHd GHt i t ƒ |  i ƒ  qÆ Xn d  S(   Nt   rbs   ! bookmark.py: Could not parses0   ! bookmark.py: Deleting corrupt bookmarks file.
(   t   _menuR@   t
   _bookmarkst   osRJ   t   isfilet   _pickle_patht   opent   cPicklet   loadt   add_bookmark_by_valuest   closet	   ExceptionR$   R   (   R   t   menuR   t   fdt   versiont   packsRX   (    (    sH   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/bookmark.pyR   š   s"    			 	c         C   sB   t  |  i | | | | | ƒ } |  i i | ƒ |  i i | ƒ d S(   s7   Create a bookmark and add it to the store and the menu.N(   R9   R@   R[   R   RZ   R   (   R   RI   RJ   RK   RL   RM   R#   (    (    sH   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/bookmark.pyRb   ¬   s    	c         C   s$   |  i  i | ƒ |  i i | ƒ d S(   s-   Add the <bookmark> to the store and the menu.N(   R[   R   RZ   R   (   R   R#   (    (    sH   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/bookmark.pyR   ³   s    c         C   s$   |  i  i | ƒ |  i i | ƒ d S(   s2   Remove the <bookmark> from the store and the menu.N(   R[   R$   RZ   R&   (   R   R#   (    (    sH   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/bookmark.pyR&   ¸   s    c         C   s—   |  i  i ƒ  } |  i  i ƒ  } |  i  i ƒ  } |  i  i ƒ  } |  i  i } x3 |  i D]( } | i | ƒ o |  i | ƒ PqR qR W|  i	 | | | | | ƒ S(   s8   Add the currently viewed file to the store and the menu.(
   R@   t   get_pretty_current_filenamet   get_real_patht   get_current_paget   get_number_of_pagesRM   R[   RQ   R&   Rb   (   R   RI   RJ   RK   RL   RM   R#   (    (    sH   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/bookmark.pyR'   ½   s    
 	c         C   s&   x |  i  D] } |  i | ƒ q Wd S(   s1   Remove all bookmarks from the store and the menu.N(   R[   R&   (   R   R#   (    (    sH   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/bookmark.pyR   Ë   s     c         C   s   |  i  S(   s&   Return all the bookmarks in the store.(   R[   (   R   (    (    sH   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/bookmark.pyt   get_bookmarksÐ   s    c         C   s   t  |  i ƒ d j S(   s,   Return True if the store is currently empty.i    (   t   lenR[   (   R   (    (    sH   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/bookmark.pyR%   Ô   s    c         C   sv   t  t d ƒ } t i t i | t i ƒ g  } |  i D] } | | i ƒ  q6 ~ } t i | | t i ƒ | i	 ƒ  d S(   s4   Store relevant bookmark info in the comix directory.t   wbN(
   R_   R^   R`   t   dumpt	   constantst   VERSIONt   HIGHEST_PROTOCOLR[   RX   Rc   (   R   Rf   t   _[1]R#   Rh   (    (    sH   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/bookmark.pyR5   Ø   s
    *(   R6   R7   R8   R   Rb   R   R&   R'   R   Rm   R%   R5   (    (    (    sH   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/bookmark.pyR   ”   s   								R)   c           B   sD   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   sA   _BookmarksDialog lets the user remove and/or rearrange bookmarks.c      	   C   sò  t  i i |  t d ƒ | t  i t  i t  i t  i t  i f ƒ | |  _	 |  i
 t ƒ |  i t ƒ |  i t  i ƒ t  i ƒ  } |  i d ƒ | i d ƒ | i t  i ƒ | i t  i t  i ƒ |  i i | ƒ t  i t  i i t i t i t ƒ |  _ t  i |  i ƒ |  _ |  i i  t ƒ |  i i! t ƒ |  i i" ƒ  |  _# | i$ |  i ƒ t  i% ƒ  } t  i& ƒ  } t  i' d  | ƒ |  _) t  i' t d ƒ | ƒ |  _* t  i' t d ƒ | ƒ |  _+ |  i i, |  i) ƒ |  i i, |  i* ƒ |  i i, |  i+ ƒ |  i) i- | d d ƒ|  i* i- | d d	 ƒ|  i+ i- | d d
 ƒ|  i* i. t ƒ |  i) i/ t  i0 ƒ |  i* i/ t  i0 ƒ |  i+ i/ t  i0 ƒ |  i1 d d ƒ |  i2 d |  i3 ƒ |  i2 d |  i4 ƒ |  i i2 d |  i5 ƒ x$ |  i	 i6 ƒ  D] } |  i7 | ƒ qÍW|  i8 ƒ  d  S(   Ns   Edit bookmarksi   i   t   Namet   PageRV   i    t   texti   i   iÂ  R2   t   delete_eventt   key_press_event(9   R   t   DialogR   R   t   DIALOG_MODALt   STOCK_REMOVEt   RESPONSE_NOt   STOCK_CLOSEt   RESPONSE_CLOSER   t   set_has_separatorRC   t   set_resizablet   Truet   set_default_responset   ScrolledWindowt   set_border_widtht   set_shadow_typet	   SHADOW_INt
   set_policyt   POLICY_AUTOMATICt   vboxt
   pack_startt	   ListStoret   gdkt   Pixbuft   gobjectt   TYPE_STRINGR9   t
   _liststoret   TreeViewt	   _treeviewt   set_rules_hintt   set_reorderablet   get_selectiont
   _selectiont   addt   CellRendererTextt   CellRendererPixbuft   TreeViewColumnR   t	   _icon_colt	   _name_colt	   _page_colt   append_columnt   set_attributest
   set_expandt
   set_sizingt   TREE_VIEW_COLUMN_AUTOSIZEt   resizeRG   t	   _responset   _closet   _key_press_eventRm   t   _add_bookmarkR   (   R   R   t   bookmarks_storet   scrolledt   cellrenderer_textt   cellrenderer_pbufR#   (    (    sH   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/bookmark.pyR   å   sV    	 c         C   s   |  i  i | i ƒ  ƒ d S(   s!   Add the <bookmark> to the dialog.N(   R‘   t   prependRW   (   R   R#   (    (    sH   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/bookmark.pyR¨     s    c         C   s]   |  i  i ƒ  d } | d j	 o9 |  i i | d ƒ } |  i i | ƒ |  i i | ƒ n d S(   sR   Remove the currently selected bookmark from the dialog and from
        the store.i   i   N(   R—   t   get_selectedR   R‘   t	   get_valueR$   R   R&   (   R   t   treeiterR#   (    (    sH   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/bookmark.pyt   _remove_selected  s
    c         C   s@   | t  i j o |  i ƒ  n | t  i j o |  i ƒ  n d  S(   N(   R   R   R¦   R}   R±   (   R   t   dialogR2   (    (    sH   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/bookmark.pyR¥   #  s    c         G   s(   | i  t i i j o |  i ƒ  n d  S(   N(   t   keyvalR   t   keysymst   DeleteR±   (   R   R²   t   eventR(   (    (    sH   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/bookmark.pyR§   )  s    c         G   s    g  } |  i  i ƒ  } xI | d j	 o; |  i  i | d ƒ } | i d | ƒ |  i  i | ƒ } q Wx. | D]& } |  i i | ƒ |  i i | ƒ qh W|  i	 ƒ  d S(   sN   Close the dialog and update the _BookmarksStore with the new
        ordering.i   i    N(
   R‘   t   get_iter_rootR   R¯   R!   t	   iter_nextR   R&   R   R/   (   R   R(   t   orderingR°   R#   (    (    sH   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/bookmark.pyR¦   -  s      (	   R6   R7   R8   R   R¨   R±   R¥   R§   R¦   (    (    (    sH   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/bookmark.pyR)   á   s   	1					(    (   R8   R\   R`   R   R   Rq   RJ   t   joint   DATA_DIRR^   R   R    t   ImageMenuItemR9   R   Rz   R)   (    (    (    sH   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/bookmark.pys   <module>   s   S2M