³ò
’\jIc           @   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 Z d d k Z d d k	 Z	 d d k
 Z
 d d k Z d d k Z d a 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   edit.py - Archive editor.iÿÿÿÿNt   _EditArchiveDialogc           B   s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   s»   The _EditArchiveDialog lets users edit archives (or directories) by
    reordering images and removing and adding images or other files. The
    result can be saved as a ZIP archive.
    c         C   sÈ  t  i i |  t d ƒ | t  i t  i t  i f ƒ t |  _ | i	 |  _	 | |  _
 |  i t  i t  i ƒ |  _ |  i t d ƒ t  i ƒ |  _ |  i i t  i t  i t  i ƒ ƒ |  i t ƒ |  i d ƒ |  i t t  i i ƒ  i ƒ  d d ƒ t t  i i ƒ  i ƒ  d d ƒ ƒ |  i d |  i ƒ t |  ƒ |  _  t! |  ƒ |  _" t  i# ƒ  } | i d ƒ | i$ |  i  t  i% t d	 ƒ ƒ ƒ | i$ |  i" t  i% t d
 ƒ ƒ ƒ |  i& i' | ƒ |  i( ƒ  t) i* |  i+ ƒ d  S(   Ns   Edit archivet   Importi   i2   iî  iX  t   responsei   t   Imagess   Other files(,   t   gtkt   Dialogt   __init__t   _t   DIALOG_MODALt   STOCK_CANCELt   RESPONSE_CANCELt   Falset   killt   file_handlert   _windowt
   add_buttont   STOCK_SAVE_ASt   RESPONSE_OKt   _save_buttont   RESPONSE_HELPt   _import_buttont	   set_imaget   image_new_from_stockt	   STOCK_ADDt   ICON_SIZE_BUTTONt   set_has_separatort   set_border_widtht   resizet   mint   gdkt   screen_get_defaultt	   get_widtht
   get_heightt   connectt	   _responset
   _ImageAreat   _image_areat
   _OtherAreat   _other_areat   Notebookt   append_paget   Labelt   vboxt
   pack_startt   show_allt   gobjectt   idle_addt   _load_original_files(   t   selft   windowt   notebook(    (    sD   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/edit.pyR      s.    		%#""
c         C   s¢   |  i  i t ƒ |  i i t ƒ |  i i t i i t i i	 ƒ ƒ |  i
 i ƒ  |  i o t Sn |  i i ƒ  |  i i d ƒ |  i  i t ƒ |  i i t ƒ t S(   s\   Load the original files from the archive or directory into
        the edit dialog.
        N(   R   t   set_sensitiveR   R   R1   t
   set_cursorR   R   t   Cursort   WATCHR$   t   fetch_imagesR   R&   t   fetch_commentst   Nonet   True(   R0   (    (    sD   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/edit.pyR/   9   s    "
c   	      C   sÁ  |  i  t ƒ |  i i t i i t i i ƒ ƒ x t i ƒ  o t i	 t ƒ q2 W|  i
 i ƒ  } |  i i ƒ  } yH t i d d t i i | ƒ d d d t i i | ƒ ƒ d } t } Wn t } n X| pv t i | | | t i i t i i | ƒ ƒ d ƒ } | i ƒ  | i ƒ  } | o t i | | ƒ t ƒ  qDt } n | or |  i i d
 ƒ t i |  i d t i t i t  d ƒ ƒ } | i! t  d	 ƒ ƒ | i" ƒ  | i# ƒ  |  i  t ƒ n d
 S(   s+   Create a new archive with the chosen files.t   suffixs   .%st   prefixs   tmp.t   diri   i    s#   The new archive could not be saved!s)   The original files have not been removed.N($   R3   R   R1   R4   R   R   R5   R6   t   events_pendingt   main_iterationR$   t   get_file_listingR&   t   tempfilet   mkstempt   ost   patht   basenamet   dirnameR:   t   archivet   Packert   splitextt   packt   waitt   renamet   _close_dialogR9   t   MessageDialogR   t   MESSAGE_ERRORt   BUTTONS_CLOSER   t   format_secondary_textt   runt   destroy(	   R0   t   archive_patht   image_filest   other_filest   tmp_patht   failt   packert   packing_successt   dialog(    (    sD   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/edit.pyt   _pack_archiveI   s@    " 	

%



c         C   s†  | t  i j oÆ t i t  i ƒ } |  i i ƒ  } | i t i	 i
 | ƒ ƒ | i d t i	 i t i	 i | ƒ ƒ d ƒ | i i t  i t d ƒ ƒ ƒ | i ƒ  | i ƒ  } | i ƒ  | o |  i | d ƒ q‚n­ | t  i j oŒ t i ƒ  } | i ƒ  | i ƒ  } | i ƒ  xm | D]Q } t i | ƒ o |  i i | ƒ qt i	 i | ƒ o |  i i | ƒ qqWn t ƒ  t |  _ d  S(   Ns   %s.cbzi    s!   Archives are stored as ZIP files.(    R   R   t   filechoosert   StandAloneFileChooserDialogt   FILE_CHOOSER_ACTION_SAVER   t   get_path_to_baset   set_current_directoryRC   RD   RF   t   set_save_nameRI   RE   t   set_extra_widgetR)   R   RR   t	   get_pathsRS   R\   R   t   filehandlert   is_image_fileR$   t   add_extra_imaget   isfileR&   t   add_extra_fileRM   R:   R   (   R0   R[   R   t   src_patht   pathsRD   (    (    sD   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/edit.pyR"   l   s6    



 (   t   __name__t
   __module__t   __doc__R   R/   R\   R"   (    (    (    sD   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/edit.pyR       s
   			#R#   c           B   sV   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(	   s6   The area used for displaying and handling image files.c         C   sp  t  i i |  ƒ | |  _ |  i t  i t  i ƒ t  i t  i i t	 t	 ƒ |  _
 t  i |  i
 ƒ |  _ |  i i d ƒ |  i i d ƒ |  i i t ƒ |  i i t  i ƒ |  i i d |  i ƒ |  i i d |  i ƒ |  i i d |  i ƒ |  i |  i ƒ t  i ƒ  |  _ d } |  i i | ƒ t  i d ƒ } | i d t  i t d	 ƒ d  d  |  i! f g ƒ |  i i" | d ƒ d  S(
   Ni    i   t   button_press_eventt   key_press_eventt
   drag_begins‡   
        <ui>
            <popup name="Popup">
                <menuitem action="remove" />
            </popup>
        </ui>
        s   comix-edit-archive-image-areat   removes   Remove from archive(#   R   t   ScrolledWindowR   t   _edit_dialogt
   set_policyt   POLICY_AUTOMATICt	   ListStoreR   t   Pixbuft   strt
   _liststoret   IconViewt	   _iconviewt   set_pixbuf_columnt   set_tooltip_columnt   set_reorderableR:   t   set_selection_modet   SELECTION_MULTIPLER!   t   _button_presst
   _key_presst   connect_aftert   _drag_begint   addt	   UIManagert   _ui_managert   add_ui_from_stringt   ActionGroupt   add_actionst   STOCK_REMOVER   R9   t   _remove_pagest   insert_action_group(   R0   t   edit_dialogt   ui_descriptiont   actiongroup(    (    sD   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/edit.pyR   Ž   s*    	c         C   só   xì t  d |  i i i ƒ  d ƒ D]Ë } |  i i i | d d d t ƒ} t i | d d ƒ } |  i i i | ƒ } |  i	 i
 | t i t i i | ƒ ƒ | g ƒ | d d j o; x t i ƒ  o t i t ƒ q³ W|  i i o d Sqë q  q  Wd S(	   s0   Load all the images in the archive or directory.i   iC   id   t   createiÿUUUi
   i    N(   t   xrangeRt   R   t   get_number_of_pagest   get_thumbnailR   t   imaget
   add_bordert   get_path_to_pageRz   t   appendt   encodingt
   to_unicodeRC   RD   RE   R   R>   R?   R   (   R0   t   paget   thumbRD   (    (    sD   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/edit.pyR7   ®   s    	 " c         C   s‘   t  i | d t ƒ} | d j o |  i t i t i ƒ } n t i	 | d d ƒ } t i
 | d d ƒ } |  i i | t i i | ƒ | g ƒ d S(   s?   Add an imported image (at <path>) to the end of the image list.R’   iC   id   i   iÿUUUN(   t	   thumbnailR•   R   R9   t   render_iconR   t   STOCK_MISSING_IMAGEt   ICON_SIZE_DIALOGR–   t   fit_in_rectangleR—   Rz   R™   RC   RD   RE   (   R0   RD   R   (    (    sD   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/edit.pyRg   ¾   s    c         C   s/   g  } x" |  i  D] } | i | d ƒ q W| S(   s>   Return a list with the full paths to all the images, in order.i   (   Rz   R™   (   R0   t	   file_listt   row(    (    sD   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/edit.pyR@   È   s
    
 c         G   sF   |  i  i ƒ  } x0 | D]( } |  i i | ƒ } |  i i | ƒ q Wd S(   s2   Remove the currently selected pages from the list.N(   R|   t   get_selected_itemsRz   t   get_iterRr   (   R0   t   argsRk   RD   t   iterator(    (    sD   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/edit.pyR   Ï   s
     c         C   s§   | i  t | i ƒ t | i ƒ ƒ } | d j o d Sn | i d j oZ | i | ƒ p | i ƒ  | i | ƒ n |  i	 i
 d ƒ i d d d | i | i ƒ n d S(   s2   Handle mouse button presses on the thumbnail area.Ni   s   /Popup(   t   get_path_at_post   intt   xt   yR9   t   buttont   path_is_selectedt   unselect_allt   select_pathRˆ   t
   get_widgett   popupt   time(   R0   t   iconviewt   eventRD   (    (    sD   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/edit.pyR‚   Ö   s    $
c         C   s(   | i  t i i j o |  i ƒ  n d S(   s)   Handle key presses on the thumbnail area.N(   t   keyvalR   t   keysymst   DeleteR   (   R0   R´   Rµ   (    (    sD   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/edit.pyRƒ   â   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_drag_iconR   R   Rx   t   COLORSPACE_RGBR:   t   get_sizet   get_from_drawablet   get_colormapt   set_icon_pixbuf(   R0   R´   t   contextRD   t   pixmapt   pointer(    (    sD   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/edit.pyR…   ç   s    (   Rl   Rm   Rn   R   R7   Rg   R@   R   R‚   Rƒ   R…   (    (    (    sD   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/edit.pyR#   Š   s   	 		
				R%   c           B   sM   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 RS(   s:   The area used for displaying and handling non-image files.c         C   s÷  t  i i |  ƒ | |  _ t  i ƒ  } | i t  i t  i ƒ |  i | ƒ t  i t	 d ƒ ƒ } | i
 d d ƒ | i t ƒ |  i | t t d ƒ t  i t t t ƒ |  _ t  i |  i ƒ |  _ |  i i t ƒ |  i i d |  i ƒ |  i i d |  i ƒ t  i ƒ  } t  i t	 d ƒ | d d ƒ} | i t ƒ |  i i | ƒ t  i t	 d	 ƒ | d d
 ƒ} |  i i | ƒ | i |  i ƒ t  i ƒ  |  _ d } |  i i | ƒ t  i d ƒ } | i  d t  i! t	 d ƒ d  d  |  i# f g ƒ |  i i$ | d ƒ d  S(   Nsˆ   Please note that the only files that are automatically added to this list are those files in archives that Comix recognizes as comments.g      à?i
   Ro   Rp   t   Namet   texti    t   Sizei   s‡   
        <ui>
            <popup name="Popup">
                <menuitem action="remove" />
            </popup>
        </ui>
        s   comix-edit-archive-other-areaRr   s   Remove from archive(%   R   t   VBoxR   Rt   Rs   Ru   Rv   R+   R)   R   t   set_alignmentt   set_line_wrapR:   R   Rw   Ry   Rz   t   TreeViewt	   _treeviewt   set_rules_hintR!   R‚   Rƒ   t   CellRendererTextt   TreeViewColumnt
   set_expandt   append_columnR†   R‡   Rˆ   R‰   RŠ   R‹   RŒ   R9   t   _remove_fileRŽ   (   R0   R   t   scrolledt   infot   cellrenderert   columnR   R‘   (    (    sD   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/edit.pyR   û   s:    	c         C   s‚   x{ t  d |  i i i ƒ  d ƒ D]Z } |  i i i | ƒ } d t i | ƒ i d } |  i i	 t i
 i | ƒ | | g ƒ q  Wd S(   s!   Load all comments in the archive.i   s   %.1f KiBg      @N(   R“   Rt   R   t   get_number_of_commentst   get_comment_nameRC   t   statt   st_sizeRz   R™   RD   RE   (   R0   t   numRD   t   size(    (    sD   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/edit.pyR8   $  s    	 c         C   sC   d t  i | ƒ i d } |  i i t  i i | ƒ | | g ƒ d S(   s3   Add an extra imported file (at <path>) to the list.s   %.1f KiBg      @N(   RC   R×   RØ   Rz   R™   RD   RE   (   R0   RD   RÚ   (    (    sD   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/edit.pyRi   ,  s    c         C   s/   g  } x" |  i  D] } | i | d ƒ q W| S(   s=   Return a list with the full paths to all the files, in order.i   (   Rz   R™   (   R0   R£   R¤   (    (    sD   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/edit.pyR@   1  s
    
 c         G   s>   |  i  i ƒ  i ƒ  d } | d j	 o |  i i | ƒ n d S(   s1   Remove the currently selected file from the list.i   N(   RÊ   t   get_selectiont   get_selectedR9   Rz   Rr   (   R0   R§   R¨   (    (    sD   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/edit.pyRÐ   8  s    c         C   s†   | i  t | i ƒ t | i ƒ ƒ } | d j o d Sn | d } | i d j o/ |  i i d ƒ i d d d | i | i	 ƒ n d S(   s(   Handle mouse button presses on the area.Ni    i   s   /Popup(
   R©   Rª   R«   R¬   R9   R­   Rˆ   R±   R²   R³   (   R0   t   treeviewRµ   RD   (    (    sD   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/edit.pyR‚   >  s    $
c         C   s(   | i  t i i j o |  i ƒ  n d S(   s   Handle key presses on the area.N(   R¶   R   R·   R¸   RÐ   (   R0   R´   Rµ   (    (    sD   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/edit.pyRƒ   H  s    (
   Rl   Rm   Rn   R   R8   Ri   R@   RÐ   R‚   Rƒ   (    (    (    sD   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/edit.pyR%   ÷   s   	)					
c         C   s+   t  d  j o t | ƒ a  n t  i ƒ  d  S(   N(   t   _dialogR9   R    t   present(   t   actionR1   (    (    sD   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/edit.pyt   open_dialogN  s    c          G   s%   t  d  j	 o t  i ƒ  d  a  n d  S(   N(   RÞ   R9   RS   (   R§   (    (    sD   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/edit.pyRM   V  s    
(   Rn   RC   RA   R-   R   t   pangoRG   t   cursorRš   R]   Re   R–   Rž   R9   RÞ   R   R    Rs   R#   RÆ   R%   Rá   RM   (    (    (    sD   /home/sork/Pontus/Programmering/Python/Comix/comix-4.0.4/src/edit.pys   <module>   s$   umW	