ó
ÉÝ{Tc           @   s<   d  Z  d d l Z d d d „  ƒ  YZ d d d „  ƒ  YZ d S(	   s~  
     python/ui/EditHistory.py: CCP4MG Molecular Graphics Program
     Copyright (C) 2001-2008 University of York, CCLRC
     Copyright (C) 2009-2010 University of York

     This library is free software: you can redistribute it and/or
     modify it under the terms of the GNU Lesser General Public License
     version 3, modified in accordance with the provisions of the 
     license to address the requirements of UK law.
 
     You should have received a copy of the modified GNU Lesser General 
     Public License along with this library.  If not, copies may be 
     downloaded from http://www.ccp4.ac.uk/ccp4license.php
 
     This program is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU Lesser General Public License for more details.
iÿÿÿÿNt   EditHistoryc           B   se   e  Z d  „  Z d d d d d „ Z d d d d „ Z d d d d „ Z d „  Z d e j d	 „ Z	 RS(
   c         C   s   |  t  _ g  |  _ d |  _ d  S(   Niÿÿÿÿ(   R    t   instst   edit_historyt   counter(   t   self(    (    sB   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/EditHistory.pyt   __init__   s    		t    t   alli    c   	      K   s—   d d  l  } i | d 6| d 6| d 6| j j j d 6} |  j j | ƒ |  j d |  _ x6 |  j D]+ } d | _ | j	 d k ra | j
 ƒ  qa qa W|  j S(   Niÿÿÿÿt   applicationt   actiont	   selectiont
   command_noi   t   MolDisp(   t   historyt   CHistoryR   t
   n_commandsR   t   appendR   t   objinstst   do_updatedisplayt   object_typet
   set_extent(	   R   R   R
   R	   t	   supercedet   keywordsR   t   itemt   obj(    (    sB   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/EditHistory.pyt   EditHistory_Append    s    	 t   savec         K   s   g  |  _  d |  _ d  S(   Niÿÿÿÿ(   R   R   (   R   R   R	   t   modeR   (    (    sB   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/EditHistory.pyt   EditHistory_Save:   s    	c         K   s!   |  j  j ƒ  |  j d |  _ d  S(   Ni   (   R   t   popR   (   R   R   R	   R   R   (    (    sB   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/EditHistory.pyt   EditHistory_Undo@   s    c         C   s÷   d d l  } d d l } t |  d ƒ s3 d |  _ n |  j d |  _ | j j | j ƒ  d ƒ } | j j | ƒ s€ | j | ƒ n  | j j | |  j	 ƒ } | j j | ƒ sº | j | ƒ n  | j j | t
 |  j ƒ d d ƒ } |  j j | ƒ |  j S(   s6   
    Save the current data to an MMDB binary file
    iÿÿÿÿNt   saveMMDBF_filesi   t   saved_filest   .t   mmdb(   t   ost   utilst   hasattrR   t   patht   joint
   get_CCP4MGt   existst   mkdirt   namet   strt   molHndt
   WriteMMDBF(   R   R#   R$   t   dirt   filename(    (    sB   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/EditHistory.pyt	   saveMMDBFF   s      &c         C   s×  d d l  } d d l } d d l } d d l } d d l } | d k r¾ | j t ƒ  j t ƒ  j ƒ } | j	 | j
 ƒ | j	 | j ƒ | j	 | j ƒ | j	 | j ƒ | j | |  j ƒ }	 n² t |  d ƒ sÑ d S| d k  ré |  j } n  | j j | j ƒ  d |  j ƒ }
 | j j |
 t | ƒ d d ƒ } | j j | ƒ sCd	 S| j t ƒ  j t ƒ  j ƒ } | j | ƒ }	 |	 rzd
 S| j | j g j | ƒ rÈ|  j j | | ƒ }	 |	 r´d S|  j d ƒ ~ d Sd d l } g  } g  } g  } xˆ t  d t! |  j" ƒ ƒ D]n } |  j" | j# sÿ| j$ |  j% | ƒ | j& ƒ  } | j$ | ƒ | j' |  j" | ƒ | j$ |  j" | ƒ qÿqÿWx | D] } | j( ƒ  qxW|  ` | |  _ d GH|  j j) ƒ  } x | D] } | j* |  j ƒ q¶W~ d S(   sd   
    Restore model from MMDB binary file
    mode = MMUT_COORDINATES : restore coordinates only
    iÿÿÿÿNi    R   i   R    R!   R"   i   i   i   t   reconfigures;   FIXME (EditHistory.py) - A preference here for aromaticize.(+   R#   R$   t   mmutt   mmdb2t	   resourcest   CMMANManagert	   RESOURCESt   SRSt   CMolBondParamst   SetFlagt   MMDBF_AutoSerialst   MMDBF_IgnoreRemarkst   MMDBF_IgnoreBlankLinest   MMDBF_IgnoreHasht   ReadCoorFileR0   R%   R   R&   R'   R(   R+   R,   R)   t	   ReadMMDBFt   MMAN_COORDINATESt   MMAN_XTLDATAt   countR-   t   RestoreDatat   update_dependentst   dataobjt   ranget   lenR   t   master_applicationR   t   objnamest   DispObjShadowR   t   deletet   GetMolBondst   restore(   R   t   idR   R#   R$   R3   R"   R5   t
   new_molHndt   rvR/   R0   RF   t   save_objnamest   save_objinstst   delete_listt   it   save_objR   t   outputR   (    (    sB   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/EditHistory.pyt   restoreMMDBF^   sf      !#    	(
   t   __name__t
   __module__R   R   R   R   R1   R3   RA   RX   (    (    (    sB   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/EditHistory.pyR       s   		t   EditHistoryManagerc           B   s¬   e  Z d Z i d  d 6d d 6Z i  d „ Z d „  Z d „  Z d g g  d d d d d	 „ Z d d d d d
 „ Z	 d d d d d „ Z
 d d g  d „ Z d d d d „ Z RS(   R   t   multi_save_modei   t   save_allc         C   ss   |  t  _ x- t  j j ƒ  D] \ } } t |  | | ƒ q Wx* | j ƒ  D] \ } } t |  | | ƒ qF Wi  |  _ d  S(   N(   R[   R   t
   initialiset   itemst   setattrt   open_windows(   R   t   paramst   keyt   value(    (    sB   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/EditHistory.pyR   »   s    	c         C   s7   i  } x* t  j j ƒ  D] } t |  | ƒ | | <q W| S(   N(   R[   R^   t   keyst   getattr(   R   Rb   Rc   (    (    sB   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/EditHistory.pyt	   getparamsÆ   s    c         C   s1   x* | j  ƒ  D] \ } } t |  | | ƒ q Wd  S(   N(   R_   R`   (   R   Rb   Rc   Rd   (    (    sB   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/EditHistory.pyt	   setparamsÍ   s    t   MolDataR   c         C   sß  d d  l  } d d  l } d d  l }	 |  j d |  j d | ƒ }
 | | | | g |  j | <| j  j j d |  d d | g d d g d	 d
 g d | g d d d d g d t |  j	 ƒ g g d d d d g d d d d d g g d |  j g g d d d d g d | g g d d d d g d |
 g g d d d d d d d g g d d d d d g g d d d d d g g d d d g d  d! g g d d  d" | g d d g d  d# g g d$ d% d  d& g d' g g d( d  d) g d' g g g g g	 ƒ d  S(*   NiÿÿÿÿR\   t   application_tagt
   save_multit   TITLEs   Save files from t   RETURNs   EH().handle_save_multit   HELPt   editingt   OFFSETt   PARAMR]   t   TYPEt   _logicalt   INITIALt   _textt   RETURN_LISTt   _text10t   version_tagt   DISPLAYt   WINDOWt   LINEt   RADIOBUTTONR   s"   Save to filename with tag appendedt   backups1   Save to same filename and backup to file with tagt
   individuals   Save to each file individuallyt   WIDGETt   LABELs    Save all files even if unchangeds   Tag files 't   't   BUTTONSt   oks
   Save filest   CLOSEt   dismisst   Quit(
   t   GUIR#   t   globt   next_version_tagR\   Ra   R   t   CreateGUIWindowR,   R]   (   R   t   DataObj_typest   DataObj_listRj   t   titlet   commandt   offsetR‡   R#   Rˆ   Rx   (    (    sB   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/EditHistory.pyt   SaveMultipleFilesÓ   sN    $										c      
   K   s(  d d  l  } d d  l } d d  l } d d  l }	 | rq | |  j k rq | |  _ |  j d |  j d | d d ƒ d  S| d k r� d  S|  j j | ƒ s® | j  j j	 d | ƒ d SxA d g D]6 }
 | j |
 ƒ r¸ | |
 r¸ t
 |  |
 | |
 ƒ q¸ q¸ Wt |  j ƒ |  _ |  j rQg  |  _ xL |  j | d D]" } |  j j | j d	 | ƒ ƒ q(Wn |  j | d
 |  _ |  j sˆ|  j d d d | ƒ d  Sg  |  _ |  j d k rt ƒ  j ƒ  } t ƒ  j | ƒ } | j j | ƒ sñ|  j d d | d | ƒ d  S| j j | | | ƒ } | j j | ƒ r:|  j d d | d | ƒ d  Sy | j | ƒ Wn" |  j d d | d | ƒ d  SXx˜|  j D]� } | j j | | j d ƒ } | j d | j j | | | j d ƒ d | d d d d ƒ } | rù|  j d | d |  j ƒ S|  j j | ƒ qzWnû|  j d k rExé|  j D]} | j d
 d | | d } y | j | j d
 | ƒ Wn& |  j d d | d d | ƒ d  SXy~ | j d | j d d | j d d d d d ƒ } | rý|  j d d | j d
 d d | d |  j ƒ d  S|  j j | ƒ Wq)|  j d d | j d
 d d | ƒ d  SXq)WnÆd  d! g j |  j ƒ rÙx«|  j D]k} | j j | j d ƒ } |	 j | d | ƒ } | d k r|  j d! k rþ|	 j | d d" | t  | ƒ ƒ } | d k r| d | d } qq | d d | d !} n
 | d } |  j d  k rL| d" | | | d } n | | d" | | d } | j d | d | j d d d d d ƒ } | rÂ|  j d d | d d | d |  j ƒ d  S|  j j | ƒ qgWn2 |  j d# k rd |  _! |  j" d d$ d | ƒ d  S|  j d | d |  j ƒ d  S(%   NiÿÿÿÿR\   Rj   t
   update_GUIi   Rƒ   s   Error handling file save for R]   R   i   t   messages   no files designated to saveR/   s"   project directory does not exist\ns   save directory already exist\ns   error creating directory\nt	   save_filet   DIR_save_filet   exitt   save_selectionR   t
   saved_listR}   R!   s   .backups   error renaming file\ns   \nAborting further savesi    s   error saving file s   error saving file\ns   
Aborting further savesR   t   prependt   _R~   t   no(#   R‡   R#   RF   t   stringR\   R‰   Ra   t   has_keyR   t   WarningMessageR`   t   intR]   t   to_save_listt   extendt   get_dataobjt   exit_save_multiR—   t   CCP4DATABASEt   get_current_projectt   get_project_dirR&   R)   R'   R*   R0   t   save_restore_dataR   t   renameRC   t   splitextt   findRH   t   to_save_indext   handle_save_individual(   R   R\   Rj   Rx   R•   R   R‡   R#   RF   R›   Rc   t   typet   projectt   project_dirt   save_dirt   dobjR“   RQ   t   file0t   pt   qt   fnam(    (    sB   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/EditHistory.pyt   handle_save_multi	  sª    0	 		#		>2.%#
+'	c   	      K   s�  d d  l  } | d k r ns | d k rŽ |  j |  j } | j d | d | d d d d	 ƒ } | r{ | j  j j d
 | ƒ qŽ |  j j | ƒ n  |  j d |  _ |  j t |  j ƒ k rÒ |  j	 d | d |  j ƒ n· |  j |  j } | j  j j
 d | j |  d d | j g d d g d d d d g d | g g d d d d g d | j d g g d d d d d d d d d d  d! | j d" g
 g g ƒ d  S(#   Niÿÿÿÿt   0t   1R“   R”   R•   i   R–   R   s   Error saving file Rj   R—   t   save_Rl   s   Save Rm   s   EH().handle_save_individualRq   Rr   Ru   Rt   t   _coord_filei    Ry   t
   SELECTFILEt   FILEs	   -filetypet	   _pdb_filet   coord_file_typess   -unknowns   -filters   *.pdbs   -defaulti   (   R‡   RŸ   Rª   R¦   R   R�   R—   R   RH   R¢   RŠ   R+   t
   name_labelR0   (	   R   Rj   R“   R”   R•   R   R‡   R°   RQ   (    (    sB   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/EditHistory.pyR«   ‡  s2    $			c         C   s…   d d  l  } | rE | j  j j d |  j | d d | ƒ d } n d } |  j | d r� t |  j | d g  i | d 6ƒ n  | S(   Niÿÿÿÿs   Error handling file save for i    s   \ni   i   R—   (   R‡   R   R�   Ra   t   apply(   R   R’   Rj   R—   R‡   t   ret(    (    sB   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/EditHistory.pyR¢   ­  s    *	%R/   i    c      	   C   sz  d d  l  } d d  l } d d  l } d d  l } d d  l } t ƒ  j t ƒ  j ƒ  ƒ }	 d }
 | d k rþ | j | j j	 |	 | d ƒ ƒ } xš| D]e } | j j
 | ƒ r’ | j | | ƒ } | d k r÷ t |
 | j | | t | ƒ d ƒ ƒ }
 q÷ q’ q’ Wn*| d k r9| j | j j	 |	 d | d ƒ ƒ } d } nc | d	 k rt| j | j j	 |	 d
 | d ƒ ƒ } d } n( | j | j j	 |	 | d ƒ ƒ } d } x‰ | D]� } | j | | ƒ } | d k r£| j | | | t | ƒ ƒ } | d k r$t |
 | j | | t | ƒ | !d ƒ ƒ }
 q$q£q£W| rl| j j j d d d d d g d t |
 d ƒ g g g ƒ n  t |
 d ƒ S(   Niÿÿÿÿi    R/   t   *R}   s   *.s   *.backups   .backupR   s   *_s   *.*R!   s   *_*.*R™   Rk   Rq   Rx   Rr   Rw   Rt   i   (   R#   Rˆ   R›   R$   R‡   R£   R¥   R¤   R&   R'   t   isdirt   rfindt   maxt   safeIntRH   R©   R   t   UpdateGUIWindowR,   (   R   R\   Rj   R‘   R#   Rˆ   R›   R$   R‡   R®   t   maxtagt   dlistt   dR²   t   termR³   (    (    sB   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/EditHistory.pyR‰   »  s<    <"6&	&	"6	 N(   RY   RZ   t   NoneR   R^   R   Rg   Rh   R�   Rµ   R«   R¢   R‰   (    (    (    sB   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/EditHistory.pyR[   ±   s   
			5}&(    (    (   t   __doc__R3   R    R[   (    (    (    sB   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/EditHistory.pyt   <module>   s   œ