mirror of
https://github.com/iperov/DeepFaceLive
synced 2025-08-19 21:13:21 -07:00
code release
This commit is contained in:
parent
b941ba41a3
commit
a902f11f74
354 changed files with 826570 additions and 1 deletions
89
xlib/qt/widgets/QXCollapsibleSection.py
Normal file
89
xlib/qt/widgets/QXCollapsibleSection.py
Normal file
|
@ -0,0 +1,89 @@
|
|||
from PyQt6.QtCore import *
|
||||
from PyQt6.QtGui import *
|
||||
from PyQt6.QtWidgets import *
|
||||
|
||||
from .QXFrame import QXFrame
|
||||
from .QXHBoxLayout import QXHBoxLayout
|
||||
from .QXLabel import QXLabel
|
||||
from .QXToolButton import QXToolButton
|
||||
from .QXVBoxLayout import QXVBoxLayout
|
||||
|
||||
|
||||
class QXCollapsibleSection(QXFrame):
|
||||
"""
|
||||
Collapsible section.
|
||||
|
||||
Open/close state is saved to app db.
|
||||
"""
|
||||
|
||||
|
||||
def __init__(self, title, content_layout, vertical=False, is_opened=True, allow_open_close=True):
|
||||
super().__init__()
|
||||
self._is_opened = is_opened
|
||||
self._vertical = vertical
|
||||
|
||||
if vertical:
|
||||
title = '\n'.join(title)
|
||||
|
||||
label_title = self.label_title = QXLabel(text=title)
|
||||
|
||||
btn = self.btn = QXToolButton(checkable=True)
|
||||
btn.setStyleSheet('border: none;')
|
||||
btn.setArrowType(Qt.ArrowType.RightArrow)
|
||||
btn.setChecked(False)
|
||||
|
||||
if allow_open_close:
|
||||
btn.toggled.connect(self.on_btn_toggled)
|
||||
|
||||
frame = self.frame = QXFrame(layout=content_layout, size_policy=(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding), hided=True)
|
||||
|
||||
if vertical:
|
||||
main_l = QXHBoxLayout([ ( QXFrame(layout=
|
||||
QXVBoxLayout([ (btn, Qt.AlignmentFlag.AlignTop),
|
||||
(label_title, Qt.AlignmentFlag.AlignCenter)
|
||||
]),
|
||||
size_policy=(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Fixed) ), Qt.AlignmentFlag.AlignTop),
|
||||
|
||||
frame ])
|
||||
else:
|
||||
main_l = QXVBoxLayout( [ ( QXFrame(layout=
|
||||
QXHBoxLayout([ (btn, Qt.AlignmentFlag.AlignTop),
|
||||
(label_title, Qt.AlignmentFlag.AlignCenter)
|
||||
]),
|
||||
size_policy=(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Fixed) ) , Qt.AlignmentFlag.AlignTop),
|
||||
|
||||
frame])
|
||||
|
||||
self.setLayout(main_l)
|
||||
|
||||
if self._is_opened:
|
||||
self.open()
|
||||
|
||||
def _on_registered(self):
|
||||
super()._on_registered()
|
||||
self._is_opened = self.get_widget_data( (QXCollapsibleSection,'opened'), default_value=self._is_opened )
|
||||
if self._is_opened:
|
||||
self.open()
|
||||
else:
|
||||
self.close()
|
||||
|
||||
def is_opened(self):
|
||||
return self.btn.isChecked()
|
||||
|
||||
def open(self):
|
||||
self.set_widget_data( (QXCollapsibleSection,'opened'), True)
|
||||
self.btn.setArrowType(Qt.ArrowType.DownArrow)
|
||||
self.btn.setChecked(True)
|
||||
self.frame.show()
|
||||
|
||||
def close(self):
|
||||
self.set_widget_data( (QXCollapsibleSection,'opened'), False)
|
||||
self.btn.setArrowType(Qt.ArrowType.RightArrow)
|
||||
self.btn.setChecked(False)
|
||||
self.frame.hide()
|
||||
|
||||
def on_btn_toggled(self):
|
||||
if self.btn.isChecked():
|
||||
self.open()
|
||||
else:
|
||||
self.close()
|
Loading…
Add table
Add a link
Reference in a new issue