ó
ÉÝ{Tc           @   sŚ   d  Z  d d l m Z m Z d d l Z d d l Z d d l Td e j f d     YZ d e j f d     YZ	 d	 e j
 f d
     YZ d e j f d     YZ d S(   s|  
     qtgui/annotationGui.py: CCP4MG Molecular Graphics Program
     Copyright (C) 2001-2008 University of York, CCLRC
     Copyright (C) 2009-2011 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˙˙˙˙(   t   QtCoret   QtGuiN(   t   *t   autoAnnotatec           B   sA   e  Z d    Z d d  Z d d i  d  Z d   Z d   Z RS(   c         C   sH   t  j j |   d |  _ d  |  _ |  j t   t  j d  |  j	  d  S(   Ni   t   atomContextMenu(
   R    t   QObjectt   __init__t   move_annotationt   Nonet   guit   connectt
   MAINWINDOWt   SIGNALt   handleAtomPick(   t   self(    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/annotationGui.pyR       s    		c      	   C   sY   | s
 d  S| j    } | s  d  Sd d  l } | j |  | d g |  j d i | d 6d  S(   Ni˙˙˙˙t   add_annotationt   infot	   pickevent(   t   getContextMenut   guiUtilst   populateMenut   getActionDef(   R   R   t   menuR   (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/annotationGui.pyR   '   s      t    c         C   sl   | s
 d  S| d k rh | j    } | rh t d d d d d |  j | j | j d d  f g d	 d
  Sn  d  S(   NR   t   texts   Add annotationt   tips   Add a text object by this atomt   slott   formatt   fullt   deleteLateri   (   t
   getDataObjt   dictt   drawGuit   namet   getLabel(   R   R!   R   R   t   obj(    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/annotationGui.pyR   0   s     $c         C   s   | \ } } |  j  r< y |  j  j   Wn n Xd  |  _  n  t t   d | d | |  _  |  j |  j  j t j d  |  j	  d  S(   Nt   atomNamet	   modelNames	   clicked()(
   R	   t   closeR   t   autoAnnotateGuiR   R
   t   apply_buttonR    R   R   (   R   t   argsR%   R$   (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/annotationGui.pyR    >   s    	c   
      C   s
  |  j  j j   } | s d  S| \ } } t |  j  j j    } d d  l } t   j d  } | j | d d d i d | d | d d	 6| d
 6} t	   j
 d | d d d | j  } | rÚ |  j rÚ | j d  n  d d  l }	 |	 j   |  j  j   d  |  _  d  S(   Ni˙˙˙˙t
   annotationt   visiblei   t   paramss   <span t   >s   </span>R   t   atom_positiont   parent_namet   object_typet
   AnnotationR!   (   R	   t   pickerWidgett   modelNameAtomNamet   strt   labelWidgetR   R1   t   FONTMANAGERt   getHtmlFontt   DISPLAYTABLEt
   addDispObjR!   R   t   toggleMovingt   rebuildt   UpdateDisplayt   CloseR   (
   R   t	   selectionR%   R$   R*   R1   t   fontt   anniet   gobjR;   (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/annotationGui.pyR   N   s"     $ 
N(   t   __name__t
   __module__R   R   R   R   R    R   (    (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/annotationGui.pyR      s
   			R'   c           B   s/   e  Z d d  d  d  Z d   Z d d  Z RS(   R   c   	      C   s]  t  j  j |  |  |  j t j j  |  j d |  t j   } | j	 t j
 d |    t j |   |  _ | j	 |  j  |  j j d | d |  | j	 t j
 d |    t |   |  _ |  j j t d  j d   | j	 |  j  xz |  j j D]l } |  j | j t j d  |  j  |  j | j t j d  |  j  |  j | j t j d	  |  j  qű Wd
 d  l } | j |   |  _ | j	 |  j  |  j j d t   j d  d t   |  j j! t j" |  j#     t j$   } | j% t j$ j&  |  _' | j% t j$ j(  } |  j | t j d  |  j)  | j	 |  |  j* |  |  j+   d  S(   Ns   Add annotation to s%   Place annotation by atom or residue..R%   R$   s   Annotation format..t   annotation_formatR   s#   currentIndexChanged(const QString&)s   editTextChanged(const QString&)i˙˙˙˙t
   definitionR*   t
   setGuiFonts	   clicked()(,   t   MGSimpleDialogR   t   setAttributeR    t   Qtt   WA_DeleteOnCloset   setWindowTitleR   t   QVBoxLayoutt	   addWidgett   QLabelt	   mgWidgetst   mgAtomPickerR2   t   setSelectiont   annotateFormatWidgett   formatWidgett	   setFormatt   PMt   gett   widgetsR
   t   labelR   t   updateLabelt   spacert   TextEditt   TextEditWidgetR5   t   setCurrentFontR6   t   getFontt   Truet   setTextt   QStringt	   makeLabelt   QDialogButtonBoxt	   addButtont   ApplyR(   t   CancelR=   t	   setLayoutt   show(	   R   t   parentR%   R$   t   layoutt   widgetR[   t   dialog_buttonst   cancel_button(    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/annotationGui.pyR   k   s8    ""&%c         C   sH   |  j  j t j |  j     t d  j d d d |  j j    d  S(   NRD   t
   do_rebuildi    R   (	   R5   R`   R    Ra   Rb   RU   t	   setparamsRS   t	   getFormat(   R   t   string(    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/annotationGui.pyRY      s    i    c         C   s°  d d  l  } |  j j   } d } x2 | D]* } t j d j | d  r( d } Pq( q( W|  j j   } d  } | rÔ t	 | d  } | rÔ | r˛ | j
 d | d | d d d  } qŃ | j | d d  \ }	 } qÔ n  | sŢ d	 Sd	 }
 xĹ| D]˝\ } } |
 | }
 t j j |  } | d k r8|
 t | j    }
 që | d
 k rW|
 | j   }
 që | d k r| j | j    } |
 | d | j | d  }
 që | d k rš|
 | j   }
 që | d k rd d  l } |
 | j j | j t | j     d  }
 që | d k rJ|
 t | j    }
 | j   } | r¨|
 d | }
 q¨që | d k r|
 | j }
 | j   r¨|
 d | j   }
 q¨që | d k rë |
 | j   }
 që që W|
 S(   Ni˙˙˙˙i    i   i   t   molt	   atom_namet   force_one_atomt   firstR   i   i   i   i   t   Xt   ,i   t   ;i   (   Rq   RS   Rp   RR   t
   label_menut   countR2   R3   R   t   datat   interpretAtomIDt   interpretResidueIDt   indexR4   t   GetModelNumt
   GetChainIDt   stript
   GetResNamet   lowert   selection_protocolst   amino_acid_codeRV   t	   GetSeqNumt
   GetInsCodeR!   t	   GetAltLoct   GetElementName(   R   t   forceRq   R   t   ifatomt   itemt   selet   pAtomt   molobjt   nselresRX   RZ   t   indxt   resnR   t   inscode(    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/annotationGui.pyRb      sZ    %"
"1  N(   RB   RC   R   R   RY   Rb   (    (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/annotationGui.pyR'   f   s   (	t   annotateFormatWidget0c           B   s>   e  Z d d   Z d d  Z d d  Z d   Z d   Z RS(   c         C   s2  t  j j |  |  t  j |   } | j d  | j d d d d  t  j |   |  _ |  j j d  x! t	 j
 D] } |  j j |  qq Wt  j |   |  _ |  j j d  x! t	 j D] } |  j j |  qˇ W|  j j t	 j  |  j j t	 j  | j |  j  | j |  j  |  j |  |  j   d  S(   Ni    i   (   R   t   QWidgetR   t   QHBoxLayoutt
   setSpacingt   setContentsMarginst	   QComboBoxRZ   t   setEditableRR   t   spacer_menut   addItemRX   Ry   t   setFixedWidtht   w1t   w2RM   Rg   Rh   (   R   Ri   Rj   R   (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/annotationGui.pyR   Ř   s$    R   c         C   s5   t  j j |  r1 |  j j t  j j |   n  d  S(   N(   RR   Ry   Rz   RX   t   setCurrentIndexR~   (   R   RX   (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/annotationGui.pyt   setLabelđ   s    iç  c         C   s5   | d k r1 t  |  d k r1 |  j j |  n  d  S(   Niç  i   (   t   lenRZ   t   setEditText(   R   RZ   (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/annotationGui.pyt	   setSpacerô   s    c         C   s   t  j |  j j   S(   N(   RR   Ry   RX   t   currentIndex(   R   (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/annotationGui.pyR"   ř   s    c         C   s   t  |  j j    S(   N(   R4   RZ   t   currentText(   R   (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/annotationGui.pyt	   getSpacerű   s    N(   RB   RC   R   R   RĄ   R¤   R"   R§   (    (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/annotationGui.pyR   Ň   s
   	RR   c           B   s   e  Z d  d d d d d d d d g	 Z d  d	 d
 d d d d d d d d d d g Z d Z d Z d   Z g  d  Z d   Z RS(   R   s   Model #s   Chain ids   Res names   RES names   R names   Seq #s	   Atom namet   Elementt    t   /s   \t   -Rw   Rx   t   :t   .t   (t   )t   [t   ]i    c         C   s
  t  j j |  |  |  j t  j j t  j j B t  j   } | j d  | j d d d d  t	 j
 s |  j   j d  d t	 _
 n  t	 j sŻ |  j   j d  d t	 _ n  g  |  _ x> t d d  D]- } |  j j t    | j |  j d  qČ W|  j |  d  S(   Ni    s	   Atom namei   t   wwi   i˙˙˙˙(   R   t   QFrameR   t   setFrameStylet   Boxt   PlainR   R   R   RR   R   t   fontMetricst   widthR   RW   t   ranget   appendR   RM   Rg   (   R   Ri   Rj   t   ii(    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/annotationGui.pyR     s    	 	 	c         C   sk   xd t  t t |  j  t |    D]> } |  j | j | | d  |  j | j | | d  q% Wd  S(   Ni    i   (   Rš   t   minR˘   RW   R¤   RĄ   (   R   R   R˛   (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/annotationGui.pyRT     s    +c         C   sX   g  } xK |  j  D]@ } | j   s. | j   r | j | j   | j   g  q q W| S(   N(   RW   R"   R§   Rş   (   R   t   outputR˛   (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/annotationGui.pyRp   $  s
    &(	   RB   RC   Ry   R   R   R   R   RT   Rp   (    (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/annotationGui.pyRR     s   !-	(   t   __doc__t   PyQt4R    R   RO   RG   t   global_definitionsR   R   R'   R   R   Rł   RR   (    (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/annotationGui.pyt   <module>   s   
Kl/