From 9ee965d2e0690640ac047888b3718b177f17063a Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Mon, 1 Dec 2025 21:35:28 -0500 Subject: [PATCH] ui: overridable title and subtitle for search query in `TreeOptionDialog` (#1538) * ui: overridable title and subtitle for `TreeOptionDialog` * lint --- system/ui/sunnypilot/widgets/input_dialog.py | 11 ++++++----- system/ui/sunnypilot/widgets/tree_dialog.py | 15 +++++++++++++-- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/system/ui/sunnypilot/widgets/input_dialog.py b/system/ui/sunnypilot/widgets/input_dialog.py index 88ab0b1a6..ed67302fc 100644 --- a/system/ui/sunnypilot/widgets/input_dialog.py +++ b/system/ui/sunnypilot/widgets/input_dialog.py @@ -8,7 +8,6 @@ from collections.abc import Callable from openpilot.common.params import Params from openpilot.system.ui.lib.application import gui_app -from openpilot.system.ui.lib.multilang import tr from openpilot.system.ui.widgets import DialogResult from openpilot.system.ui.widgets.keyboard import Keyboard @@ -27,14 +26,16 @@ class InputDialogSP: def show(self): self.keyboard.reset(min_text_size=self.keyboard._min_text_size) - self.keyboard.set_title(tr(self.title), *(tr(self.sub_title),) if self.sub_title else ()) + if self.sub_title: + self.keyboard.set_title(self.title, self.sub_title) + else: + self.keyboard.set_title(self.title) self.keyboard.set_text(self.current_text) def internal_callback(result: DialogResult): text = self.keyboard.text if result == DialogResult.CONFIRM else "" - if result == DialogResult.CONFIRM: - if self.param: - self._params.put(self.param, text) + if result == DialogResult.CONFIRM and self.param: + self._params.put(self.param, text) if self.callback: self.callback(result, text) diff --git a/system/ui/sunnypilot/widgets/tree_dialog.py b/system/ui/sunnypilot/widgets/tree_dialog.py index 5685a6c27..4691f7f8f 100644 --- a/system/ui/sunnypilot/widgets/tree_dialog.py +++ b/system/ui/sunnypilot/widgets/tree_dialog.py @@ -77,7 +77,7 @@ class TreeItemWidget(Button): class TreeOptionDialog(MultiOptionDialog): def __init__(self, title, folders, current_ref="", fav_param="", option_font_weight=FontWeight.MEDIUM, search_prompt=None, - get_folders_fn=None, on_exit=None, display_func=None, search_funcs=None): + get_folders_fn=None, on_exit=None, display_func=None, search_funcs=None, search_title=None, search_subtitle=None): super().__init__(title, [], "", option_font_weight) self.folders = folders self.selection_ref = current_ref @@ -92,6 +92,17 @@ class TreeOptionDialog(MultiOptionDialog): self.on_exit = on_exit self.display_func = display_func or (lambda node: node.data.get('display_name', node.ref)) self.search_funcs = search_funcs or [lambda node: node.data.get('display_name', ''), lambda node: node.data.get('short_name', '')] + + # Default title & overridable subtitle for InputDialogSP + self.search_title = search_title or tr("Enter search query") + self.search_subtitle = search_subtitle + self.search_dialog = InputDialogSP( + self.search_title, + self.search_subtitle, + current_text=self.query, + callback=self._on_search_confirm, + ) + self._build_visible_items() def _on_search_confirm(self, result, text): @@ -101,7 +112,7 @@ class TreeOptionDialog(MultiOptionDialog): gui_app.set_modal_overlay(self, callback=self.on_exit) def _on_search_clicked(self): - InputDialogSP(tr("Enter search query"), current_text=self.query, callback=self._on_search_confirm).show() + self.search_dialog.show() def _toggle_folder(self, folder): if folder.folder: