ó
ÉÝ{Tc           @   s   d  Z  d d l m Z d d l Z d e f d     YZ e d k r e   Z d Z d Z e j e  e j   e j	   Z
 x e
 D] Z e GHq Wn  d S(	   sR  
     qtgui/ParseHTMLTextString.py: CCP4MG Molecular Graphics Program
     Copyright (C) 2001-2008 University of York, CCLRC

     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
   HTMLParserNt   MyHTMLParserc           B   sź   e  Z d  Z d Z d Z d Z d Z d Z d Z d Z	 d d	 d
  Z
 d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   i	   i   i   i   i   i   i   i   i   t   ptc         C   s  t  j |   |  j   |  _ |  j   |  _ d |  _ d |  _ | |  _ d |  _ d |  _	 d |  _
 d |  _ d |  _ d |  _ d |  _ d |  _ g  |  _ g  |  _ d  |  _ g  |  _ d |  _ d |  _ d |  _ | |  _ d |  _ d |  _ d |  _ |  j   t |  _ d  S(   Nt   defaulti    t    i˙˙˙˙(   R    t   __init__t   getpost
   lastTagPost   lastDataPost   currentColourt   currentFacet   currentSizet   currentSuperscriptt   currentSubscriptt   currentUnderlinet   currentOverlinet   currentLinethrought   currentBoldt   currentItalict   currentFontt   fontListt	   fontStackt   Nonet   openTagt   dataListt
   dataLengtht   allDatat   currentTextt	   fontUnitst   currentMathMarkupt   currentVAlignt   currentParagrapht   addFontChanget   Falset   ignoring(   t   selft   fontSizeR   (    (    sF   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/ParseHTMLTextString.pyR   !   s6    																						
c         C   s|   |  j  r d  Si  } |  j   | d <|  j j d d  | d <|  j j |  |  j t |  j  |  _ |  j |  j |  _ d  S(   Nt   poss   
R   t   text(	   R"   R   R   t   replaceR   t   appendR   t   lenR   (   R#   t   data(    (    sF   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/ParseHTMLTextString.pyt   addDataChange>   s    	 c         C   sa   |  j    |  _ | d d k r> t t d | d   |  _ n t t |   |  _ |  j   d  S(   Ni    t   xt   0i   (   R   R   t   unichrt   intR   R+   (   R#   t   charref(    (    sF   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/ParseHTMLTextString.pyt   handle_charrefG   s
    c         C   s9   |  j    |  _ t t t j |   |  _ |  j   d  S(   N(   R   R   R.   R/   t   htmlentitydefst   name2codepointR   R+   (   R#   t   entity(    (    sF   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/ParseHTMLTextString.pyt   handle_entityrefO   s    c         C   s&   |  j    |  _ | |  _ |  j   d  S(   N(   R   R   R   R+   (   R#   R*   (    (    sF   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/ParseHTMLTextString.pyt   handle_dataT   s    	c         C   s]  xV| d j  d  D]A} | j   r t |  d k r | j  d  \ } } | j   } | d k rą | d k r~ d |  _ n  | d k r d |  _ n  | d k rą d	 |  _ qą n  | d
 k rç | j   j d d  j d d  |  _ n  | d k r| j   j d d  j d d  |  _ n  | d k rĺ| j   j d d  } | d k rY|  j } n| d k rq|  j	 } nh| d k r|  j
 } nP| d k rĄ|  j } n8| d k rš|  j } n | d k rŃ|  j } n| d k ré|  j } nđ| d k r|  j |  j } nŃ| d k r'|  j |  j } n˛| j d  d k ry/ t t | | j d    d d d  } WqŮ|  j } qŮXnX| j d  d k r×y+ t t | | j d    d d  } WqŮ|  j } qŮXn| j d  d k r#y! d t | | j d    } WqŮ|  j } qŮXnś| j d   d k roy! d! t | | j d     } WqŮ|  j } qŮXnj| j d"  d k rŔy& t | | j d"    } d" |  _ WqŮ|  j } qŮXn| j d#  d k ry t | | j d#    } WqŮ|  j } qŮXnŃ | j d$  d k r]y* t |  j t | | j d$     } WqŮ|  j } qŮXn| | j d%  d k rśy. t |  j t | | j d%    d&  } WqŮ|  j } qŮXn# y t |  } Wn |  j } n X| |  _ n  | d' k r@| d( k s	| d) k rd |  _ n  | d* k r@t |  j d d  |  _ q@n  | d+ k rý| j d,  d- k rmd |  _ n t |  j d d  |  _ | j d.  d- k r§d |  _ n t |  j d d  |  _ | j d/  d- k rád |  _ qýt |  j d d  |  _ n  | d0 k rn  | d1 k rUt |  d2 k r6d |  _ qRt |  j d d  |  _ qUq q Wd  S(3   Ni   t   ;i    t   :s   vertical-alignt   baselinet   subt   superi   t   colort   'R   t   "s   font-familys	   font-sizet    s   xx-smalls   x-smallt   smallt   mediumt   larges   x-larges   xx-larget   largert   smallert   mmgR¸ëQ@i
   iH   t   cmt   int   pci   t   pxR   t   emt   %g      Y@s
   font-stylet   italict   obliquet   normals   text-decorations   line-throughi˙˙˙˙t   overlinet	   underlines   font-variants   font-weightiX  (   t   splitt   isspaceR)   t   stripR   R'   R	   R
   t   font_xx_smallt   font_x_smallt
   font_smallt   font_mediumt
   font_larget   font_x_larget   font_xx_largeR   t   font_css_stept   findR/   t   floatR   R   t   maxR   R   R   R   (   R#   t   attrt   elementt   keypt   valt   keyt   size(    (    sF   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/ParseHTMLTextString.pyt   parse_style_attr_   sĚ       **/+!!*.c         C   s  |  j    |  _ | j   d k r4 |  j d |  _ n  | j   d k rS t |  _ d  S| j   d k rx |  j d |  _ n  | j   d k r |  j d |  _ n  | j   d k rÂ |  j d |  _ n  | j   d k rŕ d |  _	 n  | j   d k rţ d |  _
 n  | j   d	 k rd |  _ n  | j   d
 k rd |  _ x| D]?} t |  d k r>| d j   d k r||  j |  n  | d j   d k r"| d d d k rÇ|  j t | d d  |  _ nH | d d d k rü|  j t | d d  |  _ n t | d  |  _ | d j   } n  | d j   d k rN| d j   |  _ n  | d j   d k r}| d j   |  _ q}q>q>WnL xI | D]A } t |  d k r| d j   d k rĚ|  j |  qĚqqW|  j j |  j t |  j  d  |  j   d  S(   Nt   Pi   t   HEADt   MGMATHt   SUPt   SUBt   Bt   It   Ut   FONTi   i    t   STYLEt   SIZEt   -t   +t   COLORt   FACE(   R   R   t   upperR   t   TrueR"   R   R   R   R   R   R   R   R)   Re   R   R/   t   lowerR	   R
   R   R(   R   R    (   R#   t   tagt   attrsR_   R	   (    (    sF   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/ParseHTMLTextString.pyt   handle_starttagČ   sR    		!! $c         C   sŕ   i  } |  j    | d <|  j | d <|  j | d <|  j | d <|  j | d <|  j | d <|  j | d <|  j | d <|  j | d	 <|  j	 | d
 <|  j
 | d <|  j | d <|  j | d <|  j | d <|  j | d <|  j j |  d  S(   NR%   Rd   t   colourt   faceRP   RO   t   linethrought   boldRL   t	   subscriptt   superscriptt
   mathmarkupR   t   valignt	   paragraph(   R   R   R	   R
   R   R   R   R   R   R   R   R   R   R   R   R   R(   (   R#   t   font(    (    sF   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/ParseHTMLTextString.pyR    ö   s"    c         C   s[  |  j    |  _ | j   d k r. t |  _ d  S| j   d k r\ t |  j d d  |  _ n  | j   d k r t |  j d d  |  _ n  | j   d k r¸ t |  j d d  |  _ n  | j   d k rć t |  j	 d d  |  _	 n  | j   d k rt |  j
 d d  |  _
 n  | j   d	 k rBt |  j d d  |  _ n  | j   d
 k rpt |  j d d  |  _ n  t |  j  d k  r|  j d } n |  j j   } | d |  _ | d |  _ | d |  _ | d |  _ | d |  _ | d |  _ | d |  _	 | d |  _
 | d |  _ | d |  _ | d |  _ | d |  _ | d |  _ |  j   d  S(   NRg   Rh   i   i    Ri   Rj   Rk   Rl   Rm   Rn   Rd   R{   R|   RP   RO   R}   R~   RL   R   R   R   R   R   (   R   R   Ru   R!   R"   R^   R   R   R   R   R   R   R   R)   R   R   t   popR   R	   R
   R   R   R   R   R    (   R#   Rx   R   (    (    sF   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/ParseHTMLTextString.pyt   handle_endtag  sF    	c         C   s   |  j  S(   N(   R   (   R#   (    (    sF   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/ParseHTMLTextString.pyt   getFontChanges6  s    c         C   s   |  j  S(   N(   R   (   R#   (    (    sF   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/ParseHTMLTextString.pyt   getDataLength9  s    c         C   s   |  j  S(   N(   R   (   R#   (    (    sF   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/ParseHTMLTextString.pyt
   getAllData<  s    c         C   s   |  j  S(   N(   R   (   R#   (    (    sF   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/ParseHTMLTextString.pyt   getData?  s    c         C   sń  |  j    } |  j   } g  } | } xt t |  d  D]÷ } | | d d } d } xŤ t t t |   |  D] \ } }	 |	 d }
 |
 d | d k sÉ |
 d | d k r× |
 d | d k r× | | } Pqw | |	 d } | t |  d k rw g  } qw qw Wi  } | | | d <| | d <| j |  q< W|  j d |  j d k s|  j d |  j d k r|  j d |  j d k rg  } n  t |  d k ríxJ | D]? } i  } | t |  d | d <| d | d <| j |  q§Wn  | S(   Ni   R%   R   i    R&   R   (   R   R   t   rangeR)   t   zipR(   R   R   (   R#   t   changesR*   t   fontedStringst	   left_datat   jt   cpost	   this_datat   it   datumR%   t   fontedStringt   lf(    (    sF   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/ParseHTMLTextString.pyt
   getStringsB  s8    )
<

N	(   t   __name__t
   __module__RT   RU   RV   RW   RX   RY   RZ   R[   R   R+   R1   R5   R6   Re   Rz   R    R   R   R   R   R   R   (    (    (    sF   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/ParseHTMLTextString.pyR      s,   						i	.		'				t   __main__sb   hello &lt;&#60;&#x3c; < <br/><font size="+3" color="red">wo<i>r</i>ld</font> <b >&#222;</b>&THORN;s>   /1/J/123(PRO)/CA [1]        (-12.345) The &sigma;&sigma; hello(   t   __doc__R    R2   R   R   t   parserR&   t   feedt   closeR   R   t   fstring(    (    (    sF   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/ParseHTMLTextString.pyt   <module>   s   ˙ S	
