Skip to main content

Convenient PyQt6 templates for dynamic forms, CRUD windows, Designer .ui files and SQL helpers

Project description

fastqt6

fastqt6 - это небольшая библиотека-шаблон для PyQt6-проектов: динамические формы, CRUD-окна, SQL-хелперы и генерация .ui файлов для Qt Designer.

Установка:

python -m pip install fastqt6

Локальная установка из репозитория:

python -m pip install -e .

Быстрый старт в PyCharm

  1. Создай новый проект в PyCharm:
File -> New Project -> Pure Python
  1. Открой вкладку Terminal внизу PyCharm и установи библиотеку:
python -m pip install fastqt6
  1. Создай готовый маленький проект:
fastqt6 scaffold .

Если команда fastqt6 не находится, используй так:

python -m fastqt6.cli scaffold .
  1. Запусти файл main.py в PyCharm. Откроется простое CRUD-окно с таблицей товаров. Это минимальный пример, который можно дальше менять под свой вариант.

  2. Для генерации .ui файлов Qt Designer:

mkdir ui gen
fastqt6 ui-auth ui/auth.ui
fastqt6 ui-main ui/main.ui --tabs "Каталог,Мои заказы,Все заказы,Статистика"
fastqt6 ui-form ui/product.ui --title "Товар" --class-name ProductDialog \
  --field article:text:Артикул \
  --field title:text:Название \
  --field price:float:Цена
  1. Конвертация .ui в Python:
pyuic6 ui/product.ui -o gen/product.py

Полный урок для PyCharm: docs/PYCHARM_TUTORIAL.md.

Быстрый пример кода

from PyQt6.QtWidgets import QApplication
from fastqt6 import SQLDatabase, field
from fastqt6.widgets import CrudWindow

SCHEMA = """
create table if not exists products (
    id integer primary key autoincrement,
    article text not null,
    title text not null,
    price real not null default 0,
    stock integer not null default 0
);
"""

app = QApplication([])
db = SQLDatabase.sqlite("app.db")
db.run_script(SCHEMA)

window = CrudWindow(
    db,
    table="products",
    fields=[
        field("article", "Артикул", required=True),
        field("title", "Название", required=True),
        field("price", "Цена", "float", min_value=0),
        field("stock", "Остаток", "int", min_value=0),
    ],
)
window.show()
app.exec()

SQL-хелперы

SQLite:

from fastqt6 import SQLDatabase

db = SQLDatabase.sqlite("app.db")
db.insert("products", {"article": "A-1", "title": "Мяч", "price": 1000})
rows = db.select("products", where="price > ?", params=(500,), order_by="title")
db.update("products", {"price": 1200}, "id=?", (1,))
db.delete("products", "id=?", (1,))

MySQL:

from fastqt6 import SQLDatabase

db = SQLDatabase.mysql("sportplus_kvalik", user="root", password="")
user = db.login("users", "admin", "admin")
rows = db.fetch_all("select * from products where title like ?", ("%мяч%",))

В запросах можно писать ? как универсальный placeholder. Для MySQL библиотека сама заменит его на %s.

Динамические формы

from fastqt6 import field
from fastqt6.forms import DynamicFormDialog

fields = [
    field("article", "Артикул", required=True),
    field("title", "Название", required=True),
    field("price", "Цена", "float", min_value=0),
    field("category_id", "Категория", "combo", choices=[("Мячи", 1), ("Обувь", 2)]),
]

dialog = DynamicFormDialog(fields, title="Товар")
if dialog.exec():
    data = dialog.get_data()

Генерация файлов Qt Designer

Создать auth.ui:

fastqt6 ui-auth ui/auth.ui

Создать главное окно с вкладками:

fastqt6 ui-main ui/main.ui --tabs "Каталог,Мои заказы,Все заказы,Статистика"

Создать форму:

fastqt6 ui-form ui/product.ui \
  --title "Товар" \
  --class-name "ProductDialog" \
  --field article:text:Артикул \
  --field title:text:Название \
  --field price:float:Цена \
  --field stock:int:Остаток

После этого файл можно открыть в Qt Designer или конвертировать:

pyuic6 ui/product.ui -o gen/product.py

CLI

fastqt6 scaffold my_app
fastqt6 ui-auth ui/auth.ui
fastqt6 ui-main ui/main.ui
fastqt6 ui-form ui/form.ui --field title:text:Название

Что вводить на PyPI Trusted Publisher

Для репозитория git@github.com:Leevandr/fastQT6.git заполни форму так:

PyPI Project Name: fastqt6
Owner: Leevandr
Repository name: fastQT6
Workflow name: publish.yml
Environment name: pypi

Workflow уже лежит в .github/workflows/publish.yml. В GitHub желательно создать environment с названием pypi: Settings -> Environments -> New environment.

Публикация пойдет через GitHub Actions без API-токена: после настройки Trusted Publisher создай GitHub Release или запусти workflow вручную.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastqt6-0.1.1.tar.gz (15.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastqt6-0.1.1-py3-none-any.whl (16.1 kB view details)

Uploaded Python 3

File details

Details for the file fastqt6-0.1.1.tar.gz.

File metadata

  • Download URL: fastqt6-0.1.1.tar.gz
  • Upload date:
  • Size: 15.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for fastqt6-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e352e70b4d308710480d6dd731023f6b3e70392fd07ff3b729ff93b577150c85
MD5 84ffdbf347ccc46a89a3b995193a2dc8
BLAKE2b-256 b3dd7dbf03b3fb9870c17abb33234545bbfb51d76a4920ad85c36c6670705e4e

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastqt6-0.1.1.tar.gz:

Publisher: publish.yml on Leevandr/fastQT6

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastqt6-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: fastqt6-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 16.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for fastqt6-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3c8bf48dd87dc92e84954d70a87402df69d902f1e09bdd7a62afd9028c6890fc
MD5 c28ebf1e8dff248e5be160a3af6826b6
BLAKE2b-256 e5ab4dc3ce3673c77b880495f6031d4fb06867a3ea5a3a0da238190b0e079156

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastqt6-0.1.1-py3-none-any.whl:

Publisher: publish.yml on Leevandr/fastQT6

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page