o
    e~#g                     @  s   d Z ddlmZ ddlmZmZ ddlmZmZ ddl	m
Z
 ddlmZmZ ddlmZ ddlmZ er:dd	lmZ e
 G d
d deZdS )zgr.Number() component.    )annotations)CallableSequence)TYPE_CHECKINGAny)document)	ComponentFormComponent)Events)Error)Timerc                      s   e Zd ZdZejejejejgZ		d;dddddddddddddddddddd< fd&d'Z
ed=d+d,Zd>d/d0Zd?d1d2Zd@d4d5ZdAd7d8ZdAd9d:Z  ZS )BNumberz
    Creates a numeric field for user to enter numbers as input or display numeric output.

    Demos: tax_calculator, blocks_simple_squares
    NT      )labelinfoeveryinputs
show_label	containerscale	min_widthinteractivevisibleelem_idelem_classesrenderkey	precisionminimummaximumstepvaluefloat | Callable | Noner   
str | Noner   r   Timer | float | Noner   7Component | Sequence[Component] | set[Component] | Noner   bool | Noner   boolr   
int | Noner   intr   r   r   r   list[str] | str | Noner   r   int | str | Noner   r   float | Noner    r!   floatc                  sF   || _ || _|| _|| _t j||||||||	|
||||||d dS )a  
        Parameters:
            value: default value. If callable, the function will be called whenever the app loads to set the initial value of the component.
            label: the label for this component, displayed above the component if `show_label` is `True` and is also used as the header if there are a table of examples for this component. If None and used in a `gr.Interface`, the label will be the name of the parameter this component corresponds to.
            info: additional component description, appears below the label in smaller font. Supports markdown / HTML syntax.
            every: Continously calls `value` to recalculate it if `value` is a function (has no effect otherwise). Can provide a Timer whose tick resets `value`, or a float that provides the regular interval for the reset Timer.
            inputs: Components that are used as inputs to calculate `value` if `value` is a function (has no effect otherwise). `value` is recalculated any time the inputs change.
            show_label: if True, will display label.
            container: If True, will place the component in a container - providing some extra padding around the border.
            scale: relative size compared to adjacent Components. For example if Components A and B are in a Row, and A has scale=2, and B has scale=1, A will be twice as wide as B. Should be an integer. scale applies in Rows, and to top-level Components in Blocks where fill_height=True.
            min_width: minimum pixel width, will wrap if not sufficient screen space to satisfy this value. If a certain scale value results in this Component being narrower than min_width, the min_width parameter will be respected first.
            interactive: if True, will be editable; if False, editing will be disabled. If not provided, this is inferred based on whether the component is used as an input or output.
            visible: If False, component will be hidden.
            elem_id: An optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles.
            elem_classes: An optional list of strings that are assigned as the classes of this component in the HTML DOM. Can be used for targeting CSS styles.
            render: If False, component will not render be rendered in the Blocks context. Should be used if the intention is to assign event listeners now but render the component later.
            key: if assigned, will be used to assume identity across a re-render. Components that have the same key across a re-render will have their value preserved.
            precision: Precision to round input/output to. If set to 0, will round to nearest integer and convert type to int. If None, no rounding happens.
            minimum: Minimum value. Only applied when component is used as an input. If a user provides a smaller value, a gr.Error exception is raised by the backend.
            maximum: Maximum value. Only applied when component is used as an input. If a user provides a larger value, a gr.Error exception is raised by the backend.
            step: The interval between allowed numbers in the component. Can be used along with optional parameters `minimum` and `maximum` to create a range of legal values starting from `minimum` and incrementing according to this parameter.
        )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r"   N)r   r   r    r!   super__init__)selfr"   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   	__class__ }/var/www/static.ux5.de/https/Moving-Object-Detection-with-OpenCV/env/lib/python3.10/site-packages/gradio/components/number.pyr0      s*   -
zNumber.__init__numfloat | intreturnc                 C  s,   |du r| S |dkrt t| |S t| |S )a=  
        Round to a given precision.

        If precision is None, no rounding happens. If 0, num is converted to int.

        Parameters:
            num: Number to round.
            precision: Precision to round to.
        Returns:
            rounded number or the original number if precision is None
        Nr   )r*   round)r6   r   r4   r4   r5   _round_to_precision`   s
   
zNumber._round_to_precisionpayloadfloat | int | Nonec                 C  sr   |du rdS | j dur|| j k rtd| d| j  d| jdur2|| jkr2td| d| j d| || jS )z
        Parameters:
            payload: the field value.
        Returns:
            Passes field value as a `float` or `int` into the function, depending on `precision`.
        NzValue z is less than minimum value .z is greater than maximum value )r   r   r    r:   r   )r1   r;   r4   r4   r5   
preprocesst   s   zNumber.preprocessc                 C  s   |du rdS |  || jS )z
        Parameters:
            value: Expects an `int` or `float` returned from the function and sets field value to it.
        Returns:
            The (optionally rounded) field value as a `float` or `int` depending on `precision`.
        N)r:   r   )r1   r"   r4   r4   r5   postprocess   s   zNumber.postprocessdict[str, str]c                 C  s   ddiS )Ntypenumberr4   r1   r4   r4   r5   api_info   s   zNumber.api_infor   c                 C     dS N   r4   rC   r4   r4   r5   example_payload      zNumber.example_payloadc                 C  rE   rF   r4   rC   r4   r4   r5   example_value   rI   zNumber.example_value)N)&r"   r#   r   r$   r   r$   r   r%   r   r&   r   r'   r   r(   r   r)   r   r*   r   r'   r   r(   r   r$   r   r+   r   r(   r   r,   r   r)   r   r-   r    r-   r!   r.   )r6   r7   r   r)   r8   r7   )r;   r-   r8   r<   )r"   r<   r8   r<   )r8   r@   )r8   r   )__name__
__module____qualname____doc__r
   changeinputsubmitfocusEVENTSr0   staticmethodr:   r>   r?   rD   rH   rJ   __classcell__r4   r4   r2   r5   r      s>    D



r   N)rN   
__future__r   collections.abcr   r   typingr   r   gradio_client.documentationr   gradio.components.baser   r	   gradio.eventsr
   gradio.exceptionsr   gradio.componentsr   r   r4   r4   r4   r5   <module>   s    