ó
ÉÝ{Tc           @   s'   d  Z  d d l Td d d     YZ d S(   sq  
     python/ui/web.py: CCP4MG Molecular Graphics Program
     Copyright (C) 2001-2008 University of York, CCLRC
     Copyright (C) 2009 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   *t   webc        	   B   s   e  Z d Z d    Z d d  Z d d d d d d  Z d d d d d d d d d  Z d   Z d d d d	 d
 d	 d  Z	 d d d  Z
 RS(   c         C   sŽ  d d  l  } |  t _ d  |  _ | j d k rB d d d g |  _ n6 | j d k rf d d d g |  _ n d d d g |  _ d d  l } | j d	 d
 d d d d d d d d d d d d g	 d i	 d d 6|  j	   d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d  i	 d! d" g d 6t
 d# d$ d% |  j |  j g g d 6t
 d& g d 6t
 d' g d 6t
 d( g d 6t
 d) g d 6t
 d* g d 6t
 d+ g d 6t
 d, g d 6d- d.  |  _ d/ |  _ d  S(0   Ni˙˙˙˙t   win32t   netscapet   firefoxt   explorert   darwint   opent	   konquerort   namet   web_addresst   titles   Browser/Web Toolst   guit   internalt   browsert   browser_commandt   EBI_Download_PDBt   EBI_OCAt   RCSB_Searcht   RCSB_Download_PDBt   PDBJapan_Download_PDBt   PDBJapan_Searcht   defaulti   t    s/   http://www.ebi.ac.uk/msd-srv/msdlite/index.htmls   http://www.rcsb.org/pdbs   'http://www.rcsb.org/pdb/cgi/export.cgi/' + pdbid + '.pdb?job=download;pdbId=' + pdbid +';opt=show;format=PDB;pre=1&compression=gz'sJ   'ftp://ftp.ebi.ac.uk/pub/databases/msd/pdb_uncompressed/pdb'+pdbid+'.ent' s,   'ftp://www.pdbj.org/pdb_nc/pdb'+pdbid+'.ent's4   http://pdbjs3.protein.osaka-u.ac.jp/xPSSS/index.htmlt
   definitiont   bools!   Use internal browser (Linux only)s   Web browsert   TYPEDEFt   menus   Browser executable paths   EBI OCA search pages   RCSB search pages   RSCB PDB download commands   EBI PDB download commands    PDBJapan download commands    PDBJapan search paget   helpR   t   EBI(   t   sysR   t   instst   Nonet	   schedulert   platformt   browserlistt   servicest   ParamsManagert   set_default_browsert   strt   paramst   default_server(   t   selfR   R$   (    (    s:   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/web.pyt   __init__   sD    			!"R   c         B   sG  d d  l  } d d  l } d d  l } | d k rI d |  j j d d  UnJ | d k rn d |  j j d d  Un% | d k r d |  j j d d  Un  g  } | j   } | j d	  zl y) | j e  } | j   }	 | j	   Wn< | j
 k
 r}
 d
 d g } n d d | d g } n XWd  | j |  X| s?d |	 g S| Sd  S(   Ni˙˙˙˙t   RCSBs
   urlname = R   R   R   t   PDBjapanR   i
   i   s   Timeout waiting?i   s   No data called t   ?i    (   t   urllibt   sockett   timeoutsocketR(   t   getDefaultSocketTimeoutt   setDefaultSocketTimeoutt   urlopent   urlnamet   readt   closet   error(   R*   t   pdbidt   serverR/   R0   R1   t   rett   dtot   urlt   pdbdatat   msg(    (    s:   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/web.pyt
   GetPDBFileK   s2    
R   c         K   s.  d d  l  } d d  l } | r | d k rM |  j d |  j j d d d  q | d k r| |  j d |  j j d d d  q |  j d |  j j d d d  n  | r*| r*| j | j |   } | j | d	  d
 d }	 | j d |	  }
 t   j	 j
 d d d d d |	 g d |
 g g g g  n  d  S(   Ni˙˙˙˙R   R=   R   R   R,   R   R   t   ,i    s   .pdbR   t   downloadpdbfilet   OBJECTt
   local_filet	   CONFIGUREt   filenamet   fullname(   t   stringt   utilst   launch_browserR(   t   lowert   stript   splitt   get_filenamet   MGGUIR   t   UpdateGUIWindow(   R*   t   IDRD   t   DIR_local_filet   view_serverR:   t   keywordsRH   RI   R	   RG   (    (    s:   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/web.pyt   downloadpdb_handlerr   s"    ###	i   t	   all_atomsc	         K   s[  d d  l  }
 | d k r d  Sd d g j |  r: d } n  d d d g j |  r^ | |  _ n  | s~ t   j d d d	 d  Sd d  l } d d  l } d d  l } d d  l } | j	 | j
 |   } | j | d
  d } | sţ | d } t   j   } n  |
 j | |  } | j j |  rDt   j d | d d d	 d  S|  j | d | \ } } | rt   j | d d	 d  S| st   j d d d	 n  | ry1 |
 j | d d  } | j |  | j   Wn& t   j d | d d d	 d  SXy9 | j | d  } t | d  } | j | j    Wn" t   j d | d d	 d  SXy) | j   | j   | j | d  WqqXn | j d |  ržt   j d d d	 d  Sy- |
 j | d  } | j |  | j   Wn% t   j j d | d d	 d  SXt   j d	  d d  l } | j d | d | d | d | d |  d  S(   Ni˙˙˙˙t   dismissR   R-   i    R,   s!   You must enter a four-letter codet   parentRB   t   .s   .pdbs   A file called s    already existsR:   s   No data returned from servers   .gzt   wbs%   Error saving compressed data to file s   Error saving data to file s   <HTML>s!   Error reported from download sitet   wt   pdbint	   DIR_pdbint   drawing_stylet   show_gui_on_loadingt   exit(   RI   t   countR)   RO   t   WarningMessaget   gzipRH   t   ost   reRK   RL   RM   t   CCP4DATABASEt   get_current_projectRN   t   patht   existsR@   t   openFilet   writeR7   R   R6   t   removet   searchR   t   DeleteGUIWindowt   modelt   openpdbfile(   R*   R:   RQ   RD   RR   t   compressR^   R_   R`   RT   RI   Rc   RH   Rd   Re   t   filnt   statusR>   t   outputt   inputt   uncomp_outputRo   (    (    s:   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/web.pyRB      s      	 

	

c   
      C   sĺ   d d  l  } d d  l } d d  l } d d  l } d d  l } d } | j d | j  r[ d S| j d | j  rt d Sd d d	 d
 g } xX | D]L } xC | j | j d |  D]( }	 | j | j	 j
 |	 |   r­ | Sq­ Wq Wd
 Sd  S(   Ni˙˙˙˙t   :R   R   t   winR   R   R   t   mozillaR   t   PATH(   R   Re   RH   t   globRd   Rm   R"   RM   t   environRh   t   join(
   R*   R   Re   RH   R{   Rd   t	   separatort   browser_listR   Rh   (    (    s:   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/web.pyR&   ě   s      i    i˙˙˙˙c         K   s%  d d  l  } d d  l }	 d d  l }
 |
 j |	 j d  d k rf | d k rl |  j j j d  } ql n d } | r[|  j rĂ | | k s | j j	 |  rĂ |  j j
 |  j g  i | d 6| d 6 n  | j j	 |  s[| d k  r|  j r|  j j |  j g  i | d 6| d 6d | d d  S| | k s5|  j rTd	 G| Gd
 GHd d | d g Sd  Sn  | rnd | } n | rd | } n  | d k r­d d  l } | j d |  d  Sg  } |  j j j d  } |  j j j d  } |	 j d k r| sű| } n  | r| d | d } nN | rd| d | } | rWd d g j |  rW| d | } n  | d } n  d G| GHy | j |  Wqd d | d g SXnd d  l } d d  l }
 d d  l } d d  l } | séd  } d } d d d g } x| | d  k ri| t |  k  riy+ | d } | j | j | | d  } Wn d  } n X| rî| j | d  d } qîqîW| sx| rt   j d | d  d  S| j d  |  rŻd } n! | j d! |  rĘd" } n d# } d$ G| G| GHd% G| GHn  | j |  } |
 j | d d&  } xF | d D]: } | j d' |  d k  r| j |
 j | d&   qqWd d" d( g j |  rĹ| j d)  s| j d)  n  | j  d* d+ |  } | j d |  sĹd, | } qĹn  | j | j! |   d- G| Gd. G| GHy | j" | j# | |  Wn d/ d | g SXd d g S(0   Ni˙˙˙˙t   nuxi    R   t   filet   targett	   max_retryi   s!   Error attempting to display file:s    file does not exists"   Error attempting to display file: s   \n file does not exists   browser R   R   R   t    s    &R   R   t   #s   launch_browser cmds   Error launching s    browsert   HTTPt   httpt   httpss   \shell\open\commandR   s%   Failed to find executable for browsers~   //nPlease use the Preferences, Web Tools interface to choose another browser//n or enter the full path name for the executables	   IREF|irefs	   ETSC|etscR   R   s   launch_browser keys   treat as browsert   "t   %Ry   s   -urls   \\t   /s   file:///s   launch browser cmdt   argsi   ($   Rd   R   RH   t   findR"   R(   t   getR!   Rh   Ri   t
   RemoveTaskRJ   t   AddTaskt   guiUtilst   guiHelpRa   t   systemt   _winregRI   Re   R    t   lent   OpenKeyt   HKEY_CLASSES_ROOTt   QueryValueExRO   Rb   Rm   t   splitWords0RL   t   matcht   appendt   subt
   msvcescapet   spawnvt   P_NOWAIT(   R*   R=   R   R   R   t   retryR   RT   Rd   R   RH   t   cmdR   R   R   R   R   RI   Re   t   keyt   iit   trytheset
   comd_wordst   word(    (    s:   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/web.pyRJ     s¸    $ '



 	 	!
!
		   c         K   sd   d d  l  } d d  l } | j | j d  d k rJ t   j d |  n |  j d | d d  d  S(   Ni˙˙˙˙R   i    s   run_anigif R   R   (   R   RH   R   R"   RO   t   SendRJ   (   R*   R   R   RT   R   RH   (    (    s:   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/web.pyt   display_ani_gif  s    N(   t   __name__t
   __module__R    R   R+   R@   RU   RB   R&   RJ   R¨   (    (    (    s:   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/web.pyR      s   	,'		_		N(    (   t   __doc__t   global_definitionsR   (    (    (    s:   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/web.pyt   <module>   s   
