ó
ÉŻ{Tc           @   sK   d  Z  d d l Z d d l Td   Z d   Z d e j f d     YZ d S(   s  
     python/ui/Image.py: CCP4MG Molecular Graphics Program
     Copyright (C) 2001-2008 University of York, CCLRC
     Copyright (C) 2009 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   *c          C   s   d d l  m }  |  j j   S(   Ni’’’’(   t   QtGui(   t   PyQt4R   t   QImageReadert   supportedImageFormats(   R   (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/MGGLImage.pyt   supportedReadFormats   s    c          C   s   d d l  m }  |  j j   S(   Ni’’’’(   R   (   R   R   t   QImageWriterR   (   R   (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/MGGLImage.pyt   supportedWriteFormats%   s    t   Imagec           B   sČ   e  Z i  Z d  d d  g  i  d d  Z d   Z d  d  Z d   Z d d d d d  Z d   Z	 d	   Z
 d  d
  Z d   Z d d  Z d   Z d   Z d   Z d d d d d  Z d   Z RS(   t    t   1i    c      
   K   s±  t  |  _ d d  l } | r0 | j |  |  _ n | j d  rO | d |  _ n  i d d 6d d 6d d g d 6}	 | j d  r£ | j | d d  | d <| d =n  | j d	  r| j d
  r| j | d	 d  | j | d
 d  g | d <| d	 =| d
 =n  | j d  ra| j d  ra| j | d d  | j | d d  g | d <| d =| d =n  |	 j |  |	 j |  t |  j d  t	 k rŗd | j
 |  j d j d   } n d | j
 |  j d  } d d  l }
 t |  j d  t	 k r|
 j |  j d j d   } n |
 j |  j d  } | j   rU| j   rUt |  _ n d G|  j d GHHd  St j j |  d | d | d | d |	 d |  _ g  |  _ d |  _ d  S(   Ni’’’’t   filenameg      š?t   scalet   aspectg        t   positiont	   selectiont   colourt   styleg{®Gįz?t   xt   yi   t   IMGs   utf-8s   Error loading image fileR   t   parentt   visiblet   paramsi    i   (   t   Falset   isValidt   utilst   check_filenameR   t   has_keyt	   safeFloatt   updatet   typet   unicodet   fileRoott   encodet
   image_infot	   get_widtht
   get_heightt   Truet   dataobjt   DispObjt   __init__t   movingt   graph_objectst	   do_redraw(   t   selfR   R   t   nameR   R   t   restore_from_versiont   keywordsR   t   defparsR#   t   image(    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/MGGLImage.pyR)   6   sJ    	

00&"		c         C   s,   |  j  d d !d k r! |  j  d S|  j  Sd  S(   Ni    i   R   (   R.   (   R-   (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/MGGLImage.pyt   get_selection_labelq   s    c         K   s   t  |  |  _ d |  _ d  S(   Ni   (   t   floatR   R,   (   R-   R   R0   (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/MGGLImage.pyt	   set_scalex   s    c         C   s   |  j  S(   N(   R   (   R-   (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/MGGLImage.pyt	   get_scale~   s    c         K   s÷   |  j  \ } } | d  k r* t |  } n  | d  k rE t |  } n  | d  k r | d t |  } | d k  s} | d k r |  j  d } q n  | d  k rŪ | d t |  } | d k  sČ | d k rŪ |  j  d } qŪ n  | | g |  _  d |  _ d  S(   Ngü©ńŅMb`?g      šæg       @i    i   (   R   t   NoneR4   t   intR,   (   R-   R   R   t   dxt   dyR0   t   pxt   py(    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/MGGLImage.pyt   set_position   s        c         C   s   |  j  S(   N(   R   (   R-   (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/MGGLImage.pyt   get_position   s    c         C   s   d |  j  d |  j  d f S(   Ns	   %.2f %.2fi    i   (   R   (   R-   (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/MGGLImage.pyt   get_position_label   s    c         K   s%   | r! t  |  |  _ d |  _ n  d  S(   Ni   (   R4   R   R,   (   R-   R   R0   (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/MGGLImage.pyt
   set_aspect   s    c         C   s   |  j  S(   N(   R   (   R-   (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/MGGLImage.pyt
   get_aspect¤   s    i   c         C   sL   t  j j |  d | } x- d d d d g D] } t |  |  | | <q+ W| S(   Nt   allR   R   R   R   (   R'   R(   R   t   getattr(   R-   RB   t   selt   item(    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/MGGLImage.pyR   ©   s    c         C   s  d d  l  } d } | j |  j   | j  d } | rÄ d } | j d  rf |  j d | j d  n  | j d  r |  j d | j d  n  | j d  rÄ |  j | d d | d d  qÄ n  t | t j	 j
 |  |   } | rž |  j j d g  n  | S(   Ni’’’’i    i   R   R   R   R   (   R   t
   dict_diffsR   R   R5   R@   R=   t   maxR'   R(   t   update_data_status0t
   update_guit   append(   R-   t
   shadowdispR   t   rvt   diffs(    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/MGGLImage.pyt   update_data_status±   s    & c         K   s'   t    j |  j  t j j |   d  S(   N(   t   BUILDt	   deletemodt   graphmodR'   R(   t   delete(   R-   R0   (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/MGGLImage.pyRR   Ć   s    c         C   s>  |  j  s d S|  j d k r  d Sd d l } d d l } d d l } | j d  } | j |  j d |  j d d  | d <|  j s«| j   |  _	 t
   j |  j	  t |  j d  t k rź | j | | d |  j d j d   } n  | j | | d |  j d  } | j   d k r¤| j   d k r¤| j |  j |  j |  j  |  j j |  |  j	 j j |  |  j	 j j   |  j	 j j d  |  j j d  q«d Sn  xf |  j D][ } |  j d k ręt | d  rę| j   n  | j |  | j |  j |  j |  j  qµW|  j	 j   |  j j d  d |  _ d S(	   s=   
    Draw/update method called every cycle of event loop
    i    i’’’’Ni   i   s   utf-8RQ   t   ClearTextureID(   R   R,   t   cprimt   graphicsmodelt
   pygl_coordt   CartesianVectort	   CartesianR   R+   RQ   RO   RJ   R   R   R    t	   BillBoardR"   t   GetImageWidtht   GetImageHeightt   SetScaleR   R   t   objt   add_image_primitivet   rebuildt   SetBuildDisplayListt   do_rebuildGLt   hasattrRS   t   SetVertices(   R-   RT   RU   RV   t   cvt   image_obR]   (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/MGGLImage.pyt   drawĖ   s@    	  '	, $!	g        c      
   K   s7  | r3| r3d } d } d } | j  }	 | j  }
 |  j t |	 |  | t |
 |  t |	 |   |  j d t |	 |  | t |
 |  t |	 |  d t |	 |  | t |
 |  t |	 |   |  j t |	 d  | t |
 d  t |	 d   t j j |  d | d | d | d | n  d  S(	   NR   R   R   R   t   initial_statust   final_statust   fractiont   step(   R   R5   R4   R=   R@   R'   R(   t   movie_interpolation(   R-   Rg   Rh   Ri   Rj   R0   t   skeyt   xkeyt   ykeyt   init   fin(    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/MGGLImage.pyRk     s    		1	011c         C   sn   | j    \ } } } | r6 |  j d | |  j d <n  | rW |  j d | |  j d <n  d |  _ |  j   d S(   s1   
    Handle mouse input to translate objects
    i    i   N(   t   screenTransformR   R,   Rf   (   R-   t   glwidgetR9   R:   t   dz(    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/MGGLImage.pyt	   transform  s      	N(   t   __name__t
   __module__t   class_dependentsR)   R3   R5   R6   R7   R=   R>   R?   R@   RA   R   RN   RR   Rf   Rk   Rt   (    (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/MGGLImage.pyR   2   s$   	:								:(   t   __doc__R'   t   global_definitionsR   R   R(   R   (    (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/MGGLImage.pyt   <module>   s
   
		