ó
ø`9Sc           @   s   d  d l  Td  d l Td  d l m Z d  d l m Z d  d l Td  d l Td d g Z d d	 d „  ƒ  YZ d e	 f d „  ƒ  YZ
 d S(
   iÿÿÿÿ(   t   *(   t   gui(   t   txtt   ParamsDialogt   ParameterGroupInfoc           B   s   e  Z d  Z e d „ Z RS(   sŽ  Description of appearance of a group of parameters of a
    'ParamsCollection' instance in a settings dialog box.

    Attributes:
      - 'groupName': INI file group name (the same value as that specified in
        the respective 'ParameterInfo' instances describing the parameters).
      - 'groupBoxCaption': caption of the group box to hold the parameter edit
        widgets in a dialog box.
      - 'startsNewColumn': 'True' if this group box should be placed in a new
        column with respect to the previous one. Group boxes (corresponding to
        the INI file parameters groups) are arranged into columns in settings
        dialog boxes.c         C   s   | |  _  | |  _ | |  _ d  S(   N(   t	   groupNamet   groupBoxCaptiont   startsNewColumn(   t   selfR   R   R   (    (    s   code\common\ParamsDialog.pyt   __init__,   s    		(   t   __name__t
   __module__t   __doc__t   FalseR	   (    (    (    s   code\common\ParamsDialog.pyR      s   c           B   s°   e  Z d  Z d „  Z e d „  ƒ Z e d „  ƒ Z e 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(   s  Base class for dialogs intended for interactive modification of
    'ParamsCollection' instances.

    Redefine 'getGroupInfoList' method to specify which INI file groups should
    be represented in the dialog. Redefine 'updateCustomErrorMessages' to
    implement any constraint checking procedures that involve several parameter
    values at once (and hence may not be implemented at the level of a single
    editing widget). Redefine 'updateEditEnableStatus' to restrict availability
    of certain edit controls under certain circumstances. Redefine
    'checkSavePossibility' to perform some additional checkings when the 'Save'
    button is pressed, if required.

    Use 'getValue' to access current values of the parameters being edited, and
    'setErrorMessage' to inform the user of problems with these additional
    constraints. Use 'setEnabled' to dynamically alter availability to the user
    of edit controls associated with certain parameters.

    Pass an instance of a class derived from 'ParamsCollection' to the
    constructor, then run the dialog with 'exec_'. When (and only if) the user
    presses the 'Save' button (and 'checkSavePossibility' returns 'True'), the
    passed parameters instance is modified, and its 'saveToFile' method is
    invoked.c         C   s×  t  j |  | ƒ t | t ƒ s% t ‚ | |  _ i  |  _ t ƒ  } t ƒ  } xb |  j	 ƒ  D]T } | j
 r‹ | j ƒ  | j | d ƒ t ƒ  } n  | j |  j | j | j ƒ ƒ qV W| j ƒ  t |  j ƒ  ƒ |  _ |  j j t ƒ |  j j j |  j ƒ t d ƒ |  _ |  j j t ƒ |  j j j |  j ƒ t ƒ  } | j ƒ  | j |  j ƒ | j |  j ƒ | j | ƒ | j | d ƒ |  j | ƒ |  j |  j ƒ  ƒ |  j t j  d ƒ ƒ |  j! |  j" ƒ  t# j$ @ƒ |  j% ƒ  d  S(   Ni   t   Cancelt
   parameters(&   t   QDialogR	   t
   isinstancet   ParamsCollectiont   AssertionErrort   paramst   editWidgetst   QHBoxLayoutt   QVBoxLayoutt   getGroupInfoListR   t
   addStretcht	   addLayoutt	   addWidgett   createParameterGroupBoxR   R   t   QPushButtont   getSaveButtonNamet
   saveButtont   setAutoDefaultR   t   clickedt   connectt   onSaveButtonClickedt   cancelButtont   onCancelButtonClickedt	   setLayoutt   setWindowTitlet   getWindowTitlet   setWindowIconR   t   loadIcont   setWindowFlagst   windowFlagst   Qtt   WindowContextHelpButtonHintt   onValueChanged(   R   t   parentR   t   layoutt   lastColumnLayoutt   groupt   buttonBoxLayout(    (    s   code\common\ParamsDialog.pyR	   L   s@    					

	
c         C   s   g  S(   s¸   Return a list of 'ParameterGroupInfo' instances enumerating
        parameter groups that have to be present in the dialog box, along with
        the corresponding group box captions.(    (   t   cls(    (    s   code\common\ParamsDialog.pyR      s    c         C   s   d S(   s1   Return a string to be used as the dialog's title.t
   Parameters(    (   R5   (    (    s   code\common\ParamsDialog.pyR(   ˜   s    c         C   s   d S(   s3   Return a string to be displayed on the save button.s   &Save(    (   R5   (    (    s   code\common\ParamsDialog.pyR      s    c         C   s   d  S(   N(    (   R   (    (    s   code\common\ParamsDialog.pyt   updateCustomErrorMessages¢   s    c         C   s   d  S(   N(    (   R   (    (    s   code\common\ParamsDialog.pyt   updateEditEnableStatus¥   s    c         C   s   t  S(   N(   t   True(   R   (    (    s   code\common\ParamsDialog.pyt   checkSavePossibility¨   s    c         C   s   |  j  | j ƒ  S(   sÄ   Return the current value (as displayed in the corresponding edit
        widget) for a parameter with the given attribute name or 'None' if the
        value does not meet some of the constraints.(   R   t   getValue(   R   t   attributeName(    (    s   code\common\ParamsDialog.pyR;   ¬   s    c         C   s8   | d k	 r# |  j | j | ƒ n |  j | j ƒ  d S(   s¶   Set or clear custom error message for a parameter with the given
        attribute name.

        'message' has to be a string to set the error message or 'None' to
        clear it.N(   t   NoneR   t   setCustomErrorMessaget   clearCustomErrorMessage(   R   R<   t   message(    (    s   code\common\ParamsDialog.pyt   setErrorMessage³   s    c         C   s   |  j  | j | ƒ d S(   s\   Enable or disable interactive editing for a parameter with the given
        attribute name.N(   R   t
   setEnabled(   R   R<   t	   isEnabled(    (    s   code\common\ParamsDialog.pyRB   ¿   s    c   	   
   C   s©  t  | ƒ } t ƒ  } x€|  j j ƒ  D]o} | j | k r@ q% n  | j ƒ  } t | t ƒ r– t | j	 ƒ } | j
 t j ƒ | j | | d d d ƒ q% t | t ƒ rˆ|  j | ƒ } | j	 d k	 r*| j t k	 r*t | j	 ƒ } | j
 t j ƒ | j t j ƒ | j | | d ƒ | j | | d ƒ n | j | | d d d ƒ t j | ƒ ! | j t |  j | j ƒ ƒ Wd QX| |  j | j <q% t s% t ‚ q% W| j | ƒ | S(   s8  Create and return a group box widget holding edit fields for a
        parameter group of the given name. Initialize edit fields with values
        stored in 'self.params', connect all the required slots associated with
        them and save references to the created edit widgets in
        'self.editWidgets'.i    i   i   N(   t	   QGroupBoxt   QGridLayoutR   t   getParameterListR   t   rowCountR   t   ParameterHeadert   QLabelt   dialogLabelt   setTextFormatR-   t   RichTextR   t   ParameterInfot   createEditWidgetR=   t   dataTypet   boolt   setAlignmentt
   AlignRightR   t   SignalBlockert   setValuet   getattrR<   R   R   R   R&   (	   R   R   R   t   groupBoxt   groupBoxLayoutt   paramt
   currentRowt   labelt
   editWidget(    (    s   code\common\ParamsDialog.pyR   Æ   s6    	c      	   C   s  | j  d k	 rE | j t k s3 | j t k s3 t ‚ t | j  ƒ } nœ | j t k sc | j t k r– t	 | j
 | j | j | j d | j t k ƒ} nK | j t k r· t | j ƒ } n* | j t k sÌ t ‚ t | j | j ƒ } | j j |  j ƒ | j j |  j ƒ | S(   sŠ   Create and return and 'EditWidget' instance suitable for editing of
        a parameter described with the given 'ParameterInfo' instance.t   isFloatingPointN(   t   admissibleValuesR=   RO   t   strt   unicodeR   t   ComboBoxEditWidgett   floatt   intt   NumberEditWidgett   minValuet   maxValuet   isMinStrictt   isMaxStrictRP   t   BoolEditWidgetRJ   t   StringEditWidgett	   minLengtht	   maxLengtht   valueChangedR"   R/   t   returnPressedt   onReturnPressed(   R   t	   paramInfoR[   (    (    s   code\common\ParamsDialog.pyRN      s     $c         C   sÆ   x4 |  j  D]) } |  j  | j ƒ  j ƒ  r
 | } Pq
 q
 W|  j j | ƒ j } |  j j | ƒ } xJ t t | ƒ d ƒ D]( } | | | k ru | | d } Pqu qu W| d } |  j  | j ƒ  j	 ƒ  d S(   sš   Pass focus to the edit control below the current one in the current
        parameter group, looping to the group's first parameter in the
        bottom.i   i    N(
   R   t   getEditWidgett   hasFocusR   t   getParameterInfoByNameR   t   getAttributeNamest   ranget   lent   setFocus(   R   R<   t   curParamNameR   t   groupParamNamest   it   nextParamName(    (    s   code\common\ParamsDialog.pyRn   %  s    
c            se   x! ˆ  j  D] } ˆ  j | d ƒ q
 Wˆ  j ƒ  ˆ  j ƒ  ˆ  j j t ‡  f d †  ˆ  j  Dƒ ƒ ƒ d S(   s.   Update button state and custom error messages.c         3   s"   |  ] } ˆ  j  | j ƒ  Vq d  S(   N(   R   t   hasValue(   t   .0R<   (   R   (    s   code\common\ParamsDialog.pys	   <genexpr>K  s   N(   R   RA   R=   R7   R8   R   RB   t   all(   R   R<   (    (   R   s   code\common\ParamsDialog.pyR/   ?  s    

c         C   s_   |  j  ƒ  s d Sx1 |  j D]& } t |  j | |  j | j ƒ  ƒ q W|  j j ƒ  |  j ƒ  d S(   s   Save changes to the INI file, update the 'self.params' instance and
        close the dialog box, unless 'self.checkSavePossibility' returns
        'False'.N(   R:   R   t   setattrR   R;   t
   saveToFilet   accept(   R   R<   (    (    s   code\common\ParamsDialog.pyR#   N  s    c         C   s   |  j  ƒ  d  S(   N(   t   reject(   R   (    (    s   code\common\ParamsDialog.pyR%   ^  s    (   R
   R   R   R	   t   classmethodR   R(   R   R7   R8   R:   R;   RA   RB   R   RN   Rn   R/   R#   R%   (    (    (    s   code\common\ParamsDialog.pyR   3   s"   	D							:	%			N(    (   t   PyQt4.QtCoret   PyQt4.QtGuit   common.utilsR   R   t   common.EditWidgetst   common.ParamsCollectiont   __all__R   R   R   (    (    (    s   code\common\ParamsDialog.pyt   <module>   s   



