ó
ø`9Sc           @   sf   d  d l  Td  d l m Z d d d g Z d d
 d „  ƒ  YZ d d d „  ƒ  YZ d d d „  ƒ  YZ d	 S(   iÿÿÿÿ(   t   *(   t   utilst   ParamsCollectiont   ParameterInfot   ParameterHeaderc           B   s>   e  Z d  Z d d d e e d d d „ Z d „  Z d „  Z RS(   sô  Description of a parameter to be stored in an INI file and possibly
    edited via a dialog box.

    Attributes:
      - 'groupName': INI file group name for the parameter (an ASCII string).
      - 'dialogLabel': label to denote the parameter in a settings dialog
        box, or 'None' if there should be no label for this parameter.
      - 'attributeName': name of the attribute of a parameters collection
        class instance to store the data in. This same string will be used as
        the parameter's name in the INI file.
      - 'dataType': Python datatype of the attribute that will hold the data:
        'int', 'float', 'bool', 'str' or 'unicode'.
      - 'defaultValue': parameter's default value (may be 'None').
      - 'admissibleValues': a complete sequence of allowable parameter values
        or 'None' if the set of values is not fixed.
      - 'minValue', 'maxValue': minimum and maximum values for numeric data
        types or 'None' for boundaries that are not defined.
      - 'isMinStrict', 'isMaxStrict': 'True' if the respective boundary values
        themselves are not acceptable.
      - 'minLength', 'maxLength': minimum and maximum lengths for 'str' and
        'unicode' data types or 'None' if string length is not restricted.c            sß  t  | t ƒ r! t | ƒ d k s' t ‚ t  | t ƒ rH t | ƒ d k sN t ‚ | d  k so t  | ˆ  ƒ so t ‚ | d  k s t ‡  f d †  | Dƒ ƒ s t ‚ | d  k sÇ | d  k sÇ | | k  sÇ t ‚ | d  k sè t  | ˆ  ƒ sè t ‚ | d  k s	t  | ˆ  ƒ s	t ‚ | d  k s'| d k s't ‚ | d  k sE| d k sEt ‚ | d  k so| d  k so| | k sot ‚ | |  _ | |  _ | |  _ ˆ  |  _	 | |  _
 | |  _ | |  _ | |  _ |	 |  _ |
 |  _ | |  _ | |  _ d  S(   Ni    c         3   s   |  ] } t  | ˆ  ƒ Vq d  S(   N(   t
   isinstance(   t   .0t   item(   t   dataType(    s   code\common\ParamsCollection.pys	   <genexpr>;   s   (   R   t   strt   lent   AssertionErrort   Nonet   allt	   groupNamet   dialogLabelt   attributeNameR   t   defaultValuet   admissibleValuest   minValuet   maxValuet   isMinStrictt   isMaxStrictt	   minLengtht	   maxLength(   t   selfR   R   R   R   R   R   R   R   R   R   R   R   (    (   R   s   code\common\ParamsCollection.pyt   __init__0   s.    ''!*!!*											c         C   s3   t  j | |  j ƒ  | j |  j | ƒ Wd QXd S(   sŠ   Save a parameter specified by 'value' in the given 'QSettings'
        instance in an appropriate way as specified by the 'self' instance.N(   R   t   SettingsGrouperR   t   setValueR   (   R   t   settingst   value(    (    s   code\common\ParamsCollection.pyt   saveToSettingsQ   s    c      
   C   sZ  t  j | |  j ƒ 0 | j |  j ƒ s/ |  j S| j |  j ƒ } Wd QX|  j t k rk | j	 ƒ  \ } } nÌ |  j t
 k r | j ƒ  \ } } n¨ |  j t k r³ | j ƒ  } t } n„ |  j t k rÝ t | j ƒ  ƒ } t } nZ |  j t k r%y t | j ƒ  ƒ } Wn t k
 rt } q7Xt } n t s7t d ƒ ‚ | rE|  j d k	 rd| |  j k rdt } n  |  j d k	 r¦| |  j k  sš|  j r¦| |  j k r¦t } q¦n  |  j d k	 rè| |  j k sÜ|  j rè| |  j k rèt } qèn  |  j d k	 rt | ƒ |  j k  rt } n  |  j d k	 rEt | ƒ |  j k rEt } qEn  | rO| S|  j Sd S(   sû   Load a parameter from the given 'QSettings' instance and return its
        value converted to the required data type.

        If the value is missing from the 'QSettings' instance or does not meet
        the constraints, return 'self.defaultValue'.Ns   The data type is not supported(   R   R   R   t   containsR   R   R   R   t   floatt   toDoublet   intt   toIntt   boolt   toBoolt   Truet   unicodet   toStringR	   t   UnicodeEncodeErrort   FalseR   R   R   R   R   R   R   R   R
   R   (   R   R   t   variantValueR   t   conversionResult(    (    s   code\common\ParamsCollection.pyt   loadFromSettingsX   sP    		
		$	$N(   t   __name__t
   __module__t   __doc__R   R+   R   R   R.   (    (    (    s   code\common\ParamsCollection.pyR      s   	c           B   s   e  Z d  Z d „  Z RS(   s.  Description of a settings dialog box header to be used to denote a
    subgroup of parameters within a group of the given name.

    Attributes:
      - 'groupName': INI file group name (an ASCII string).
      - 'dialogLabel': label to denote a subgroup of parameters in a settings
        dialog box.c         C   sO   t  | t ƒ r! t | ƒ d k s' t ‚ | d  k	 s9 t ‚ | |  _ | |  _ d  S(   Ni    (   R   R	   R
   R   R   R   R   (   R   R   R   (    (    s   code\common\ParamsCollection.pyR   ¡   s    '	(   R/   R0   R1   R   (    (    (    s   code\common\ParamsCollection.pyR   ˜   s   c           B   s€   e  Z d  Z e d „  ƒ Z e d „  ƒ Z d „  Z d „  Z d „  Z e d
 d „ ƒ Z
 e d „  ƒ Z d „  Z e d	 „  ƒ Z RS(   så  Base class for parameter collections to be stored in text INI files and
    possibly edited via a dialog box.

    Redefine 'getParameterList' virtual method to specify the list of the
    parameters along with constraints that may apply. Specify the name of the
    INI file to hold the data by redefining 'getSettingsFilePath', and then use
    'saveToFile' and 'loadFromFile' methods for persistent data storage.

    Use ordinary attributes of the derived class to access the data.c         C   s   g  S(   s­  Return an ordered list of 'ParameterInfo' instances (possibly
        intervened by a number of 'ParameterHeader's) describing properties of
        the parameters (to be stored as attributes in instances of the derived
        class), as well as their appearance and order in a settings dialog box.

        In a dialog box, as well as in an INI file, parameters will be grouped
        according to 'groupName's specified in 'ParameterInfo's and
        'ParameterHeader's (so that parameters with a common 'groupName' are
        displayed side by side). Within a group, parameter order is determined
        by the order of elements in the list returned by this function. In the
        dialog box, each parameter may be denoted with a separate label, as
        specified by 'ParameterInfo.dialogLabel'. By means of introducing
        intervening 'ParameterHeader' instances into the list, it's also
        possible to insert informative labels between consecutive parameter
        fields in the dialog box. Otherwise, 'ParameterHeader' elements of the
        list will be ignored.

        Use 'ParamsDialog' to interactively edit attributes of the derived
        class in a dialog box.(    (   t   cls(    (    s   code\common\ParamsCollection.pyt   getParameterList¸   s    c         C   s   d S(   sK   Return INI file path to be used by 'saveToFile' and
        'loadFromFile'.N(   R   (   R2   (    (    s   code\common\ParamsCollection.pyt   getSettingsFilePathÐ   s    c         C   s   |  j  ƒ  d S(   s)   Construct an all-default params instance.N(   t   reset(   R   (    (    s   code\common\ParamsCollection.pyR   Ø   s    c         C   sC   x< |  j  ƒ  D]. } t | t ƒ r t |  | j | j ƒ q q Wd S(   s+   Set the parameters to their default values.N(   R3   R   R   t   setattrR   R   (   R   t   param(    (    s   code\common\ParamsCollection.pyR5   Ý   s    c         C   s@   |  j  ƒ  } x- |  j ƒ  D] } t | | t |  | ƒ ƒ q W| S(   s<   Return a new instance of this class holding the same values.(   t	   __class__t   getAttributeNamesR6   t   getattr(   R   t   copyR   (    (    s   code\common\ParamsCollection.pyR;   ä   s    c         C   sa   g  } xT |  j  ƒ  D]F } t | t ƒ r | d k sC | j | k rY | j | j ƒ qY q q W| S(   sQ  Return the list of class instance attribute names that belong to the
        specified INI file group, or the complete list of class instance
        attributes if 'groupName' is 'None'.

        Order of the returned attribute names will correspond to the required
        parameter sequence in a dialog box (as well as in an INI file).N(   R3   R   R   R   R   t   appendR   (   R2   R   t   attributeNamesR7   (    (    s   code\common\ParamsCollection.pyR9   î   s    	c         C   s@   x9 |  j  ƒ  D]+ } t | t ƒ r | j | k r8 | Sq q Wd S(   s_   Return 'ParameterInfo' instance that corresponds to the given class
        instance attribute.N(   R3   R   R   R   (   R2   R   R7   (    (    s   code\common\ParamsCollection.pyt   getParameterInfoByName   s    c         C   sg   t  |  j ƒ  t  j ƒ } xH |  j ƒ  D]: } t | t ƒ r% t |  | j ƒ } | j | | ƒ q% q% Wd S(   sf   Save the current settings in a text file located at the path defined
        by 'getSettingsFilePath'.N(	   t	   QSettingsR4   t	   IniFormatR3   R   R   R:   R   R   (   R   R   R7   t
   paramValue(    (    s   code\common\ParamsCollection.pyt
   saveToFile
  s
    c         C   sp   t  |  j ƒ  t  j ƒ } |  ƒ  } xH |  j ƒ  D]: } t | t ƒ r. | j | ƒ } t | | j | ƒ q. q. W| S(   s³   Return params instance loaded from a text file located at the path
        defined by 'getSettingsFilePath'.

        Invalid or absent values, if any, are replaced with defaults.(	   R?   R4   R@   R3   R   R   R.   R6   R   (   R2   R   t   paramsR7   R   (    (    s   code\common\ParamsCollection.pyt   loadFromFile  s    	N(   R/   R0   R1   t   classmethodR3   R4   R   R5   R;   R   R9   R>   RB   RD   (    (    (    s   code\common\ParamsCollection.pyR   ¬   s   				

	N(    (    (    (   t   PyQt4.QtCoret   common.utilsR   t   __all__R   R   R   (    (    (    s   code\common\ParamsCollection.pyt   <module>   s
   
