ó
ø`9Sc           @   sM   d  d l  Td  d l Td d g Z d d d „  ƒ  YZ d e f d „  ƒ  YZ d S(   iÿÿÿÿ(   t   *t   DataTableWidgett   TableWidgetColumnc           B   s    e  Z d  Z d e ƒ  d „ Z RS(   s|  Description of a data table widget column.

    Attributes:
      - 'dataAttributeName': attribute of a data record class instance that
        will correspond to the table widget column and hold the data for it, or
        'None' if the column has no data attribute associated with it;
      - 'columnLabel': text displayed in the table widget's column header;
      - 'formatString': string to format the data with '%' operator or either
        'date' or 'time' for date and time values, or 'None' if the column has
        no data attribute associated with it. Note: date and time values must
        have 'year', 'month', 'day' and 'hour', 'minute', 'second' attributes
        respectively to work properly;
      - 'toolTip': string holding the tooltip for the table header.
      - 'icon': 'QIcon' for the table widget's column header or 'None' if
        there's no need for an icon.t    c         C   s1   | |  _  | |  _ | |  _ | |  _ | |  _ d  S(   N(   t   dataAttributeNamet   columnLabelt   formatStringt   toolTipt   icon(   t   selfR   R   R   R   R   (    (    s   code\common\DataTableWidget.pyt   __init__)   s
    				(   t   __name__t
   __module__t   __doc__t   QIconR
   (    (    (    s   code\common\DataTableWidget.pyR      s   c           B   s˜   e  Z d  Z e ƒ  Z 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 d „  Z d „  Z RS(   sA  Table widget intended for display of list of uniform data records.

    Call 'setColumns' to define the structure of the table's header; call
    'populateTable' and 'updateTableRow' to modify the table's data or
    'clearTable' to clear the data.

    By default, table items are not editable, table rows are selected in their
    entirety, and multiple selection is disabled. To modify that, call the
    required 'QTableWidget' methods manually.

    If the widget is manually configured to contain editable items, then the
    following signals will be provided:
      - 'itemEditingStarted': an editor is opened in one of the widget's items.
      - 'itemEditingFinished': the item editor is closed.

    Warning: if several widget items are edited in a row, only the last one
    will trigger the 'itemEditingFinished' signal.c         C   s¦   t  j |  | ƒ |  j t j ƒ |  j t j ƒ |  j t ƒ |  j	 t ƒ |  j
 ƒ  j t ƒ |  j
 ƒ  j t j ƒ |  j ƒ  j t j ƒ |  j ƒ  j ƒ  g  |  _ d  S(   N(   t   QTableWidgetR
   t   setSelectionBehaviort   QAbstractItemViewt
   SelectRowst   setSelectionModet   SingleSelectiont   setTabKeyNavigationt   Falset   setCornerButtonEnabledt   horizontalHeadert   setHighlightSectionst   setResizeModet   QHeaderViewt   Fixedt   verticalHeadert   hidet
   columnList(   R	   t   parent(    (    s   code\common\DataTableWidget.pyR
   K   s    c         C   sÆ   | |  _  g  |  j  D] } | j ^ q } |  j t |  j  ƒ ƒ |  j | ƒ xj t t |  j  ƒ ƒ D]S } |  j | ƒ } | j |  j  | j ƒ | j	 |  j  | j
 ƒ |  j | | ƒ qa W|  j ƒ  d S(   s   Define the table structure by means of the given list of
        'TableWidgetColumn' instances and set the table widget's header.N(   R   R   t   setColumnCountt   lent   setHorizontalHeaderLabelst   ranget   horizontalHeaderItemt
   setToolTipR   t   setIconR   t   setHorizontalHeaderItemt   resizeColumnsToContents(   R	   R   t   columnt   columnLabelst   it
   headerItem(    (    s   code\common\DataTableWidget.pyt
   setColumns[   s    	c         C   s>   x7 t  t |  j ƒ ƒ D]  } |  j | j | k r | Sq Wd S(   sW   Return index of the column that corresponds to the given data record
        attribute.N(   R$   R"   R   R   (   R	   R   R,   (    (    s   code\common\DataTableWidget.pyt   getColumnIndexByAttributeNames   s    c         C   s   |  j  | ƒ } |  j | S(   s`   Return 'TableWidgetColumn' instance that corresponds to the given
        data record attribute.(   R/   R   (   R	   R   t   columnIndex(    (    s   code\common\DataTableWidget.pyt   getColumnByAttributeName{   s    c         C   s•  |  j  t | ƒ ƒ xt t | ƒ ƒ D]ø } | | } xå t t |  j ƒ ƒ D]Î } |  j | | ƒ } | d k rv qL n  t | ƒ } | j t j	 t j
 Bƒ | j t j t j Bƒ |  j | } t | | j ƒ } t | t ƒ sí t | t ƒ r| j t j t j Bƒ n  |  j | | | ƒ qL Wq& W|  j d d ƒ }	 |	 d k	 rP|  j |	 ƒ n  x* t |  j ƒ  ƒ D] }
 |  j |
 d ƒ qcW|  j ƒ  |  j ƒ  d S(   sW  Set table contents in accordance with its structure defined by
        'setColumns' and the given list of uniform data records.

        All the table widget items are enabled and selectable, but not
        editable by default. Different options are supposed to be set via
        manual manipulation of the items after calling this function.i    N(   t   setRowCountR"   R$   R   t   _getItemValueStrt   Nonet   QTableWidgetItemt   setFlagst   Qtt   ItemIsEnabledt   ItemIsSelectablet   setTextAlignmentt
   AlignRightt   AlignVCentert   getattrR   t
   isinstancet   unicodet   strt	   AlignLeftt   setItemt   itemt   scrollToItemt   rowCountt   setRowHeightR)   t   resizeRowsToContents(   R	   t   dataRecordListt   rowIndext
   dataRecordt   colIndext   valueStrt	   tableItemt   tableColumnt   valuet	   firstItemt   row(    (    s   code\common\DataTableWidget.pyt   populateTable‚   s,    

c         C   sä   g  } x‚ t  t |  j ƒ ƒ D]k } |  j | | ƒ } | d k rF q n  |  j | | ƒ } | j ƒ  | k rz | j | ƒ n  | j | ƒ q Wx* t  |  j	 ƒ  ƒ D] } |  j
 | d ƒ qž Wx | D] } |  j | ƒ q¿ W|  j ƒ  d S(   s¯   Set concents of an existing table row in accordance with the given
        data record, without modifying any icons, flags etc. associated with
        the table widget items.i    N(   R$   R"   R   R3   R4   RC   t   textt   appendt   setTextRE   RF   t   resizeColumnToContentsRG   (   R	   RI   RJ   t   modifiedColIndicesRK   RL   RM   RQ   (    (    s   code\common\DataTableWidget.pyt   updateTableRow»   s    c         C   s%   |  j  ƒ  |  j d ƒ |  j ƒ  d S(   s/   Remove all the data, retaining the sole header.i    N(   t   clearContentsR2   R)   (   R	   (    (    s   code\common\DataTableWidget.pyt
   clearTableá   s    
c         C   s=   x6 t  |  j ƒ  ƒ D]" } |  j | | ƒ j t j ƒ q Wd S(   s-   Disable all the table cells in the given row.N(   R$   t   columnCountRC   R6   R7   t   NoItemFlags(   R	   RI   RK   (    (    s   code\common\DataTableWidget.pyt
   disableRowè   s    c         C   sr   t  t d „  |  j ƒ  Dƒ ƒ ƒ } xI | D]A } x8 t |  j ƒ  ƒ D]$ } |  j | | ƒ j ƒ  sB t ‚ qB Wq) W| S(   s;   Return a sorted list of indices of currently selected rows.c         s   s   |  ] } | j  ƒ  Vq d  S(   N(   RQ   (   t   .0RC   (    (    s   code\common\DataTableWidget.pys	   <genexpr>ð   s    (   t   sortedt   sett   selectedItemsR$   R[   RC   t
   isSelectedt   AssertionError(   R	   t   selectedRowsRI   RK   (    (    s   code\common\DataTableWidget.pyt   getSelectedRowsí   s
    "&c         C   sF   |  j  ƒ  } t | ƒ d k s$ t ‚ t | ƒ d k r: d S| d Sd S(   s}   Return index of the currently selected row or 'None' if no row is
        selected. Fail if there are multiple rows selected.i   i    N(   Re   R"   Rc   R4   (   R	   Rd   (    (    s   code\common\DataTableWidget.pyt   getSelectedRowù   s
    c         C   sA   t  j |  | | | ƒ } |  j ƒ  t j k r= |  j j ƒ  n  | S(   sX   Redefinition of a virtual function implementing the
        'itemEditingStarted' signal.(   R   t   editt   stateR   t   EditingStatet   itemEditingStartedt   emit(   R	   t
   modelIndext   editTriggert   eventt   editingStarted(    (    s   code\common\DataTableWidget.pyRg     s
    c         C   s<   t  j |  | | ƒ |  j ƒ  t j k r8 |  j j ƒ  n  d S(   sY   Redefinition of a virtual function implementing the
        'itemEditingFinished' signal.N(   R   t   closeEditorRh   R   Ri   t   itemEditingFinishedRk   (   R	   t   editorWidgett   endEditHint(    (    s   code\common\DataTableWidget.pyRp     s    	c         C   s‰   |  j  | } | j d k r  d St | | j ƒ } | d k rB d S| j d k r^ | j d ƒ S| j d k rz | j d ƒ S| j | Sd S(   s·   Return the textual representation of a 'dataRecord's attribute
        associated with the given table column or 'None' if the column has no
        data attribute associated with it.R   t   dates   %Y-%m-%dt   times   %H:%MN(   R   R   R4   R=   R   t   strftime(   R	   RJ   RK   RN   RO   (    (    s   code\common\DataTableWidget.pyR3   &  s    N(   R   R   R   t
   pyqtSignalRj   Rq   R4   R
   R.   R/   R1   RR   RX   RZ   R]   Re   Rf   Rg   Rp   R3   (    (    (    s   code\common\DataTableWidget.pyR   3   s    						9	&						N(    (   t   PyQt4.QtCoret   PyQt4.QtGuit   __all__R   R   R   (    (    (    s   code\common\DataTableWidget.pyt   <module>   s   

