ó
3L—Nc           @   sÒ   y d  d l  m Z m Z Wn d  d l m Z m Z n Xd  d l Z d  d l m Z d  d l Z d e j f d „  ƒ  YZ	 d d „ Z e d k rÎ d  d l Z e j e j ƒ Z e j d ƒ Z e e ƒ GHn  d S(	   iÿÿÿÿ(   t   QtCoret   QtGuiN(   t   relationt   creatorFormc           B   sn   e  Z d d  „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d	 „  Z d
 „  Z RS(   c         C   s3   t  j j |  ƒ |  j t ƒ d  |  _ | |  _ d  S(   N(   R   t   QDialogt   __init__t   setSizeGripEnabledt   Truet   Nonet   result_relationt   rel(   t   selfR
   (    (    s=   /home/salvo/dev/relational/trunk/relational_pyside/creator.pyR      s    	c         C   sH   | |  _  |  j  j |  _ |  j d  k r4 |  j ƒ  n |  j |  j ƒ d  S(   N(   t   uit   tableR
   R   t   setup_emptyt   setup_relation(   R   R   (    (    s=   /home/salvo/dev/relational/trunk/relational_pyside/creator.pyt   setUi%   s
    	c         C   s
  |  j  j d ƒ xi | j j D][ } t j ƒ  } | j | ƒ |  j  j |  j  j ƒ  ƒ |  j  j	 d |  j  j ƒ  d | ƒ q Wx‡ | j
 D]| } |  j  j |  j  j ƒ  ƒ xZ t t | ƒ ƒ D]F } t j ƒ  } | j | | ƒ |  j  j	 |  j  j ƒ  d | | ƒ q¸ Wq† Wd  S(   Ni    i   (   R   t	   insertRowt   headert
   attributesR   t   QTableWidgetItemt   setTextt   insertColumnt   columnCountt   setItemt   contentt   rowCountt   ranget   len(   R   R
   t   it   itemt   j(    (    s=   /home/salvo/dev/relational/trunk/relational_pyside/creator.pyR   -   s    '+c         C   s   |  j  j d ƒ |  j  j d ƒ |  j  j d ƒ |  j  j d ƒ t j ƒ  } t j ƒ  } t j ƒ  } t j ƒ  } | j d ƒ | j d ƒ | j d ƒ | j d ƒ |  j  j d d | ƒ |  j  j d d | ƒ |  j  j d d | ƒ |  j  j d d | ƒ d  S(   Ni    s   Field name 1s   Field name 2s   Value 1s   Value 2i   (   R   R   R   R   R   R   R   (   R   t   i00t   i01t   i10t   i11(    (    s=   /home/salvo/dev/relational/trunk/relational_pyside/creator.pyR   ?   s     c         C   s·  g  } xH t  |  j j ƒ  ƒ D]1 } | j t j |  j j d | ƒ j ƒ  ƒ ƒ q Wy t j	 | ƒ } WnX t
 k
 r¾ } t j j d  t j j d d ƒ d t j j d d ƒ | j ƒ  f ƒ d  SXt j ƒ  } | | _	 xÜ t  d |  j j ƒ  ƒ D]Â } g  } x t  |  j j ƒ  ƒ D]† } y/ | j t j |  j j | | ƒ j ƒ  ƒ ƒ Wqt j j d  t j j d d ƒ t j j d d | d | d f ƒ ƒ d  SXqW| j j t | ƒ ƒ qí W| S(   Ni    t   Formt   Errors   %s
%ss   Header error!i   s   Unset value in %d,%d!(   R   R   R   t   appendt   compatibilityt
   get_py_strR   t   textR   R   t	   ExceptionR   t   QMessageBoxt   informationR   t   QApplicationt	   translatet   __str__R   R   t   addt   tuple(   R   t   hlistR   R   t   et   rR   (    (    s=   /home/salvo/dev/relational/trunk/relational_pyside/creator.pyt   create_relationR   s(    /D	/F	c         C   s5   |  j  ƒ  |  _ |  j d  k r1 t j j |  ƒ n  d  S(   N(   R5   R	   R   R   R   t   accept(   R   (    (    s=   /home/salvo/dev/relational/trunk/relational_pyside/creator.pyR6   j   s    c         C   s   d  |  _ t j j |  ƒ d  S(   N(   R   R	   R   R   t   reject(   R   (    (    s=   /home/salvo/dev/relational/trunk/relational_pyside/creator.pyR7   r   s    	c         C   s   |  j  j |  j  j ƒ  ƒ d  S(   N(   R   R   R   (   R   (    (    s=   /home/salvo/dev/relational/trunk/relational_pyside/creator.pyt	   addColumnv   s    c         C   s   |  j  j d ƒ d  S(   Ni   (   R   R   (   R   (    (    s=   /home/salvo/dev/relational/trunk/relational_pyside/creator.pyt   addRowy   s    c         C   s5   |  j  j ƒ  d k r1 |  j  j |  j  j ƒ  ƒ n  d  S(   Ni   (   R   R   t   removeColumnt   currentColumn(   R   (    (    s=   /home/salvo/dev/relational/trunk/relational_pyside/creator.pyt   deleteColumn|   s    c         C   s5   |  j  j ƒ  d k r1 |  j  j |  j  j ƒ  ƒ n  d  S(   Ni   (   R   R   t	   removeRowt
   currentRow(   R   (    (    s=   /home/salvo/dev/relational/trunk/relational_pyside/creator.pyt	   deleteRow€   s    N(   t   __name__t
   __module__R   R   R   R   R   R5   R6   R7   R8   R9   R<   R?   (    (    (    s=   /home/salvo/dev/relational/trunk/relational_pyside/creator.pyR      s   									c         C   sC   t  j ƒ  } t |  ƒ } | j | ƒ | j | ƒ | j ƒ  | j S(   sŽ   Opens the editor for the given relation and returns a _new_ relation
    containing the new relation.
    If the user cancels, it returns None(   t   rel_editt	   Ui_DialogR   t   setupUiR   t   exec_R	   (   R
   R   R$   (    (    s=   /home/salvo/dev/relational/trunk/relational_pyside/creator.pyt   edit_relation†   s    
t   __main__s3   /home/salvo/dev/relational/trunk/samples/people.csv(   t   PyQt4R    R   t   PySideR'   t
   relationalR   RB   R   R   R   RF   R@   t   sysR-   t   argvt   appR4   (    (    (    s=   /home/salvo/dev/relational/trunk/relational_pyside/creator.pyt   <module>   s   h