> 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/arabic/almyzat-alreysyh/create-plugins-with-designer-window/components.md).

# المكونات

المكونات هي عناصر واجهة تفاعلية تتيح للمستخدمين تكوين المعاملات (المدخلات) أو عرض النتائج داخل الكتلة المخصصة الخاصة بك.

{% hint style="info" %}
يتم بناء المكونات عبر وسائط اسم-قيمة (keyword arguments).
{% endhint %}

#### Generic Arguments <a href="#generic-arguments" id="generic-arguments"></a>

تنطبق الوسائط العامة على جميع المكونات المخصصة. يمكنك تمريرها كوسائط مسماة إلى البانيين.

بدلاً من تكرارها تحت كل مكون، فيما يلي مرجع صغير بأسلوب “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: ...
```

ملاحظات:

* `tool_tip` يتحكم بالنص التوضيحي الذي يظهر عند تحويم الماوس فوق المكون.
* `fixed_width` / `fixed_height` بوحدة البيكسل. استخدم `0` للقيمة “تلقائي”.
* بعض المكونات تغير القيم الافتراضية (مثلاً `DropDown` غير قابل للتسلسل؛ و`Image` غير قابل للتسلسل بشكل افتراضي).

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

يتيح للمستخدمين إدخال نص/أرقام عبر سطر واحد.

<figure><img src="/files/qSk9cnl40TOHuJsq3SS1" 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: ...
```

ملاحظات:

* استخدم `check_type=int` أو `check_type=float` لتقييد ما يمكن للمستخدم كتابته.
* استخدم `.toInt()` / `.toFloat()` عندما تريد أن تظهر أخطاء التحويل كاستثناء واضح (بدون تراجع صامت).

<mark style="color:blue;">مثال:</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>

تسمح القوائم المنسدلة للمستخدمين باختيار خيار من قائمة نصوص متوفرة.

<figure><img src="/files/5arwICX1IM3DftqJeYGI" 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: ...
```

ملاحظات:

* إذا مررت `items` كـ `dict[str, object]`، يمكنك الوصول إلى القيمة المرتبطة عبر `.getCurrentMatch()`.

{% hint style="warning" %}
`DropDown` معلمة حالياً غير قابلة للتسلسل. إذا أردت أن يبقى الاختيار محفوظًا في السيناريوهات المحفوظة، احفظ `selected_index` بنفسك (مثلاً باستخدام `register_ser_value()` أو `serialize_node()`).
{% endhint %}

<mark style="color:blue;">مثال:</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>

الملصقات عبارة عن مكونات نصية بسيطة لعرض نص ثابت أو ديناميكي على الكتلة المخصصة الخاصة بك.

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

كما تُستخدم لتقديم معلومات حول المكونات التفاعلية:

<figure><img src="/files/aJyCFUGtWnrFaovuJkB6" 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;">مثال:</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>

يقيد إدخال المستخدم إلى مدى من الأعداد.

<figure><img src="/files/1FkvhD5oNCZKF9Bklvbr" 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;">مثال:</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>

مماثل لـ [Slider](#slider) لكنه يضيف تسمية تعرض تلقائيًا القيمة المعروضة في المكون.

<figure><img src="/files/FzPv5SsljdrHA5zMdoLZ" 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;">مثال:</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>

يسمح بإدخال حالة منطقية (صح/خطأ).

<figure><img src="/files/mdmHoscWpGSmnkfJZYgy" 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;">مثال:</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>

يؤدي حدثًا في سكربتك عند النقر بالماوس. هذا المكون مفيد أيضًا لإدارة الموارد للكتل المخصصة داخل السيناريو الخاص بك.

<figure><img src="/files/5L2mSyKTDnslmlpq1qIB" 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" %}
استخدم `set_clicked_callback(...)` داخل `init()`.
{% endhint %}

<mark style="color:blue;">مثال:</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')
    
```

المثال أعلاه يستخدم ردود النداء مع [`register_resource`](/arabic/almyzat-alreysyh/create-plugins-with-designer-window/coding-reference.md#blockregister_resourcename-str-path-str-str) و [`get_resource`](/arabic/almyzat-alreysyh/create-plugins-with-designer-window/coding-reference.md#blockget_resourcename-str-str).

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

<figure><img src="/files/UXGVHOoyMeZvjKlOKF9g" 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;">مثال:</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>

يسمح باختيار عناصر/وضعيات متعددة في نفس الوقت.

<figure><img src="/files/HDSuSOTTURVOVhpeqnTP" 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;">مثال:</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 هو حقل نص متعدد الأسطر.

```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;">مثال:</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
```
