ó
ÉÝ{Tc           @   sI  d  Z  d d l Z d d l Z d d l Z d d l m Z m Z i  Z d d g Z d e j	 f d „  ƒ  YZ
 d e f d	 „  ƒ  YZ d
 e f d „  ƒ  YZ d „  Z d „  Z d „  Z d d i  d d d d „ Z d i  d d d „ Z d i  d d d „ Z d d „ Z g  Z d d g  d d i  d „ Z d „  Z d d d d d d „ Z d S(   sw  
     qtgui/guiUtils.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ÿÿÿÿN(   t   QtGuit   QtCores   .svgs   .pngt   mgMenuc           B   s   e  Z d d  „ Z d „  Z RS(   c         C   s   t  j j |  | ƒ d  S(   N(   R    t   QMenut   __init__(   t   selft   parent(    (    s;   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/guiUtils.pyR      s    c         C   s]   |  j  t j | j ƒ  | j ƒ  ƒ ƒ } | rF | j t j d ƒ ƒ n  t j j	 |  | ƒ d  S(   Nt   mouseRelease(
   t   actionAtR   t   QPointt   xt   yt   emitt   SIGNALR    R   t   mouseReleaseEvent(   R   t   eventt   action(    (    s;   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/guiUtils.pyR      s    'N(   t   __name__t
   __module__t   NoneR   R   (    (    (    s;   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/guiUtils.pyR      s   t   partialc           B   s   e  Z d  „  Z d „  Z RS(   c          O   s3   |  d } |  d |  d | | _  | _ | _ d  S(   Ni    i   i   (   t   fnt   argst   kw(   R   R   R   (    (    s;   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/guiUtils.pyR   3   s    
c         O   sP   | r. |  j  r. |  j  j ƒ  } | j | ƒ n | p: |  j  } |  j |  j | Ž  S(   N(   R   t   copyt   updateR   R   (   R   R   R   t   d(    (    s;   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/guiUtils.pyt   __call__7   s
    (   R   R   R   R   (    (    (    s;   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/guiUtils.pyR   1   s   	t   partialWithSignalc           B   s   e  Z d  „  Z d „  Z RS(   c          O   s3   |  d } |  d |  d | | _  | _ | _ d  S(   Ni    i   i   (   R   R   R   (   R   R   R   (    (    s;   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/guiUtils.pyR   A   s    
c         O   sT   | r. |  j  r. |  j  j ƒ  } | j | ƒ n | p: |  j  } |  j |  j | | Ž  S(   N(   R   R   R   R   R   (   R   R   R   R   (    (    s;   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/guiUtils.pyR   E   s
    (   R   R   R   R   (    (    (    s;   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/guiUtils.pyR   ?   s   	c         C   s   |  r t  j j St  j j Sd  S(   N(   R   t   Qtt   Checkedt	   Unchecked(   t   inp(    (    s;   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/guiUtils.pyt
   checkStateM   s    
c         C   s   |  t  j j k r d Sd Sd  S(   Ni    i   (   R   R   R   (   R    (    (    s;   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/guiUtils.pyt   fromCheckStateS   s    c         C   s(   | j  |  ƒ r  | | j |  ƒ S|  Sd  S(   N(   t   countt   index(   t   textt	   menu_listt
   alias_list(    (    s;   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/guiUtils.pyt   fromMenuZ   s    t    c         C   sÚ  | r | } n | j  |  ƒ } | j d ƒ r5 | d Sd } | j d ƒ rw t | d ƒ rj | d ƒ  } qw | d } n  | d  k rû | j d ƒ ræ | j t j | d ƒ } | sÔ t j | ƒ } | j | d ƒ n  | j | ƒ }	 qt j	 | | ƒ }	 n | }	 |	 j |  ƒ | j d ƒ rn| d rnt
 | d t j ƒ rQ|	 j | d ƒ qn|	 j t j | d ƒ ƒ n  t |  | d | d | ƒ}
 |
 r¬|	 j |
 ƒ |	 j t ƒ n  | j d d ƒ } | rÔ|	 j | ƒ n  | j d	 ƒ rf| d	 rf|	 j d
 ƒ | j d ƒ rft | d ƒ rf| d ƒ  } t | ƒ t j k sPt | ƒ t j k rc|	 j | ƒ qcqfn  | j d ƒ rÜt | d ƒ r•| d ƒ  } n
 | d } t | ƒ t j k sÉt | ƒ t j k rÜ|	 j | ƒ qÜn  | j d ƒ r| d rt j |	 ƒ |	 j ƒ  n  | j d ƒ r+| d } n d } | j d d ƒ rÖ| d  k rÖt
 | d t j ƒ r³t | d ƒ d
 k r³| j |	 t  j! | ƒ t" | d d | d d
 ƒ ƒ qÖ| j |	 t  j! | ƒ | d ƒ n  |	 S(   NR   R)   R%   t   groupt   shortcutt	   icon_patht   default_icont   toolTipt	   checkablei   t   checkedt   enabledt   deleteLatert   signals   triggered()t   sloti    (#   t   getActionDeft   has_keyt   callableR   t	   findChildR    t   QActionGroupt   setObjectNamet	   addActiont   QActiont
   isinstancet   typest   IntTypet   setShortcutt   QKeySequencet
   createIcont   setIcont   setIconVisibleInMenut   Truet   gett
   setToolTipt   setCheckablet   typet   BooleanTypet
   setCheckedt
   setEnabledt   actionst   appendR2   t   ListTypet   lent   connectR   R   R   (   t   nameR   t
   definitionR,   R-   t   existing_actiont   adefR%   R*   t   at   icont   tipt   resR3   (    (    s;   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/guiUtils.pyt   createActiond   sl    	 *
*,8#t   unknownc         C   s6  | j  d ƒ r, | d r, t | d ƒ } n t |  ƒ } t j j | ƒ ro t j j | ƒ | k ro t j | ƒ S| s£ t j j t j j	 t j
 d ƒ d d ƒ } n  xF t D]> } t j j | | | ƒ } t j j | ƒ rª t j | ƒ Sqª W| r.t j j t j j	 t j
 d ƒ d | d ƒ } t j | ƒ Sd  Sd  S(   NRW   t   CCP4MGt   qticonsRM   s   .png(   R6   t   strt   ost   patht   existst   basenameR    t   QIcont   joint   abspatht   environt   ICON_EXTENSIONSR   (   RR   RU   R,   R-   t	   icon_namet   extt   file(    (    s;   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/guiUtils.pyRB   »   s    * ./c         C   s½   t  |  | | | ƒ } | j | ƒ | j d ƒ r¹ | j d ƒ r¹ t | d ƒ t k r’ | j | t j | d ƒ t | d d | d d ƒ ƒ q¹ | j | t j | d ƒ | d ƒ n  | S(   NR4   R3   i    i   (	   RZ   R;   R6   RI   t   tupleRQ   R   R   R   (   RR   RS   R   R,   R   (    (    s;   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/guiUtils.pyt   addMenuEntryÒ   s    <'c         C   s;   |  j  t j ƒ } |  j ƒ  x | D] } | j ƒ  q# Wd  S(   N(   t   findChildrenR    R   t   clear(   t   menut   submenust   sm(    (    s;   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/guiUtils.pyt	   clearMenuß   s    
 c         C   s  | s/ | j  t d |  i d d 6d | ƒƒ nÏt | t j ƒ si |  j | t j d ƒ t | | ƒ ƒ n•x’| D]Š} d  } | d k r• | j
 ƒ  n  t | t j ƒ r…t | ƒ d k r…| j | d ƒ } t | ƒ d k rî | j d ƒ qút | d t j ƒ r6t d	 |  d
 | d | d d | d | d | ƒ qút | d t j ƒ rú|  j | t j d ƒ t | d | | d f ƒ ƒ qúqp | r£t | | g | ƒ }	 n t |  j | g | ƒ }	 |	 rä|  j t j | ƒ } | rå| }
 n d  }
 | s@|	 j d ƒ r%t | |  |	 d |	 d d | ƒ} qát | |  |	 d | ƒ} qä|	 j d ƒ rzt | |  |	 d |	 d d | d |
 ƒ} n t | |  |	 d | d |
 ƒ} |	 j d ƒ rÎt |	 d ƒ rÎ| j |	 d ƒ  ƒ n  |	 j d ƒ rt |	 d ƒ r| j |	 d ƒ n  |	 j d ƒ rkt |	 d ƒ rk|	 d ƒ  } t | ƒ t j k sXt | ƒ t j k rk| j | ƒ qkn  |	 j d ƒ rät |	 d ƒ rš|	 d ƒ  } n
 |	 d } t | ƒ t j k sÎt | ƒ t j k rá| j | ƒ qáqän  | rp | j  | ƒ qp qp Wd  S(   Nt   dummys     --  R%   R-   s   aboutToShow()t   sepi    i   R   t
   menuWidgetRS   R5   t   infoR,   RT   R0   R1   (   R;   RZ   R=   R>   RO   RQ   R   R   R   R   t   addSeparatorRP   t   addMenuRL   t
   StringTypet   populateMenut
   MethodTypet   applyR5   R8   R    R<   R6   R7   t   setTextRI   R?   RJ   RK   (   R   Ru   RS   R5   R-   Rv   t   itemRV   t   sub_menuRU   RT   RY   (    (    s;   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/guiUtils.pyRz   è   s^    )($29	%+ *
* c         C   s6   |  j  ƒ  } | s d  St j j t j j ƒ  | ƒ d  S(   N(   R.   R    t   QToolTipt   showTextt   QCursort   pos(   R   RX   (    (    s;   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/guiUtils.pyt   handleMenuHover,  s     RM   i    i    c   
      C   su  | r | } n  t  | ƒ d t  | ƒ } t j |  ƒ oI t |  j | ƒ rT| r t j j t j j t j d ƒ d ƒ } n  d } xF t D]> } t j j | | |  | ƒ } t j j	 | ƒ rÊ | } Pn  qŒ W| rt j j t j d d d ƒ } t j j	 | ƒ rt
 Sn  n  t j |  ƒ r.i  t |  <n  t j | ƒ j | | ƒ t |  | <n  t |  | Sd t j j d „ }	 (   Nt   _R\   R]   R)   s   unknown.pngc         S   s+   t  j | ƒ } |  j j | | ƒ |  _ d  S(   N(   R   t   QUrlt   textBrowsert   loadResourcet   style(   R   t   urlt   modet   qu(    (    s;   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/guiUtils.pyRˆ   R  s    (   R^   t   LOADED_PIXMAPSR6   R_   R`   Rd   Re   Rf   Rg   Ra   R   R    t   QPixmapt   scaledt   QTextDocumentt   StyleSheetResource(
   RR   R*   R,   t   widtht   heightt   size_keyRj   Ri   t   fRˆ   (    (    s;   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/guiUtils.pyt
   loadPixmap3  s*     	#+
 &(   t   __doc__R_   R>   R   t   PyQt4R    R   R�   Rg   R   R   t   objectR   R   R!   R"   R(   R   RZ   RB   Rl   Rr   RM   Rz   R„   R–   (    (    (    s;   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/guiUtils.pyt   <module>   s&   $			
W	C	