Files
Dispatch/Dispatch_V0.1.1/gui/containers/v_container.py
2026-04-29 08:18:54 +04:00

102 lines
4.2 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
# gui/containers/v_container.py
"""Вертикальный контейнер — тонкая обёртка над SContainer(orientation='v').
Удобство: ``VContainer(width_percent=30)`` вместо
``SContainer(width_percent=30, orientation='v')``.
Высота всегда Expanding (height_percent=None).
"""
from PySide6.QtWidgets import QWidget
from .s_container import SContainer
class VContainer(SContainer):
"""Вертикальный контейнер с шириной в процентах от родителя."""
def __init__(
self,
width_percent: int | float | None = None,
margin: int | tuple[int, int, int, int] = 0,
spacing: int = 0,
content_width_percent: int | None = None,
content_height_percent: int | None = None,
content_width: int | None = None,
content_height: int | None = None,
content_fit: bool = True,
content_driven: bool = False,
parent: QWidget | None = None,
style: str | None = None,
active_style: str | None = None,
is_active: bool | None = None,
):
super().__init__(
width_percent=width_percent,
height_percent=None,
margin=margin,
spacing=spacing,
orientation="v",
content_width_percent=content_width_percent,
content_height_percent=content_height_percent,
content_width=content_width,
content_height=content_height,
content_fit=content_fit,
content_driven=content_driven,
parent=parent,
style=style,
active_style=active_style,
is_active=is_active,
)
# ---------------------------------------------------------------------------
# Module workflow notes
# ---------------------------------------------------------------------------
#
# 1) Назначение модуля:
# Вертикальный контейнер — тонкая обёртка над SContainer с фиксированной
# ориентацией "v". Удобный синтаксический сахар: VContainer(width_percent=30)
# вместо SContainer(width_percent=30, orientation='v'). Высота всегда
# Expanding (height_percent=None по умолчанию).
#
# 2) Зависимости модуля:
# Импорты: QWidget (PySide6)
# Хост/базовый класс: SContainer (s_container.py)
# Внешние библиотеки: PySide6
#
# 3) Экспорт:
# Класс VContainer — вертикальный контейнер с шириной в процентах.
#
# 4) Состояние (поля):
# Собственных полей нет — всё наследуется от SContainer.
# Параметр alignment в __init__ принимается, но игнорируется
# (deprecated, для обратной совместимости).
#
# 5) Последовательность действий и вызовов:
# __init__(params) -> super().__init__(height_percent=None, orientation="v", ...)
# Все методы делегируются SContainer: add_widget(), add_stretch(),
# set_margins(), set_spacing(), get_layout() и т.д.
#
# 6) Побочные эффекты:
# Те же, что и у SContainer: стилизация через _apply_style(),
# флаг _auto_add_children=True, subscribe на theme_bus.
#
# 7) Границы ответственности:
# НЕ добавляет собственной логики — только фиксирует orientation="v"
# и height_percent=None. Вся логика — в SContainer.
#
# 8) Обработка ошибок:
# Делегируется SContainer.
#
# 9) Инварианты и контракты:
# - height_percent всегда None → вертикальная ось Expanding.
# - orientation всегда "v".
#
# 10) Правило сопровождения:
# Не добавлять сюда логику. Если нужна новая функциональность —
# добавлять в SContainer, чтобы VContainer и HContainer наследовали
# её автоматически.