Initial commit: the FS25 Lua mod (live.json data export), the FS25-WebDashboard project (Node/web dashboard + PySide6 desktop variant), and FarmHUD (standalone PySide6 companion app with Discord Rich Presence, settings, and installer).
76 lines
2.9 KiB
Python
76 lines
2.9 KiB
Python
"""HUD tiles - the two shapes the "gauge cluster" hero section is built
|
||
from: one wide masthead reading (current vehicle) and several compact
|
||
gauges side by side (money, farm value, time), the way a tractor's dash
|
||
has one big central display flanked by smaller round gauges."""
|
||
from __future__ import annotations
|
||
|
||
from PySide6.QtCore import Qt
|
||
from PySide6.QtWidgets import QFrame, QHBoxLayout, QLabel, QVBoxLayout
|
||
|
||
|
||
class StatTile(QFrame):
|
||
def __init__(self, icon: str, label: str, variant: str = "hero", parent=None) -> None:
|
||
super().__init__(parent)
|
||
self.variant = variant
|
||
self.setProperty("role", "tile-hero" if variant == "hero" else "tile")
|
||
|
||
if variant == "hero":
|
||
layout = QHBoxLayout(self)
|
||
layout.setContentsMargins(16, 14, 16, 14)
|
||
layout.setSpacing(14)
|
||
|
||
icon_label = QLabel(icon)
|
||
icon_label.setStyleSheet("font-size: 30px;")
|
||
icon_label.setFixedWidth(38)
|
||
layout.addWidget(icon_label)
|
||
|
||
text_col = QVBoxLayout()
|
||
text_col.setSpacing(2)
|
||
self.label = QLabel(label)
|
||
self.label.setProperty("role", "tile-label")
|
||
text_col.addWidget(self.label)
|
||
|
||
self.value = QLabel("–")
|
||
self.value.setProperty("role", "tile-value-lg")
|
||
self.value.setWordWrap(True)
|
||
text_col.addWidget(self.value)
|
||
|
||
layout.addLayout(text_col, 1)
|
||
else:
|
||
layout = QVBoxLayout(self)
|
||
layout.setContentsMargins(10, 12, 10, 12)
|
||
layout.setSpacing(4)
|
||
layout.setAlignment(Qt.AlignmentFlag.AlignHCenter)
|
||
|
||
icon_label = QLabel(icon)
|
||
icon_label.setStyleSheet("font-size: 20px;")
|
||
icon_label.setAlignment(Qt.AlignmentFlag.AlignHCenter)
|
||
layout.addWidget(icon_label)
|
||
|
||
self.label = QLabel(label)
|
||
self.label.setProperty("role", "tile-label")
|
||
self.label.setAlignment(Qt.AlignmentFlag.AlignHCenter)
|
||
layout.addWidget(self.label)
|
||
|
||
self.value = QLabel("–")
|
||
self.value.setProperty("role", "tile-value")
|
||
self.value.setAlignment(Qt.AlignmentFlag.AlignHCenter)
|
||
self.value.setWordWrap(True)
|
||
layout.addWidget(self.value)
|
||
|
||
self.sub_value = QLabel("")
|
||
self.sub_value.setProperty("role", "dim")
|
||
self.sub_value.setAlignment(Qt.AlignmentFlag.AlignHCenter)
|
||
self.sub_value.hide()
|
||
layout.addWidget(self.sub_value)
|
||
|
||
def set_value(self, text: str) -> None:
|
||
self.value.setText(text)
|
||
|
||
def set_sub_value(self, text: str) -> None:
|
||
"""Compact tiles only: a small line under the value (e.g. the day
|
||
number under the clock) - keeps the big value short enough to
|
||
never wrap in a narrow gauge tile."""
|
||
self.sub_value.setText(text)
|
||
self.sub_value.setVisible(bool(text))
|