129 lines
4.3 KiB
Python
129 lines
4.3 KiB
Python
from PySide6.QtWidgets import (
|
||
QWidget,
|
||
QLabel,
|
||
QVBoxLayout,
|
||
QHBoxLayout,
|
||
QScrollArea,
|
||
)
|
||
from PySide6.QtCore import Qt, Signal
|
||
from PySide6.QtGui import QFont, QGuiApplication
|
||
from PySide6.QtWidgets import QScroller
|
||
import build_info
|
||
|
||
|
||
class AboutScreen(QWidget):
|
||
dev_unlocked = Signal()
|
||
|
||
def __init__(self):
|
||
super().__init__()
|
||
self._dev_taps = 0
|
||
self._dev_hint = QLabel("")
|
||
|
||
layout = QVBoxLayout(self)
|
||
layout.setContentsMargins(0, 0, 0, 0)
|
||
layout.setSpacing(12)
|
||
|
||
scroll = QScrollArea()
|
||
scroll.setWidgetResizable(True)
|
||
scroll.setFrameShape(QScrollArea.NoFrame)
|
||
scroll.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
||
scroll.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
||
|
||
scroller = QScroller.scroller(scroll.viewport())
|
||
scroller.grabGesture(
|
||
scroll.viewport(),
|
||
QScroller.LeftMouseButtonGesture
|
||
)
|
||
|
||
content = QWidget()
|
||
content_layout = QVBoxLayout(content)
|
||
content_layout.setContentsMargins(0, 0, 0, 0)
|
||
content_layout.setSpacing(12)
|
||
|
||
info = QVBoxLayout()
|
||
info.setContentsMargins(0, 0, 0, 0)
|
||
info.setSpacing(8)
|
||
|
||
info.addWidget(_info_row("Приложение", build_info.APP_NAME))
|
||
info.addWidget(_info_row("Версия", build_info.VERSION))
|
||
build_row = _info_row("Сборка", build_info.BUILD_DATE, clickable=True)
|
||
build_row.clicked.connect(self._on_build_tap)
|
||
info.addWidget(build_row)
|
||
self._dev_hint.setObjectName("DevHint")
|
||
self._dev_hint.setFont(QFont("", 12, 600))
|
||
self._dev_hint.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
|
||
info.addWidget(self._dev_hint)
|
||
info.addWidget(_info_row("Коммит", build_info.GIT_HASH))
|
||
info.addWidget(_info_row("Устройство", build_info.get_device_model()))
|
||
info.addWidget(_info_row("ОС", build_info.get_os_pretty_name()))
|
||
info.addWidget(_info_row("Ядро", build_info.get_kernel_version()))
|
||
info.addWidget(_info_row("RAM (используется/всего)", build_info.get_ram_info()))
|
||
info.addWidget(_info_row("Диск (используется/всего)", build_info.get_disk_info()))
|
||
info.addWidget(_info_row("Экран", build_info.get_display_resolution()))
|
||
info.addWidget(_info_row("Экран (факт)", _get_runtime_resolution()))
|
||
info.addWidget(_info_row("Серийный номер", build_info.get_serial_number()))
|
||
info.addWidget(_info_row("IP", build_info.get_ip_address()))
|
||
info.addWidget(_info_row("Температура CPU", build_info.get_cpu_temp()))
|
||
|
||
content_layout.addLayout(info)
|
||
content_layout.addStretch(1)
|
||
|
||
scroll.setWidget(content)
|
||
layout.addWidget(scroll)
|
||
|
||
def _on_build_tap(self):
|
||
self._dev_taps += 1
|
||
remaining = 5 - self._dev_taps
|
||
if remaining > 0:
|
||
self._dev_hint.setText(f"Осталось {remaining} нажат.")
|
||
return
|
||
if self._dev_taps >= 5:
|
||
self._dev_taps = 0
|
||
self._dev_hint.setText("Режим разработчика включен")
|
||
self.dev_unlocked.emit()
|
||
|
||
|
||
class _ClickableRow(QWidget):
|
||
clicked = Signal()
|
||
|
||
def __init__(self):
|
||
super().__init__()
|
||
self.setCursor(Qt.PointingHandCursor)
|
||
|
||
def mousePressEvent(self, event):
|
||
if event.button() == Qt.LeftButton:
|
||
self.clicked.emit()
|
||
super().mousePressEvent(event)
|
||
|
||
|
||
def _info_row(label: str, value: str, clickable: bool = False) -> QWidget:
|
||
row = _ClickableRow() if clickable else QWidget()
|
||
layout = QHBoxLayout(row)
|
||
layout.setContentsMargins(12, 6, 12, 6)
|
||
layout.setSpacing(12)
|
||
|
||
lbl = QLabel(label)
|
||
lbl.setFont(QFont("", 15, 600))
|
||
|
||
val = QLabel(value)
|
||
val.setFont(QFont("", 15))
|
||
val.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
|
||
|
||
layout.addWidget(lbl)
|
||
layout.addStretch(1)
|
||
layout.addWidget(val)
|
||
return row
|
||
|
||
|
||
def _get_runtime_resolution() -> str:
|
||
app = QGuiApplication.instance()
|
||
if app is None:
|
||
return "—"
|
||
screen = app.primaryScreen()
|
||
if screen is None:
|
||
return "—"
|
||
size = screen.size()
|
||
if size.isEmpty():
|
||
return "—"
|
||
return f"{size.width()}x{size.height()}"
|