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.

Офлайн-туториал внутри установленной библиотеки

Начиная с версии 0.1.2, инструкция лежит прямо внутри пакета. После python -m pip install fastqt6 ее можно открыть без интернета в PyCharm:

External Libraries
  -> Python ...
  -> site-packages
  -> fastqt6
  -> docs
  -> PYCHARM_TUTORIAL.md

Также можно скопировать инструкцию в текущий проект:

fastqt6 tutorial --copy

Или просто узнать путь к файлу внутри site-packages:

fastqt6 tutorial

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

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.2.tar.gz (18.1 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.2-py3-none-any.whl (19.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fastqt6-0.1.2.tar.gz
  • Upload date:
  • Size: 18.1 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.2.tar.gz
Algorithm Hash digest
SHA256 fd1718e23c9501f1f2a596067ea69ed06ba02c9c3ae7e6271e803a1599e03d7c
MD5 4c1f3a4a33bdd42b3360c564fdd50447
BLAKE2b-256 024f4907928d4efd4e5f977718710f84d757adad0b62e76c1afb94e8c4ce77be

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastqt6-0.1.2.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.2-py3-none-any.whl.

File metadata

  • Download URL: fastqt6-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 19.6 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 19f4fea536b7a8ce0ad65a5a56d14e1e7d364f44db74f67ec2fbb0c3559f7e20
MD5 b29d0685c58666d00788641e964d2d90
BLAKE2b-256 94bc0a0a7cdc8b63a54d0cdd1acc5ed4f35933e469cc6bebb1ba65eabfefd0b9

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastqt6-0.1.2-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