Metadata-Version: 2.4
Name: pyqt6-template-widgets
Version: 0.1.0
Summary: Template-based widgets and form helpers for PyQt6 applications
Author: proov
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: User Interfaces
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: PyQt6>=6.6
Provides-Extra: dev
Requires-Dist: pytest>=8; extra == "dev"
Requires-Dist: build>=1; extra == "dev"
Requires-Dist: twine>=5; extra == "dev"

# pyqt6-template-widgets

Template-based widgets and form helpers for PyQt6 applications. The library
helps build simple data-driven interfaces from reusable card, list and form
templates.

- `CardTemplate` описывает внешний вид карточки;
- `FormTemplate` и `FormField` описывают форму добавления/редактирования;
- `TemplateListWindow` показывает список и открывает форму;
- optional partner-management preset built on top of the template widgets;
- small calculation helpers are included for demo business rules.

## Installation

```bash
pip install -e .
```

## Template Example

```python
from pyqt6_templates import CardTemplate, FormField, FormTemplate, TemplateListWindow

items = [
    {
        "partner_type": "Дилер",
        "name": "ООО Ромашка",
        "director": "Иванов Иван Иванович",
        "phone": "+7 223 322 22 32",
        "rating": 10,
        "discount": 10,
    }
]

card_template = CardTemplate(
    title="{partner_type} | {name}",
    lines=["{director}", "{phone}", "Рейтинг: {rating}"],
    badge="{discount}%",
)

form_template = FormTemplate(
    title_create="Добавить партнера",
    title_edit="Редактировать партнера",
    fields=[
        FormField("name", "Наименование:", required=True),
        FormField("partner_type", "Тип:", kind="choice", choices=["Дилер", "Оптовик"]),
        FormField("rating", "Рейтинг:", kind="number", minimum=0),
        FormField("director", "Директор:", required=True),
        FormField("phone", "Телефон:", required=True),
    ],
)

window = TemplateListWindow(
    title="Список партнеров",
    items=items,
    card_template=card_template,
    form_template=form_template,
)
window.run()
```

The full example is available in `examples/template_demo.py`.

## Partner Preset

If your application manages partners, you can use the built-in preset:

```python
from pyqt6_templates import Partner, PartnerListWindow

partner = Partner(
    partner_type="Дилер",
    name="ООО Ромашка",
    director="Иванов Иван Иванович",
    phone="+7 223 322 22 32",
    rating=10,
    total_sales=62000,
)

window = PartnerListWindow(
    partners=[partner],
    partner_types=["Дилер", "Оптовик"],
)
window.run()
```

## Calculation Helpers

```python
from pyqt6_templates import calculate_partner_discount, calculate_required_material

discount = calculate_partner_discount(62000)

material = calculate_required_material(
    product_type_id=1,
    material_type_id=2,
    product_count=10,
    parameter_1=2.5,
    parameter_2=3.0,
    product_type_coefficients={1: 1.2},
    material_defect_rates={2: 0.05},
)
```

## PyPI Build

```bash
python -m pip install build twine
python -m build
python -m twine upload dist/*
```
