> For the complete documentation index, see [llms.txt](https://docs.augelab.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.augelab.com/french/key-features/create-plugins-with-designer-window/components.md).

# Composants

Les composants sont des widgets interactifs qui permettent aux utilisateurs de configurer des paramètres (inputs) ou de visualiser les résultats dans votre bloc personnalisé.

{% hint style="info" %}
Les composants sont construits via des arguments nommés (keyword arguments).
{% endhint %}

#### Arguments génériques <a href="#generic-arguments" id="generic-arguments"></a>

Les arguments génériques s'appliquent à tous les composants personnalisés. Vous pouvez les fournir en tant qu'arguments nommés aux constructeurs.

Au lieu de les répéter sous chaque composant, voici une petite référence de style « pyi » :

```python
# Common keyword arguments (supported by all components)
class _CommonComponentKwargs:
    def __init__(
        self,
        *,
        tool_tip: str = "",
        enabled: bool = True,
        hidden: bool = False,
        fixed_width: int = 0,
        fixed_height: int = 0,
        minimum_width: int = 0,
        minimum_height: int = 0,
        maximum_width: int = 0,
        maximum_height: int = 0,
        serializable: bool = True,
        stylesheet: str = "",
        font_size: int = -1,
        font_bold: bool = False,
        alignment: str = "AlignLeft",
        **kwargs,
    ) -> None: ...
```

Remarques :

* `tool_tip` contrôle l'infobulle affichée lors du survol du composant.
* `fixed_width` / `fixed_height` sont en pixels. Utilisez `0` pour « automatique ».
* Certains composants remplacent les valeurs par défaut (par exemple `DropDown` n'est pas sérialisable ; `Image` n'est pas sérialisable par défaut).

### Text Input <a href="#text-inputx20" id="text-inputx20"></a>

Permet aux utilisateurs de saisir du texte/numérique sur une seule ligne.

<figure><img src="/files/EOkiYz9cufeo9Uye79iI" alt=""><figcaption></figcaption></figure>

```python
# pyi-style reference
class TextInput:
    def __init__(
        self,
        *,
        text: str = "",
        place_holder: str = "",
        check_type: type = str,
        password: bool = False,
        tool_tip: str = "",
        **kwargs,
    ) -> None: ...

    @property
    def value(self) -> str: ...

    @property
    def text(self) -> str: ...  # same as .value

    def toInt(self) -> int: ...
    def toFloat(self) -> float: ...
```

Remarques :

* Utilisez `check_type=int` ou `check_type=float` pour restreindre ce que l'utilisateur peut taper.
* Utilisez `.toInt()` / `.toFloat()` lorsque vous souhaitez que les erreurs de conversion remontent via une exception explicite (pas de repli silencieux).

<mark style="color:blue;">Exemple :</mark>

```python
class Example_Block(Block):
    ...
    def init(self):
        ...
        self.param["text1"] = TextInput(
            text="5",
            place_holder="Enter an integer",
            check_type=int,
            tool_tip="Defines constant",
        )
    
    def run(self):
        ...
        constant: int = self.param["text1"].toInt()
        ... 
```

### Drop Down List <a href="#drop-down-list" id="drop-down-list"></a>

Les listes déroulantes permettent aux utilisateurs de choisir une option parmi une liste de textes fournis.

<figure><img src="/files/GI7RiPfH9xziqMigbHjJ" alt=""><figcaption></figcaption></figure>

```python
# pyi-style reference
class DropDown:
    serializable: bool = False

    def __init__(
        self,
        *,
        items: list[str] | dict[str, object] = ["item1", "item2", "item3"],
        selected_index: int = 0,
        tool_tip: str = "",
        **kwargs,
    ) -> None: ...

    @property
    def selected_item(self) -> str: ...

    @property
    def selected_index(self) -> int: ...
```

Remarques :

* Si vous passez `items` en tant que `dict[str, object]`, vous pouvez accéder à la valeur mappée via `.getCurrentMatch()`.

{% hint style="warning" %}
`DropDown` est actuellement marqué comme non sérialisable. Si vous voulez que la sélection persiste dans les scénarios sauvegardés, stockez `selected_index` vous-même (par exemple avec `register_ser_value()` ou `serialize_node()`).
{% endhint %}

<mark style="color:blue;">Exemple :</mark>

```python
class Example_Block(Block):
    ...
    def init(self):
        ...
        self.param['drop_down'] = DropDown(items=['Method 1', 'Method 2', 'Method 3'], 
                                        tool_tip='Choose Method')
    
    def run(self):
        ...
        method_index: int = self.param['drop_down'].selected_index
        method_name: str = self.param['drop_down'].selected_item
        if method_index == 0:
            ... 
```

### Label <a href="#label" id="label"></a>

Les Label sont des composants textuels simples pour afficher du texte statique ou dynamique sur votre bloc personnalisé.

<figure><img src="/files/KYBsVi8qgHNnsk9jYft0" alt=""><figcaption></figcaption></figure>

Ils servent aussi à fournir des informations sur des composants interactifs :

<figure><img src="/files/uwFtlAoNSIauueJhCt0K" alt=""><figcaption></figcaption></figure>

```python
# pyi-style reference
class Label:
    def __init__(self, *, text: str = "", tool_tip: str = "", **kwargs) -> None: ...
    def set_text(self, text: str) -> None: ...
```

<mark style="color:blue;">Exemple :</mark>

```python
class Example_Block(Block):
    ...
    def init(self):
        ...
        self.param['label'] = Label(text='Result is: Not Set', 
                                        tool_tip='Shows mean value')
    
    def run(self):
        ...
        self.param['label'].set_text(f'Result is: {n}')
        ... 
```

### Slider <a href="#slider" id="slider"></a>

Restreint la saisie utilisateur à une plage de nombres.

<figure><img src="/files/2DUvBWDB96JeGmLMwlpW" alt=""><figcaption></figcaption></figure>

```python
# pyi-style reference
class Slider:
    def __init__(
        self,
        *,
        min: int = 0,
        max: int = 100,
        val: int = 50,
        tool_tip: str = "",
        **kwargs,
    ) -> None: ...

    @property
    def value(self) -> float | int: ...
```

<mark style="color:blue;">Exemple :</mark>

```python
class Example_Block(Block):
    ...
    def init(self):
        ...
        self.param['slider'] = Slider(min=-5, max=5, val=3)
    
    def run(self):
        ...
        threshold: int = self.param['slider'].value
        ... 
```

### Slider Labeled <a href="#slider-labeled" id="slider-labeled"></a>

Identique à [Slider](#slider) mais ajoute une étiquette qui affiche automatiquement la valeur courante du composant.

<figure><img src="/files/DdXM1pxpFurUb1LbLvky" alt=""><figcaption></figcaption></figure>

```python
# pyi-style reference
class SliderLabeled:
    def __init__(
        self,
        *,
        min: int = 0,
        max: int = 100,
        val: int = 50,
        label: str = "Value",
        multiplier: float | int = 1,
        add: float | int = 0,
        tool_tip: str = "",
        **kwargs,
    ) -> None: ...

    @property
    def value(self) -> float | int: ...

    @property
    def modifiedValue(self) -> float | int: ...
```

<mark style="color:blue;">Exemple :</mark>

```python
class Example_Block(Block):
    ...
    def init(self):
        ...
        self.param['threshold_odd'] = SliderLabeled(min= -5, max= 5, val= 3, label="Value", multiplier = 2, add = -1)
    
    def run(self):
        ...
        threshold_odd: int = self.param['threshold_odd'].modifiedValue
        ... 
```

### CheckBox <a href="#checkboxx20" id="checkboxx20"></a>

Permet une entrée d'état logique.

<figure><img src="/files/1FGSjqZv7xgUSMtwYLB2" alt=""><figcaption></figcaption></figure>

```python
# pyi-style reference
class CheckBox:
    def __init__(
        self,
        *,
        text: str = "",
        init_state: bool = False,
        tool_tip: str = "",
        **kwargs,
    ) -> None: ...

    @property
    def is_checked(self) -> bool: ...
```

<mark style="color:blue;">Exemple :</mark>

```python
class Example_Block(Block):
    ...
    def init(self):
        ...
        self.param['gray_mode'] = CheckBox(text=': Gray Mode')
    
    def run(self):
        ...
        flag_gray: bool = self.param['gray_mode'].is_checked
        ... 
```

### Button <a href="#button" id="button"></a>

Déclenche un événement dans votre script lors d'un clic de souris. Ce composant est aussi très utile pour la gestion des ressources dans les blocs personnalisés de votre scénario.

<figure><img src="/files/VXnJkiKZj4SzQJ9SiqgR" alt=""><figcaption></figcaption></figure>

```python
# pyi-style reference
from collections.abc import Callable

class Button:
    def __init__(self, *, text: str = "", tool_tip: str = "", **kwargs) -> None: ...
    def set_clicked_callback(self, callback: Callable[[], None]) -> None: ...
```

{% hint style="info" %}
Utilisez `set_clicked_callback(...)` dans `init()`.
{% endhint %}

<mark style="color:blue;">Exemple :</mark>

```python
...
class Example_Block(Block):
    ...
    file_path: str = ''
    def init(self):
        ...
        self.param['Choose File'] = Button(text= 'Choose File')
        self.param['Choose File'].set_clicked_callback(self.load_image)
    
    def load_image(self):
        path = QAFileDialog.getOpenFileName(caption='Load Image', 
                                        directory='C:/Images', 
                                        filter='Image Files (*.png *.jpg *.bmp)')
        self.file_path = self.register_resource('image-path', path)
        
    def run(self):
        image_path = self.get_resource('image-path')
    
```

L'exemple ci-dessus utilise des callbacks avec [`register_resource`](/french/key-features/create-plugins-with-designer-window/coding-reference.md#blockregister_resourcename-str-path-str-str) et [`get_resource`](/french/key-features/create-plugins-with-designer-window/coding-reference.md#blockget_resourcename-str-str).

### Image <a href="#imagex20" id="imagex20"></a>

<figure><img src="/files/N3fRNvL3ESVtWINES6Yk" alt=""><figcaption></figcaption></figure>

```python
# pyi-style reference
import numpy as np
import numpy.typing as npt

class Image:
    def __init__(
        self,
        *,
        fixed_width: int = 80,
        fixed_height: int = 80,
        tool_tip: str = "",
        serializable: bool = False,
        **kwargs,
    ) -> None: ...

    def update(self, img: npt.NDArray[np.uint8]) -> None: ...
```

<mark style="color:blue;">Exemple :</mark>

```python
...
class Example_Block(Block):
    def init(self):
        ...
        self.param['Result'] = Image(
            fixed_width=self.width - 40,
            fixed_height=self.height - 80,
        )

    def run(self):
        ...
        self.param['Result'].update(np.zeros((60, 60, 3), dtype=np.uint8))
        ...
```

### Table <a href="#table" id="table"></a>

Permet de sélectionner plusieurs éléments/modes en même temps.

<figure><img src="/files/uDVGNIEmveGY3gkIfjPF" alt=""><figcaption></figcaption></figure>

```python
# pyi-style reference
class Table:
    def __init__(
        self,
        *,
        header_label: str = "table",
        items: list[str] | dict[str, bool] = ["item1", "item2", "item3"],
        tool_tip: str = "",
        **kwargs,
    ) -> None: ...

    @property
    def items(self) -> list[str]: ...

    @property
    def selected_items(self) -> list[str]: ...

    def set_items(self, items: list[str]) -> None: ...
```

<mark style="color:blue;">Exemple :</mark>

```python
...
class Example_Block(Block):
    def init(self):
        ...
        self.param['Detection List'] = Table(items=['Human', 'Cat', 'Dog'])

    def run(self):
        ...
        detection_list: list[str, ...] = self.param['Detection List'].selected_items
        ...
```

### Text Edit <a href="#text-edit" id="text-edit"></a>

Text Edit est une zone de texte multilignes.

```python
# pyi-style reference
class TextEdit:
    def __init__(self, *, text: str = "", tool_tip: str = "", **kwargs) -> None: ...

    @property
    def value(self) -> str: ...

    @property
    def text(self) -> str: ...  # same as .value
```

<mark style="color:blue;">Exemple :</mark>

```python
class Example_Block(Block):
    def init(self):
        self.param['notes'] = TextEdit(tool_tip='Write notes here')

    def run(self):
        notes: str = self.param['notes'].value
```
