54e6124925
version: sunnypilot v2026.001.000 (dev) date: 2026-05-07T23:07:19 master commit: c28eb958740187620f2282023b8f1997cf90f583
95 lines
3.0 KiB
Python
95 lines
3.0 KiB
Python
"""
|
|
Copyright (c) 2021-, Haibin Wen, sunnypilot, and a number of other contributors.
|
|
|
|
This file is part of sunnypilot and is licensed under the MIT License.
|
|
See the LICENSE.md file in the root directory for more details.
|
|
"""
|
|
from enum import IntEnum
|
|
|
|
from openpilot.system.ui.widgets import Widget
|
|
from openpilot.system.ui.lib.multilang import tr
|
|
from openpilot.system.ui.widgets.scroller_tici import Scroller
|
|
from openpilot.system.ui.sunnypilot.widgets.list_view import option_item_sp
|
|
from openpilot.sunnypilot.system.params_migration import ONROAD_BRIGHTNESS_TIMER_VALUES
|
|
|
|
|
|
class OnroadBrightness(IntEnum):
|
|
AUTO = 0
|
|
AUTO_DARK = 1
|
|
SCREEN_OFF = 2
|
|
|
|
|
|
class DisplayLayout(Widget):
|
|
def __init__(self):
|
|
super().__init__()
|
|
|
|
items = self._initialize_items()
|
|
self._scroller = Scroller(items, line_separator=True, spacing=0)
|
|
|
|
def _initialize_items(self):
|
|
self._onroad_brightness = option_item_sp(
|
|
param="OnroadScreenOffBrightness",
|
|
title=lambda: tr("Onroad Brightness"),
|
|
description="",
|
|
min_value=0,
|
|
max_value=22,
|
|
value_change_step=1,
|
|
label_callback=lambda value: self.update_onroad_brightness(value),
|
|
inline=True
|
|
)
|
|
self._onroad_brightness_timer = option_item_sp(
|
|
param="OnroadScreenOffTimer",
|
|
title=lambda: tr("Onroad Brightness Delay"),
|
|
description="",
|
|
min_value=0,
|
|
max_value=15,
|
|
value_change_step=1,
|
|
value_map=ONROAD_BRIGHTNESS_TIMER_VALUES,
|
|
label_callback=lambda value: f"{value} s" if value < 60 else f"{int(value/60)} m",
|
|
inline=True
|
|
)
|
|
self._interactivity_timeout = option_item_sp(
|
|
param="InteractivityTimeout",
|
|
title=lambda: tr("Interactivity Timeout"),
|
|
description=lambda: tr("Apply a custom timeout for settings UI." +
|
|
"<br>This is the time after which settings UI closes automatically " +
|
|
"if user is not interacting with the screen."),
|
|
min_value=0,
|
|
max_value=120,
|
|
value_change_step=10,
|
|
label_callback=lambda value: (tr("Default") if not value or value == 0 else
|
|
f"{value} s" if value < 60 else f"{int(value/60)} m"),
|
|
inline=True
|
|
)
|
|
items = [
|
|
self._onroad_brightness,
|
|
self._onroad_brightness_timer,
|
|
self._interactivity_timeout,
|
|
]
|
|
return items
|
|
|
|
@staticmethod
|
|
def update_onroad_brightness(val):
|
|
if val == OnroadBrightness.AUTO:
|
|
return tr("Auto (Default)")
|
|
|
|
if val == OnroadBrightness.AUTO_DARK:
|
|
return tr("Auto (Dark)")
|
|
|
|
if val == OnroadBrightness.SCREEN_OFF:
|
|
return tr("Screen Off")
|
|
|
|
return f"{(val - 2) * 5} %"
|
|
|
|
def _update_state(self):
|
|
super()._update_state()
|
|
|
|
brightness_val = self._onroad_brightness.action_item.current_value
|
|
self._onroad_brightness_timer.action_item.set_enabled(brightness_val not in (OnroadBrightness.AUTO, OnroadBrightness.AUTO_DARK))
|
|
|
|
def _render(self, rect):
|
|
self._scroller.render(rect)
|
|
|
|
def show_event(self):
|
|
self._scroller.show_event()
|