ó
ÉÝ{Tc           @   s&  d  Z  d d l Z d d l m Z m Z m 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
 e j f d „  ƒ  YZ e d k r"d e j k rÒ e j ƒ  n  d d „ Z e j e j ƒ Z y: e j d k re j j d ƒ Z n e j j d ƒ Z Wn n Xe r´e j j e ƒ r´e j j e d ƒ Z e j j e ƒ r†e j j  e ƒ q´y! e j! e ƒ e j j  e ƒ Wq´q´Xn  e ƒ  Z" e" j# e" e j$ d ƒ e ƒ e" j% d d g ƒ e" j& ƒ  e" j' e j( d ƒ ƒ e j e j) ƒ  ƒ n  d S(   s{  
     qtgui/MGWebBrowser.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   QtWebKitt   QtGuit   QtCoret	   MGWebPagec           B   s;   e  Z d d d d  „ Z d d „ Z d „  Z d d „ Z RS(   c         C   sl   xe |  j  D]V } t j j t | j ƒ  j ƒ  ƒ ƒ j | ƒ r
 |  j t j	 d ƒ | j ƒ  ƒ t
 Sq
 Wt Sd  S(   Nt   CustomMimeTypeRequested(   t   customTypest   ost   patht   basenamet   strt   urlt   endswitht   emitR   t   SIGNALt   Falset   True(   t   selft   framet   requestt   type(    (    s?   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/MGWebBrowser.pyt   acceptNavigationRequest   s
    -c         C   s    t  j j |  | ƒ g  |  _ d  S(   N(   R    t   QWebPaget   __init__R   (   R   t   parent(    (    s?   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/MGWebBrowser.pyR   "   s    c         C   s   |  j  S(   N(   R   (   R   (    (    s?   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/MGWebBrowser.pyt   customMimeTypes&   s    c         C   s:   | r t  | ƒ t k s* t  | ƒ t k r6 | |  _ n  d  S(   N(   R   t   tuplet   listR   (   R   t   types(    (    s?   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/MGWebBrowser.pyt   setCustomMimeTypes)   s    *N(   t   __name__t
   __module__t   NoneR   R   R   R   (    (    (    s?   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/MGWebBrowser.pyR      s   	t	   MGWebViewc           B   s€   e  Z d d  „ Z d „  Z d d „ Z d d „ Z d „  Z d d „ Z d d „ Z	 d „  Z
 d d „ Z d	 „  Z d d
 „ Z RS(   c         C   s9   t  ƒ  } | j |  j ƒ  ƒ |  j t j d ƒ | ƒ | S(   Nt   NewWindowRequested(   R    R   R   R   R   R   (   R   R   t   view(    (    s?   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/MGWebBrowser.pyt   createWindow/   s    	c         C   s/   t  j ƒ  } |  j t j d ƒ | |  f ƒ d  S(   Nt	   IconReady(   R   t   QIconR   R   R   (   R   t   icon(    (    s?   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/MGWebBrowser.pyt   LoadStarted5   s    c         C   s   | |  _  d  S(   N(   t   target(   R   R(   (    (    s?   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/MGWebBrowser.pyt	   setTarget9   s    c         C   sq   |  j  ƒ  } |  j rN |  j ƒ  } | j |  j ƒ |  j d ƒ |  j | ƒ n  |  j t j d ƒ | |  f ƒ d  S(   Nt    R$   (	   R&   R(   R
   t   setFragmentR)   t   loadR   R   R   (   R   t   okR&   t   myurl(    (    s?   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/MGWebBrowser.pyt   LoadFinished<   s    	c         C   s   |  j  ƒ  j ƒ  S(   N(   t   pageR   (   R   (    (    s?   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/MGWebBrowser.pyR   F   s    c         C   sD   | r t  | ƒ t k s* t  | ƒ t k r@ |  j ƒ  j | ƒ n  d  S(   N(   R   R   R   R0   R   (   R   R   (    (    s?   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/MGWebBrowser.pyR   I   s    *c         C   s&   | r" |  j  t j d ƒ | ƒ n  d  S(   NR   (   R   R   R   (   R   R
   (    (    s?   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/MGWebBrowser.pyR   M   s     c         C   s    t  j j ƒ  j |  j ƒ  ƒ d  S(   N(   R   t   QApplicationt	   clipboardt   setTextt   selectedText(   R   (    (    s?   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/MGWebBrowser.pyt   copyHighlightedP   s    c         C   s-  t  j j |  | ƒ t |  ƒ |  _ |  j |  j ƒ |  j |  j t j d ƒ |  j	 ƒ |  j |  j t j d ƒ |  j
 ƒ |  j |  j t j d ƒ |  j ƒ |  j |  t j d ƒ |  j ƒ |  j |  t j d ƒ |  j ƒ t j t j |  j d d ƒ ƒ |  ƒ } |  j | t j d ƒ |  j ƒ |  j d	 ƒ d  S(
   NR   s    statusBarMessage(const QString&)s>   linkHovered(const QString &, const QString &, const QString &)s   loadFinished(bool)s   loadStarted()s   Ctrl+Ct   Copys   activated()R*   (   R    t   QWebViewR   R   t   mgpaget   setPaget   connectR   R   R   t   StatusBarMessaget   LinkHoveredR/   R'   R   t	   QShortcutt   QKeySequencet   trR5   R)   (   R   R   t   shortcut(    (    s?   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/MGWebBrowser.pyR   S   s    """'c         C   s   |  j  t j d ƒ | ƒ d  S(   NR;   (   R   R   R   (   R   t   linkt   titlet   content(    (    s?   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/MGWebBrowser.pyR<   g   s    c         C   s   |  j  t j d ƒ | ƒ d  S(   NR;   (   R   R   R   (   R   t   message(    (    s?   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/MGWebBrowser.pyR;   j   s    N(   R   R   R   R#   R'   R)   R/   R   R   R   R5   R   R<   R;   (    (    (    s?   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/MGWebBrowser.pyR    -   s   	
			t   MGTabWidgetc           B   s    e  Z d d  „ Z d d „ Z RS(   c         C   s	   | GHd  S(   N(    (   R   t   event(    (    s?   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/MGWebBrowser.pyt   contextMenuEventn   s    c         C   s   t  j j |  | ƒ d  S(   N(   R   t
   QTabWidgetR   (   R   R   (    (    s?   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/MGWebBrowser.pyR   q   s    N(   R   R   R   RG   R   (    (    (    s?   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/MGWebBrowser.pyRE   m   s   t   MGBrowserWindowc           B   s¿   e  Z d d  „ Z d d „ Z d d „ Z d d „ Z e d „ Z d d „ Z	 d d d „ Z
 d „  Z d	 „  Z d d
 „ Z d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   s   |  j  ƒ  } | j | ƒ d  S(   N(   t	   statusBart   showMessage(   R   RD   t   sb(    (    s?   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/MGWebBrowser.pyR;   u   s    c         C   sd   x] t  |  j j ƒ  ƒ D]F } |  j j | ƒ } t | d ƒ r t | j ƒ r | j | ƒ q q Wd  S(   NR   (   t   ranget   tabt   countt   widgett   hasattrt   callableR   (   R   R   t   iRP   (    (    s?   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/MGWebBrowser.pyR   y   s    c         C   sÁ   | r½ |  j  j | | j ƒ  ƒ | j | t j d ƒ |  j ƒ |  j | t j d ƒ |  j ƒ |  j | t j d ƒ |  j ƒ |  j | t j d ƒ |  j	 ƒ |  j | t j d ƒ |  j
 ƒ n  d  S(   NR   R!   R;   s   titleChanged(const QString &)R$   (   RN   t   addTabRB   R:   R   R   R   R!   R;   t   setTabTitlesR$   (   R   R"   (    (    s?   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/MGWebBrowser.pyR!      s    c         C   s%  xi t  |  j j ƒ  ƒ D]R } |  j j | ƒ } t | d ƒ r t | j ƒ r |  j j | | j ƒ  ƒ q q W|  j d |  j j	 |  j j
 ƒ  ƒ ƒ |  j j |  j j
 ƒ  ƒ } t | d ƒ rt | j ƒ rt | j ƒ  d ƒ rt | j ƒ  j ƒ r|  j j | j ƒ  j ƒ  ƒ qn  |  j ƒ  d  S(   NRB   s   CCP4mg Browser: R
   t   toString(   RM   RN   RO   RP   RQ   RR   RB   t
   setTabTextt   setWindowTitlet   tabTextt   currentIndexR
   RV   t   addressEditR3   t   setHistoryActionAvailability(   R   RB   RS   RP   (    (    s?   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/MGWebBrowser.pyRU   ˆ   s     &*"c         C   s?   |  j  j ƒ  d k r1 |  j  j |  j  j ƒ  ƒ n  |  j ƒ  d  S(   Ni   (   RN   RO   t	   removeTabRZ   R\   (   R   R-   (    (    s?   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/MGWebBrowser.pyt	   DeleteTab•   s    c         C   s   |  j  t j d ƒ | ƒ d  S(   NR   (   R   R   R   (   R   R
   (    (    s?   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/MGWebBrowser.pyR   š   s    R*   c         C   sf   | r< t  j j t  j d d d | | ƒ } |  j | ƒ d  S|  j t  j j t  j d d | ƒ ƒ d  S(   Nt   CCP4MGt   qtguit   pluginst   help(   R   R   t   joint   environt   loadFile(   R   t   filet   plugint   filename(    (    s?   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/MGWebBrowser.pyt
   loadMgHelpž   s
    %c         C   sï   | } d  } | j d ƒ d k r< | j d d ƒ \ } } n  t j j | ƒ rc t j j | ƒ } n{ t j j | d ƒ r¯ | d } | rš | d | } n  t j j | ƒ } n/ | d d !d k sØ t j d | ƒ } n | } |  j	 | ƒ d  S(   Nt   #i    i   s   .htmli   t   https   http://(
   R   t   findt   splitR   R   t   existsR   t   QUrlt   fromLocalFilet   loadPage(   R   Rf   t   ftestR(   R
   t   urlName(    (    s?   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/MGWebBrowser.pyRe   ¥   s     
c   
      C   sù  d } | j  ƒ  d k r� t | j ƒ  j ƒ  ƒ j d ƒ d k r� t | j ƒ  j ƒ  ƒ j d d ƒ \ } } t j j | ƒ } q� n  | j	 r� n d  S|  j
 j ƒ  d k r>|  j
 j ƒ  } t | d ƒ r>t | j ƒ r>y | j | ƒ | j | ƒ WnC t j ƒ  d  \ } } } | GH| GHd d  l } | j | ƒ n Xd  Sn  t ƒ  }	 |	 j |	 t j d	 ƒ |  j ƒ |  j |	 t j d
 ƒ |  j ƒ |  j |	 t j d ƒ |  j ƒ |  j |	 t j d ƒ |  j ƒ |  j |	 t j d ƒ |  j ƒ |  j
 j |	 d ƒ d  S(   NR*   Rf   Rj   i    i   R,   i   iÿÿÿÿR   R!   R;   s   titleChanged(const QString &)R$   t   MGWebBrowser(   t   schemeR	   R   t   toAsciiRl   Rm   R   Ro   Rp   t   isValidRN   RO   t   currentWidgetRQ   RR   R,   R)   t   syst   exc_infot	   tracebackt   print_tbR    R:   R   R   R!   R;   RU   R$   RT   (
   R   R
   R(   t   urlpathRP   t   exc_typet	   exc_valuet   exc_tbR{   R"   (    (    s?   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/MGWebBrowser.pyRq   ¶   s8    '*		c         C   sd   | \ } } xQ t  |  j j ƒ  ƒ D]: } |  j j | ƒ } | | k r" |  j j | | ƒ q" q" Wd  S(   N(   RM   RN   RO   RP   t
   setTabIcon(   R   t   argsR&   R"   RS   RP   (    (    s?   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/MGWebBrowser.pyR$   Ö   s
    c   	      C   s*  | s! d d  l  } | j ƒ  } n  t j j |  | ƒ t |  ƒ |  _ t j ƒ  } | j |  j	 d ƒ ƒ |  j j
 | ƒ |  j | t j d ƒ |  j ƒ t ƒ  } | j | t j d ƒ |  j ƒ |  j | t j d ƒ |  j ƒ |  j | t j d ƒ |  j ƒ |  j | t j d ƒ |  j ƒ |  j | t j d ƒ |  j ƒ |  j j | d	 ƒ |  j |  j ƒ |  j d
 ƒ } t j |  ƒ |  _ t j |  ƒ |  _ |  j j |  j	 d ƒ ƒ |  j j |  j	 d ƒ ƒ | j |  j ƒ | j |  j ƒ t j ƒ  |  _ t j ƒ  |  _ d } |  j j | ƒ t j  ƒ  } | j! |  j ƒ | j! |  j ƒ |  j |  j t j d ƒ |  j" ƒ |  j |  j t j d ƒ |  j# ƒ | j$ d d ƒ | j! | ƒ |  j |  j t j d ƒ |  j% ƒ |  j |  j t j d ƒ |  j& ƒ |  j' ƒ  |  j |  j t j d ƒ |  j ƒ |  j( ƒ  } d |  _) d  S(   Niÿÿÿÿs
   Delete tabs   clicked(bool)R   R!   R;   s   titleChanged(const QString &)R$   Rt   t   ToolBart   Backt   Forwards›   QLineEdit {
             		border: 1px solid gray;
             		border-radius: 12;
			border-style: inset;
             		padding: 0 3px;
         	}
	 	s   returnPressed()i    i   s   triggered(bool)s   currentChanged(int)s   http://www.google.com/search?q=(*   t   global_definitionst
   MAINWINDOWR   t   QMainWindowR   RE   RN   t   QPushButtonR3   R?   t   setCornerWidgetR:   R   R   R^   R    R   R!   R;   RU   R$   RT   t   setCentralWidgett
   addToolBart   QActiont
   backActiont   forwardActiont	   addActiont	   QLineEditR[   t
   searchEditt   setStyleSheett	   QSplittert	   addWidgett   addressEditedt   searchEditedt   setStretchFactort   historyBackt   historyForwardR\   RJ   t   searchEngineString(	   R   R   R†   t   pbR"   t   toolbart   searchStylet   editSplitterRL   (    (    s?   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/MGWebBrowser.pyR   Ý   sR    	""""
"c         C   sN   |  j  j ƒ  j t j d ƒ t j d ƒ ƒ } |  j t j |  j | ƒ ƒ d  S(   Ns   \s+t   +(	   R’   t   textt   replaceR   t   QRegExpt   QStringRq   Ro   R›   (   R   R¡   (    (    s?   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/MGWebBrowser.pyR—     s    -c         C   s#   |  j  t j |  j j ƒ  ƒ ƒ d  S(   N(   Rq   R   Ro   R[   R¡   (   R   (    (    s?   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/MGWebBrowser.pyR–     s    c         C   sž   |  j  j ƒ  } t | d ƒ rš t | j ƒ rš | j ƒ  } | j ƒ  rX |  j j t ƒ n |  j j t	 ƒ | j
 ƒ  r‡ |  j j t ƒ qš |  j j t	 ƒ n  d  S(   Nt   history(   RN   Rx   RQ   RR   R¥   t   canGoForwardR�   t
   setEnabledR   R   t	   canGoBackRŽ   (   R   RP   R¥   (    (    s?   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/MGWebBrowser.pyR\     s    c         C   sl   |  j  j ƒ  } t | d ƒ r^ t | j ƒ r^ | j ƒ  } | j ƒ  r^ | j | j ƒ  ƒ q^ n  |  j ƒ  d  S(   NR¥   (	   RN   Rx   RQ   RR   R¥   R¦   t   goToItemt   forwardItemR\   (   R   RP   R¥   (    (    s?   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/MGWebBrowser.pyRš   $  s    c         C   sl   |  j  j ƒ  } t | d ƒ r^ t | j ƒ r^ | j ƒ  } | j ƒ  r^ | j | j ƒ  ƒ q^ n  |  j ƒ  d  S(   NR¥   (	   RN   Rx   RQ   RR   R¥   R¨   R©   t   backItemR\   (   R   RP   R¥   (    (    s?   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/MGWebBrowser.pyR™   ,  s    c         C   s6   t  j t j j ƒ  j ƒ  d t j j ƒ  j ƒ  d ƒ S(   Ni   i   (   R   t   QSizeR   R1   t   desktopt   widtht   height(   R   (    (    s?   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/MGWebBrowser.pyt   minimumSizeHint4  s    N(   R   R   R   R;   R   R!   RU   R   R^   R   Ri   Re   Rq   R$   R   R—   R–   R\   Rš   R™   R°   (    (    (    s?   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/MGWebBrowser.pyRI   t   s"   			 2					t   __main__s   -quitc         C   s   d G|  GHd  S(   Ns   Do something with(    (   R
   (    (    s?   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/MGWebBrowser.pyt   DoSomething:  s    t   win32t   USERPROFILEt   HOMEs   .qwebkit_idbR   t   pdbt   mtzs$   file:///Users/stuart/Qt4.4/test.html(*   t   __doc__Ry   t   PyQt4R    R   R   t   urllib2R   R   R   R7   R    RH   RE   Rˆ   RI   R   t   argvt   exitR   R²   R1   t   appt   platformRd   t   gett   homedirR   Rn   Rc   t	   webkit_dbt   QWebSettingst   setIconDatabasePatht   mkdirt   browserR:   R   R   t   showRq   Ro   t   exec_(    (    (    s?   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/MGWebBrowser.pyt   <module>   sD   @Ã	
