ó
ÉÝ{Tc           @   s¥   d  Z  d d l Z d d l m Z m Z d d l Td d l Z d d l Z d d l Z d e j	 f d „  ƒ  YZ
 d e j f d „  ƒ  YZ d	 e j f d
 „  ƒ  YZ d S(   sœ  
     qtgui/pictureWizardGui.py: CCP4MG Molecular Graphics Program
     Copyright (C) 2001-2008 University of York, CCLRC
     Copyright (C) 2009-2011 University of York
     Copyright (C) 2012 STFC

     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ÿÿÿÿN(   t   QtGuit   QtCore(   t   *t   drawingStyleGuic           B   sb   e  Z d d  d e d „ Z d d „ Z d „  Z d d „ Z d „  Z d „  Z	 d	 „  Z
 d
 „  Z RS(   id   i    c         C   sC   t  j j |  | ƒ | |  _ | |  _ |  j d | ƒ |  j ƒ  d  S(   Nt   description(   R    t   QWidgett   __init__t   disable_query_scenest   picSizet   drawt   show(   t   selft   parentt   heightR   R   (    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/pictureWizardGui.pyR   $   s
    		c         C   s±  d } t  j ƒ  } d } | j | | | | ƒ | j | ƒ |  j ƒ  |  _ |  j ƒ  | j |  j ƒ |  j |  j t	 j
 d ƒ |  j ƒ |  j |  j t	 j
 d ƒ |  j ƒ |  j |  j t	 j
 d ƒ |  j ƒ t  j ƒ  |  _ t  j d ƒ } |  j j | ƒ | j |  j ƒ | ryt  j |  ƒ |  _ |  j j d ƒ |  j j | ƒ t  j ƒ  } | j | ƒ | j |  j ƒ |  j | ƒ n  d  |  _ | j ƒ  |  j | ƒ |  j ƒ  |  j ƒ  d  S(   NiP   i    s   itemSelectionChanged()s!   itemEntered(QTreeWidgetItem*,int)s'   itemDoubleClicked(QTreeWidgetItem*,int)s   ccp4mg_icon.pngi   (   R    t   QHBoxLayoutt   setContentsMarginst
   setSpacingt   drawTreet   treet   setStylet	   addWidgett   connectR   t   SIGNALt   changePicturet   handleDoubleClickt   QLabelt	   wiz_labelt   QPixmapt	   setPixmapt	   QTextEditt   descriptionWidgett   setReadOnlyt   setFixedHeightt   QVBoxLayoutt	   addLayoutt	   setLayoutt   Nonet
   addStretch(   R   R   t   description_heightt   layoutt   margint
   wiz_pixmapt   layout0(    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/pictureWizardGui.pyR	   ,   s8    
"""	

c   
      C   s‹  d d  l  } t ƒ  } | j d g  ƒ } t j ƒ  } | j t j j ƒ | j d ƒ x| D]} t j	 | j
 | d d d ƒ g ƒ } | j t j j ƒ | j | ƒ xÈ | d D]¼ \ } } | r|  j rt j	 | j
 | d d ƒ g ƒ }	 |	 rl|	 j t j j ƒ | j |	 ƒ qlq° t j	 | j
 | d d ƒ g ƒ }	 |	 r° |	 j t j j t j j Bƒ | j |	 ƒ q° q° WqZ W| j ƒ  j d ƒ | S(   Niÿÿÿÿt   styles*   Select a drawing style to apply to a modeli    t   _t    i   (   t   stringt   PICTUREWIZARDt   define_model_style_menuR    t   QTreeWidgett   setSelectionModet   QAbstractItemViewt   SingleSelectiont
   setToolTipt   QTreeWidgetItemt   replacet   setFlagsR   t   Qtt   ItemIsEnabledt   addTopLevelItemR   t   NoItemFlagst   addChildt   ItemIsSelectablet
   headerItemt	   setHidden(
   R   R.   t   picwizt	   menu_listR   t   groupt   itemt   filet   queryt   item0(    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/pictureWizardGui.pyR   W   s,    	%!!t    c   	      C   sˆ  d d  l  } | r` d d  l } t | | j ƒ sT | j | j | d d ƒ d ƒ } n  | |  _ n* | j | j t ƒ  j d d ƒ d ƒ |  _ |  j	 j
 t j |  j d ƒ t j j ƒ } d } d } xÀ | d k  rƒ| t | ƒ k  rƒ| | j ƒ  } d } x{ | d k  ru| | k  rut | | j | ƒ j d ƒ ƒ |  j d k rh| } |  j	 j | | j | ƒ ƒ n  | d } qû W| d } qÄ Wd  S(   NiÿÿÿÿR,   R-   t   :i    i   (   R.   t   typest
   isinstancet   ListTypet   splitR7   R+   R/   t   default_drawing_styleR   t	   findItemsR   t   QStringR9   t   MatchExactlyt   lent
   childCountt   strt   childt   textt   setCurrentItem(	   R   R+   R.   RJ   t   itemst   hitt   iit	   nChildrent   nc(    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/pictureWizardGui.pyR   w   s(    $$+!/ c         C   s&  d d  l  } d d  l } |  j j ƒ  } | r"| j ƒ  sL |  j |  j ƒ q"| j t | j ƒ  j	 d ƒ ƒ d d ƒ } | j t | j	 d ƒ ƒ d d ƒ } | | g |  _ t
 ƒ  j d | d | d d ƒ } y> t j | ƒ } | j |  j t j j ƒ } |  j j | ƒ Wn d	 G| GHn Xt
 ƒ  j d | d | d d
 ƒ } t
 ƒ  j d | d d ƒ \ }	 }
 d } |	 sŽ|  j j |
 ƒ d |
 d } n  |  j rñ|  j j ƒ  t
 ƒ  j d | d d ƒ \ }	 } |	 sñ|  j j | | j d d ƒ ƒ qñn  t
 ƒ  j | d | ƒ |  j t j d ƒ ƒ n  d  S(   Niÿÿÿÿi    R-   R,   t   drawing_styleRI   t   modet   pngsnapshott   Not   mgpict   filenamet   sectiont   TITLERH   s   <b>s	   </b><br/>t   NOTESs   
s   <br>t   changed(   R.   t   osR   t   currentItemR   R   R+   R7   RT   RV   R/   t   snapshot_fileR    R   t   scaledToHeightR   R   R9   t   SmoothTransformationR   R   t   read_mgpic_file_sectionR5   R   t   cleart   setTextt   set_default_drawing_stylet   emitR   (   R   R.   Rg   t   currentt   subdirR+   t
   style_fileR)   t   pic_filet   rvt   titlet	   desc_textt   desc(    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/pictureWizardGui.pyR   –   s8    *$##!	! &c         C   s�   d d  l  } |  j j ƒ  } | r‡ | j ƒ  r‡ | j t | j ƒ  j d ƒ ƒ d d ƒ } | j t | j d ƒ ƒ d d ƒ } | d | Sd Sd  S(   Niÿÿÿÿi    R-   R,   RI   RH   (   R.   R   Rh   R   R7   RT   RV   (   R   R.   Rq   Rr   R+   (    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/pictureWizardGui.pyt   getStyle½   s    *$c         C   s   d G| G| GHd  S(   NR   (    (   R   RD   t   col(    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/pictureWizardGui.pyR   É   s    c         C   s   d G| G| GHd  S(   Nt   handleItemEntered(    (   R   RD   Rz   (    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/pictureWizardGui.pyR{   Í   s    N(   t   __name__t
   __module__R$   t   FalseR   R	   R   R   R   Ry   R   R{   (    (    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/pictureWizardGui.pyR      s   +	 	'		t   drawingStyleComboc           B   s,   e  Z d g  d  „ Z g  d „ Z d „  Z RS(   c         C   sD   t  t |  ƒ j | ƒ |  j d ƒ |  j d ƒ |  j d | ƒ d  S(   Ni    i
   R+   (   t   superR   R   t   setEditablet   setMaxVisibleItemst   populateMenu(   R   R   R+   (    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/pictureWizardGui.pyR   Ù   s    c         C   s”   t  ƒ  } | j d | ƒ \ } } x> t d t | ƒ ƒ D]' } |  j | | t j | | ƒ ƒ q7 W| j | j ƒ r� |  j	 | j
 | j ƒ ƒ n  d  S(   NR+   i    (   R/   R0   t   rangeRR   t   addItemR   t   QVariantt   countRN   t   setCurrentIndext   index(   R   R+   RA   RB   t
   alias_listRZ   (    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/pictureWizardGui.pyRƒ   à   s    	%c         C   s1   t  |  j |  j ƒ  ƒ j ƒ  ƒ } | t ƒ  _ | S(   N(   RT   t   itemDatat   currentIndext   toStringR/   RN   (   R   t   alias(    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/pictureWizardGui.pyRy   í   s    !N(   R|   R}   R$   R   Rƒ   Ry   (    (    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/pictureWizardGui.pyR   Ô   s   t   pictureWizardGuic           B   sb   e  Z d
 d  d  e d „ Z d d „ Z d  d „ Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z RS(   RH   c         C   sË   t  j j |  | ƒ | |  _ d |  _ g  |  _ | |  _ | d k rc |  j d d ƒ |  j d ƒ n |  j ƒ  |  j d | ƒ |  j	 j
 | ƒ |  j | ƒ |  j |  j	 t j d ƒ |  j ƒ |  j ƒ  d  S(   NRH   t   ALLR   i   s-   Picture wizard to apply to ALL VISIBLE modelss   Picture wizard: Rf   (   R    t   QDialogR   t   recentreIfOnlyOneR]   t   choicest   moldata_nameR	   t   setWindowTitlet   drawingStyleWidgetR   t   updateDrawingStyleR   R   R   R
   (   R   R   R]   R”   R’   (    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/pictureWizardGui.pyR   ü   s    				
"i    c         C   sr  t  j ƒ  } t  j d |  ƒ |  _ |  j j d t ƒ  j ƒ | j |  j ƒ t |  d d d d d | ƒ|  _	 | j |  j	 ƒ t  j
 |  ƒ |  _ | j |  j ƒ t  j |  ƒ } | j t j j ƒ x‘ d t  j j |  j g d t  j j |  j g d	 t  j j |  j g g D]J \ } } } | j | | ƒ } | j d
 ƒ |  j | t j d ƒ | ƒ qW| j | ƒ |  j | ƒ d  S(   Ns"   Delete any existing display objecti   R   R   i–   R   s   Create picturet   Cancelt   Helpi    s	   clicked()(   R    R!   t	   QCheckBoxt   deleteWidgett
   setCheckedR/   t   keep_display_objectsR   R   R–   t   QFramet   definitionFramet   QDialogButtonBoxt   setOrientationR   R9   t
   Horizontalt
   ActionRolet   Applyt
   RejectRolet   hidet   HelpRoleR™   t	   addButtont   setAutoDefaultR   R   R#   (   R   R   R'   t
   button_boxt   labelt   rolet   slott   button(    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/pictureWizardGui.pyR	     s$    !( c         C   s¶   | s |  j  j ƒ  } n  | |  j k r+ d  S| |  _ t ƒ  j d |  j d d ƒ |  _ t ƒ  j d | ƒ } | d d k r› t j j	 |  d | | d ƒ n | d |  _
 |  j ƒ  d  S(   NR]   R^   Ra   i    s   Error reading drawing style i   (   R–   Ry   R]   R/   Ri   Rb   t   read_mgpic_file_choicesR    t   QMessageBoxt   warningR“   t   drawDefinitionFrame(   R   R]   Ru   (    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/pictureWizardGui.pyR—   ,  s      	!!c      
   C   sÛ  |  j  j t j ƒ } |  j ƒ  } x | D] } | j ƒ  q( W|  j  j ƒ  } | d  k r™ t j ƒ  } | j	 d ƒ | j
 d d d d ƒ |  j  j | ƒ n  |  j d k rpt d d ƒ } d  } g  } xŸ | D]— } t | d ƒ r| d  k rt j | j ƒ } t j | j ƒ } n  t | d ƒ rÊ | d  k rÊ x1 | D]% }	 |	 | j k r5| j |	 ƒ q5q5WqÊ qÊ W| j d d ƒ d }
 xY|  j D]ä } | j d	 d ƒ } d
 g j | ƒ r…|
 d }
 t j | j d d ƒ |  ƒ } | j | |
 d d d ƒ | j d d ƒ } | d
 k r-t j |  ƒ } | j | ƒ n  | j | ƒ | j t j j ƒ | j | |
 d d d ƒ q…q…Wngd }
 x^|  j D]S} | j d	 d ƒ } d
 d g j | ƒ r|
 d }
 t j | j d d ƒ |  ƒ } | j | |
 d d d ƒ | j d d ƒ } | d
 k rYt  j! |  d |  j d d d d ƒ} | j" | ƒ rÓ| j# d | | ƒ qÓnz | d k rÓd d d d d g } t  j$ |  d t% |  j ƒ j& d | d d d g ƒ} | j" | ƒ rÓ| j' | | ƒ qÓn  | j | ƒ | j t j j ƒ | j | |
 d d d ƒ q€| d k r€|
 d }
 t j( | j d d ƒ |  ƒ } | j d d ƒ } | j | ƒ | j" | ƒ r…| j) | | ƒ n  | j) t* | j d d ƒ ƒ ƒ | j t j j ƒ | j | |
 d d d ƒ q€q€Wd  S(   Ni    i   R�   t   object_typet   MolDatat   chainsRH   iÿÿÿÿt   typet   chainR«   t   namet   monomert   MolData_nameR^   R„   t   blankt   atomNamet   monomerst
   saccharidet   solutet   peptidet   nucleict   abstractModelt   modelGroupst   selectionWidgetst   namedSelectiont   logicalt   initiali   (+   RŸ   t   findChildrenR    R   t	   getParamst   closeR'   R$   t   QGridLayoutR   R   R#   R”   t   get_dataobjt   hasattrt   copyt   deepcopyRµ   t   removet   insertR“   t   getR‡   R   R   t	   QComboBoxt   addItemst   setObjectNamet   setAttributeR   R9   t   WA_DeleteOnCloset	   mgWidgetst   mgAtomPickert   has_keyt   setSelectiont   mgSelectionCombot   datat	   treeModelRn   Rš   Rœ   t   int(   R   t   togot   paramsRD   R'   t   dataobjst   firstChainst	   allChainst   ot   cht   nnt   defnt	   defn_typeR«   R¸   t   widgetRÃ   (    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/pictureWizardGui.pyR²   A  sˆ     
#
$ 3 
 c      
   C   s—  |  j  ƒ  |  j d k r1 t d d ƒ } t } n t d |  j ƒ g } t } x^ | D]V } | j rS | j d |  j j	 ƒ  d |  j
 ƒ  d d t |  j j ƒ  ƒ d	 | ƒ qS qS Wd
 d  l } | j d | d |  ƒ t ƒ  } | r÷ | j t j d ƒ ƒ n  x6 | D]. } t ƒ  j | j ƒ } | rþ | j ƒ  qþ qþ W| rO| j t j d ƒ ƒ n  |  j r‰t t d d ƒ ƒ d k r‰t ƒ  j d d ƒ n  |  j ƒ  d  S(   NR�   R³   R´   R¸   R]   t   chosenR�   i   t   force_recolour_bymoliÿÿÿÿt   targett   controllingWidgett   applyWizardt   finishedApplyWizardt   glidei    (   R¦   R”   RÌ   t   TrueRÝ   R~   t   visiblet   applyDrawingStyleR–   Ry   RÉ   Rß   R›   t	   isCheckedt   rebuildt   UpdateDisplayt   DISPLAYTABLERp   R   R   t
   getDataObjR¸   t   updateDispObjR’   RR   t
   MAINWINDOWt   handleRecentreRÊ   (   R   t   target_listRì   Rí   Rö   t   dtt   obj(    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/pictureWizardGui.pyR¤   �  s2    
		'	   $c         C   s   d  S(   N(    (   R   (    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/pictureWizardGui.pyt   undo­  s    c         C   s‰  i  } x||  j  D]q} |  j j t j | j d d ƒ ƒ } | r d g j | j d d ƒ ƒ r{ t | j ƒ  ƒ | | d <n  d g j | j d d ƒ ƒ rÅ t	 | d ƒ rÅ t | j
 ƒ  ƒ | | d <q�d g j | j d d ƒ ƒ rCt	 | d ƒ rC| j ƒ  d k rCt | j ƒ  ƒ } | j d ƒ s2| d } n  | | | d <q�d	 g j | j d d ƒ ƒ r�t | j ƒ  ƒ | | d <q�q q W| S(
   NR¸   RH   R¹   R¶   R·   t	   selectiont   currentTextt   /RÆ   (   R“   RŸ   t	   findChildR    R   RÒ   R‡   RT   RV   RÍ   R  R  t   endswithRß   Rõ   (   R   t   parsRè   Rê   Ræ   (    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/pictureWizardGui.pyRÉ   ³  s     $-?$c         C   s   t  ƒ  j d d ƒ d  S(   NRE   s   picture_wizard.html(   t   HELPBROWSERt
   loadMgHelp(   R   (    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/pictureWizardGui.pyR™   È  s    N(   R|   R}   R$   R~   R   R	   R—   R²   R¤   R   RÉ   R™   (    (    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/pictureWizardGui.pyR�   ö   s   	L	 		(   t   __doc__RÎ   t   PyQt4R    R   t   global_definitionst   MGSimpleDialogRØ   Rg   R   R   RÓ   R   R‘   R�   (    (    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/pictureWizardGui.pyt   <module>   s   
µ"