Skip to content

misc

Classes:

StatusBar

StatusBar(parent: QWidget)

Bases: QStatusBar

Methods:

Attributes:

Source code in vspreview/core/custom/misc.py
32
33
34
35
def __init__(self, parent: QWidget) -> None:
    super().__init__(parent)

    self.permament_start_index = 0

duration_label instance-attribute

duration_label: QLabel

fps_label instance-attribute

fps_label: QLabel

frame_props_label instance-attribute

frame_props_label: QLabel

label instance-attribute

label: QLabel

label_names class-attribute instance-attribute

label_names = (
    "total_frames_label",
    "duration_label",
    "resolution_label",
    "pixel_format_label",
    "fps_label",
    "frame_props_label",
    "label",
)

permament_start_index instance-attribute

permament_start_index = 0

pixel_format_label instance-attribute

pixel_format_label: QLabel

resolution_label instance-attribute

resolution_label: QLabel

total_frames_label instance-attribute

total_frames_label: QLabel

addPermanentWidget

addPermanentWidget(widget: QWidget, stretch: int = 0) -> None
Source code in vspreview/core/custom/misc.py
37
38
def addPermanentWidget(self, widget: QWidget, stretch: int = 0) -> None:
    self.insertPermanentWidget(self.permament_start_index, widget, stretch)

addWidget

addWidget(widget: QWidget, stretch: int = 0) -> None
Source code in vspreview/core/custom/misc.py
40
41
42
def addWidget(self, widget: QWidget, stretch: int = 0) -> None:
    self.permament_start_index += 1
    super().addWidget(widget, stretch)

addWidgets

addWidgets(widgets: Sequence[QWidget], stretch: int = 0) -> None
Source code in vspreview/core/custom/misc.py
44
45
46
def addWidgets(self, widgets: Sequence[QWidget], stretch: int = 0) -> None:
    for widget in widgets:
        self.addWidget(widget, stretch)

insertWidget

insertWidget(index: int, widget: QWidget, stretch: int = 0) -> int
Source code in vspreview/core/custom/misc.py
48
49
50
def insertWidget(self, index: int, widget: QWidget, stretch: int = 0) -> int:
    self.permament_start_index += 1
    return super().insertWidget(index, widget, stretch)

Switch

Switch(
    radius: int = 10,
    width: int = 32,
    border: int = 1,
    state_texts: tuple[str, str, int] = ("OFF", "ON", 1),
    state_colors: tuple[QColor, QColor] = (
        QColor(69, 83, 100),
        QColor(96, 121, 139),
    ),
    border_color: QColor = QColor(69, 83, 100),
    text_color: QColor = QColor(224, 225, 226),
    background_color: QColor = QColor(25, 35, 45),
    **kwargs: Any
)

Bases: PushButton

Methods:

Attributes:

Source code in vspreview/core/custom/misc.py
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
def __init__(
    self, radius: int = 10, width: int = 32, border: int = 1,
    state_texts: tuple[str, str, int] = ('OFF', 'ON', 1),
    state_colors: tuple[QColor, QColor] = (QColor(69, 83, 100), QColor(96, 121, 139)),
    border_color: QColor = QColor(69, 83, 100), text_color: QColor = QColor(224, 225, 226),
    background_color: QColor = QColor(25, 35, 45), **kwargs: Any
):
    super().__init__(**kwargs)

    self.radius = radius
    self.sw_width = width
    self.border = border
    self.state_texts = state_texts
    self.state_colors = state_colors
    self.border_color = border_color
    self.text_color = text_color
    self.background_color = background_color

    self.setCheckable(True)
    self.setMinimumWidth((width + border) * 2)
    self.setMinimumHeight((radius + border) * 2)

background_color instance-attribute

background_color = background_color

border instance-attribute

border = border

border_color instance-attribute

border_color = border_color

radius instance-attribute

radius = radius

state_colors instance-attribute

state_colors = state_colors

state_texts instance-attribute

state_texts = state_texts

sw_width instance-attribute

sw_width = width

text_color instance-attribute

text_color = text_color

paintEvent

paintEvent(event: QPaintEvent) -> None
Source code in vspreview/core/custom/misc.py
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
def paintEvent(self, event: QPaintEvent) -> None:
    painter = QPainter(self)
    painter.setRenderHint(QPainter.RenderHint.Antialiasing)
    painter.translate(self.rect().center())
    painter.setBrush(self.background_color)

    pen = QPen(self.border_color)
    pen.setWidth(self.border)
    painter.setPen(pen)

    painter.drawRoundedRect(
        QRect(-self.sw_width, -self.radius, self.sw_width * 2, self.radius * 2), self.radius, self.radius
    )
    painter.setBrush(QBrush(self.state_colors[int(self.isChecked())]))

    switch_rect = QRect(
        -self.radius, -self.radius + self.border, self.sw_width + self.radius, self.radius * 2 - self.border * 2
    )

    if not self.isChecked():
        switch_rect.moveLeft(-self.sw_width)

    painter.setPen(pen)
    painter.drawRoundedRect(switch_rect, self.radius, self.radius)

    textpen = QPen(self.text_color)
    textpen.setWidth(self.state_texts[2])

    painter.setPen(textpen)
    painter.drawText(switch_rect, Qt.AlignmentFlag.AlignCenter, cast(str, self.state_texts[int(self.isChecked())]))

TableModel

TableModel(
    data: list[list[Any]] = [],
    columns: list[Any] | bool = True,
    rows: bool = True,
)

Bases: QAbstractTableModel

Methods:

Source code in vspreview/core/custom/misc.py
109
110
111
112
113
114
def __init__(self, data: list[list[Any]] = [], columns: list[Any] | bool = True, rows: bool = True) -> None:
    super().__init__()

    self._data = data
    self._columns = columns
    self._rows = rows

columnCount

columnCount(index: QModelIndex) -> int
Source code in vspreview/core/custom/misc.py
123
124
def columnCount(self, index: QModelIndex) -> int:
    return len(self._data) and len(self._data[0])

data

data(index: QModelIndex, role: int) -> Any
Source code in vspreview/core/custom/misc.py
116
117
118
def data(self, index: QModelIndex, role: int) -> Any:
    if role == Qt.ItemDataRole.DisplayRole:
        return self._data[index.row()][index.column()]

headerData

headerData(section, orientation, role)
Source code in vspreview/core/custom/misc.py
126
127
128
129
130
131
132
133
134
135
136
137
def headerData(self, section, orientation, role):
    if role == Qt.ItemDataRole.DisplayRole:
        if orientation == Qt.Orientation.Horizontal:
            if isinstance(self._columns, bool):
                if self._columns:
                    return super().headerData(section, orientation, role)
            else:
                return str(self._columns[section])

        if orientation == Qt.Orientation.Vertical:
            if self._rows:
                return super().headerData(section, orientation, role)

rowCount

rowCount(index: QModelIndex) -> int
Source code in vspreview/core/custom/misc.py
120
121
def rowCount(self, index: QModelIndex) -> int:
    return len(self._data)