47 lines
1.7 KiB
Python
47 lines
1.7 KiB
Python
from PySide6.QtCore import Qt, Signal
|
|
from PySide6.QtWidgets import QWidget, QVBoxLayout, QLabel, QPushButton, QHBoxLayout, QScrollArea
|
|
|
|
|
|
class ProfileView(QWidget):
|
|
start_chat_clicked = Signal(dict) # payload with user data
|
|
follow_clicked = Signal(dict)
|
|
|
|
def __init__(self, user: dict, parent=None):
|
|
super().__init__(parent)
|
|
self.user = user or {}
|
|
|
|
root = QVBoxLayout(self)
|
|
root.setContentsMargins(16, 12, 16, 12)
|
|
root.setSpacing(8)
|
|
|
|
# Header info
|
|
login = self.user.get("login") or "user"
|
|
full_name = self.user.get("full_name") or self.user.get("custom_name") or ""
|
|
bio = (self.user.get("profile") or {}).get("bio") if isinstance(self.user.get("profile"), dict) else None
|
|
|
|
self.login_label = QLabel(f"@{login}")
|
|
self.login_label.setObjectName("ProfileLogin")
|
|
self.name_label = QLabel(full_name)
|
|
self.name_label.setObjectName("ProfileName")
|
|
|
|
root.addWidget(self.login_label)
|
|
if full_name:
|
|
root.addWidget(self.name_label)
|
|
|
|
if bio:
|
|
bio_label = QLabel(str(bio))
|
|
bio_label.setWordWrap(True)
|
|
root.addWidget(bio_label)
|
|
|
|
# Actions
|
|
actions = QHBoxLayout()
|
|
self.message_btn = QPushButton("Написать сообщение")
|
|
self.follow_btn = QPushButton("Подписаться")
|
|
actions.addWidget(self.message_btn)
|
|
actions.addWidget(self.follow_btn)
|
|
root.addLayout(actions)
|
|
|
|
self.message_btn.clicked.connect(lambda: self.start_chat_clicked.emit(self.user))
|
|
self.follow_btn.clicked.connect(lambda: self.follow_clicked.emit(self.user))
|
|
|